I am trying to load an assembly A in a new AppDomain in my console application with same base directory and RelativePath as the default domain.
When I create a type from A using CreateInstanceFrom it succeeds but when I use CreateInstanceAndUnwrap
it fails to find assembly file with FileLoadException
. Keep in mind that assembly A.MyType
calls a method from assembly B.Typeb
in it's constructor. Both assemblies files are present at the same path in parent folder of executing assembly (..\Mytypes)
_domain = AppDomain.CreateDomain("MyDomain" + Guid.NewGuid(), null, AppDomain.CurrentDomain.SetupInformation);
var mytype = _domain.CreateInstanceAndUnwrap(pathtoassembly, typename);
Here is the error message:
Could not load file or assembly '..\Mytypes\A.dll' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)`
CreateInstanceAndUnwrap
takes the assembly name as the first parameter, not the path to the assembly. Also, the path..\MyTypes
is outside the application base directory and so it is not used when probing for assemblies. – Saffian