net 6 load assemblies at runtim to AppDomain.CurrentDomain

118 views Asked by At

The goal is to migrate a .net 4.6 FullFramework lib to .netStandard /.net6. There is one app that is using a typegrabber, so it is looking in its executing folder for *.dll and tries to load them into AppDomain.CurrentDomain (no comments if this is good or bad but it has to be done like this). The dlls that should be loaded are .netStandard 2.1

But the .net 6 app is throwing errors like this:

"Could not load file or assembly 'Framework.Tests.NetCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL'. Das System kann die angegebene Datei nicht finden."

The Code looks like this:

        public virtual AppDomain App
        {
            get
            {
                return AppDomain.CurrentDomain;
            }
        }

    private void LoadMatchingAssemblies(string directoryPath)
    {
          foreach (var dllPath in Directory.GetFiles(directoryPath, "*.dll"))
                    {
                        try
                        {
                            var an = AssemblyName.GetAssemblyName(dllPath);
                            if (this.Matches(an.FullName) && !loadedAssemblyNames.Contains(an.FullName))
                            {
                              this.App.Load(an);
                            }
                        }
                        catch (BadImageFormatException)
                        {
                        }
                        catch(Exception e)
                        {
                            string es = e.Message;
                        }
                    }
     }
0

There are 0 answers