C
C#15mo ago
MrBruh

❔ string[]' does not contain a definition for 'FirstOrDefault' and no accessible extension method...

This is probably a simple mistake so I apologize in advance.
c#
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;

internal class VersionAgnosticSerializationBinder : SerializationBinder
{
public override Type BindToType(string assemblyName, string typeName)
{
Type type = Type.GetType(Assembly.CreateQualifiedName(assemblyName, typeName));
if (type == null)
{
string simpleAssemblyName = assemblyName.Split(new char[1] { ',' }).FirstOrDefault();
if (string.IsNullOrEmpty(simpleAssemblyName))
{
throw new InvalidOperationException("Cannot retrieve assembly name from string '" + assemblyName + "'");
}
Assembly assembly2 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly assembly) => assembly.GetName().Name.Equals(simpleAssemblyName));
if (assembly2 == null)
{
throw new InvalidOperationException("The requested assembly '" + simpleAssemblyName + "' was not found");
}
type = assembly2.GetType(typeName);
}
if (type == null)
{
Logger.TraceEvent(TraceEventType.Critical, null, "Cannot bind requested type \"{0}, {1}\"", assemblyName, typeName);
}
return type;
}
}
c#
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;

internal class VersionAgnosticSerializationBinder : SerializationBinder
{
public override Type BindToType(string assemblyName, string typeName)
{
Type type = Type.GetType(Assembly.CreateQualifiedName(assemblyName, typeName));
if (type == null)
{
string simpleAssemblyName = assemblyName.Split(new char[1] { ',' }).FirstOrDefault();
if (string.IsNullOrEmpty(simpleAssemblyName))
{
throw new InvalidOperationException("Cannot retrieve assembly name from string '" + assemblyName + "'");
}
Assembly assembly2 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly assembly) => assembly.GetName().Name.Equals(simpleAssemblyName));
if (assembly2 == null)
{
throw new InvalidOperationException("The requested assembly '" + simpleAssemblyName + "' was not found");
}
type = assembly2.GetType(typeName);
}
if (type == null)
{
Logger.TraceEvent(TraceEventType.Critical, null, "Cannot bind requested type \"{0}, {1}\"", assemblyName, typeName);
}
return type;
}
}
error CS1061: 'string[]' does not contain a definition for 'FirstOrDefault' and no accessible extension method 'FirstOrDefault' accepting a first argument of type 'string[]' could be found
3 Replies
Omnissiah
Omnissiah15mo ago
(for one char i don't think you need the char array in the split)
MrBruh
MrBruhOP15mo ago
This needs System.Linq but I accidently specified a very old build version which didn't include the needed libraries/functions. Upgrading from net4.0 to net7.0 solved the problem
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server