vendredi 24 juin 2022

Alternative to Assembly.ReflectionOnlyLoad() and ReflectionOnlyLoadFrom()?

I'm migrating a .Net 4.x application to .Net 6, but the above methods are now deprecated and throw an exception if called. What are the alternatives?

This is the code, which gets passed a list of assembly filenames, and loads any assemblies found to have a certain assembly-level attribute in AssemblyInfo.cs:

AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve +=
    (s, e) => Assembly.ReflectionOnlyLoad(e.Name);

foreach (var assemblyFile in assemblyFilenames)
{
    var reflectionOnlyAssembly = Assembly.ReflectionOnlyLoadFrom(assemblyFile);
    if (FoundOurCustomAttr(reflectionOnlyAssembly))
    {
        var assembly = Assembly.LoadFrom(assemblyFile);
        ProcessAssembly(assembly);
    }
}




Aucun commentaire:

Enregistrer un commentaire