Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading assembly using Assembly.LoadFrom cause failure to find assemblies in references dlls #399

Open
joli03 opened this issue May 5, 2023 · 0 comments

Comments

@joli03
Copy link

joli03 commented May 5, 2023

Hi

I have a situation where I Bootstrap our host (.NET Framework 4.7.2) under .NET 7 by loadings it's assembly and calling Main. The AppHost use Ninject via Topshelf.Ninject.

var assembly = Assembly.LoadFrom("AppHost.exe");
var program = assembly.GetType("Program");
var main = program.GetMethod("Main", BindingFlags.Static | BindingFlags.Public);
main.Invoke(program, new object[] { Array.Empty<string>() });

In AppHost, Ninject modules are instantiated

 HostFactory.Run(x =>
          {
              x.UseNinject(
                      new MyModule() // More goes here
              );
// Omitted for brevity...
}

MyModule is in a library that has a reference to System.ServiceModel and upon calling base.Load() it crashes

System.IO.FileNotFoundException: Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified
File name: 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
   at BaseNinjectModule.Load()
   at MyModule.Load()
   at Ninject.Modules.NinjectModule.OnLoad(IKernel kernel)
   at Ninject.KernelBase.Load(IEnumerable`1 m)
   at Ninject.KernelBase..ctor(IComponentContainer components, INinjectSettings settings, INinjectModule[] modules)
   at Ninject.KernelBase..ctor(INinjectModule[] modules)
   at Ninject.StandardKernel..ctor(INinjectModule[] modules)
   at Topshelf.Ninject.NinjectBuilderConfigurator.get_Kernel()

I assume it has to do with not resolving them from the correct context, but can't figure out how to instruct Ninject (or earlier) about this.

Update: It just struck me that the issue might be that System.ServiceModel is not supported in .NET Runtime.. Need to check with the API Compatibility Tool.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant