0

I try to create new application domain and load new assembly:

AppDomain newDomain = AppDomain.CreateDomain("SecondaryDomain");

newDomain.AssemblyLoad += (sender, eventArgs) => Console.WriteLine("Assembly loaded");
newDomain.DomainUnload += (sender, EventArgs) => Console.WriteLine("Domain unloaded");

Console.WriteLine($"New domain name: {newDomain.FriendlyName}");
newDomain.Load(new AssemblyName("System.Dynamic"));

foreach (Assembly assembly in newDomain.GetAssemblies())
    Console.WriteLine($"Assembly in secondary domain: {assembly.GetName().Name}");

AppDomain.Unload(newDomain);

It throws System.IO.FileNotFoundException even if reference to System.Dynamic is added. How to solve it?

  • 1
    System.Dynamic is a namespace name, not an assembly name. Classes in that namespace live inside System.Core.dll. If you do this in a .NETCore etc project then you ought to mention that. – Hans Passant Apr 04 '18 at 22:45
  • Yes, You're right, however, it seems that fully qualified name of the assembly has also to be used for the `AssemblyName` instance to be constructed properly. – Lukasz M Apr 04 '18 at 22:52

1 Answers1

0

When creating AssemblyName instance with a string parameter, You should use the assembly fully qualified name, as mentioned here. So, instead writing only the assembly name, You should also specify its version, culture and public key token.

When using the assembly fully qualified name, the line that loads the assembly may look similar to this one:

newDomain.Load(new AssemblyName("System.Dynamic, Version=<version>, Culture=<culture>, PublicKeyToken=<public key token>"));

but placeholders marked with < and > should be replaced with proper values.

For more information about assembly fully qualified names, You can take a look here.

There are several ways to get fully qualified name of an assembly. If You have any problems obtaining this full name of the assembly You want to load, You can take a look at these links:

UPDATE

As Hans Passant mentioned in his comment, System.Dynamic namespace seems to be located inside System.Core assembly, so make sure which assembly You really want to load.

Lukasz M
  • 5,285
  • 2
  • 19
  • 28