0

I'm receiving this error "Could not load file or assembly 'MyReferenceAssembly', Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified." when attempting to load a reference to another custom DLL.

AppDomainSetup domainSetup = new AppDomainSetup();
domainSetup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

AppDomain domain = AppDomain.CreateDomain("myCustomDomain", null, domainSetup);

Type compilerType = typeof(MyCustomObject);
MyCustomObject cr = (MyCustomObject)domain.CreateInstanceFromAndUnwrap(compilerType.Assembly.Location, compilerType.FullName);


List<AssemblyName> references = compilerType.Assembly.GetReferencedAssemblies().ToList();
    references.ForEach(r => domain.Load(r));

I have tried not loading the references but still encounter the same error. It does seem to successfully load any references that are in the GAC.

Do i need to load references into this domain? And if so, how do i load custom library references into a new AppDomain?

Bob
  • 66
  • 4
  • I've had a mini breakthrough. I've found that by loading the entire AppDomainSetup from the current domain into the new domain it works. AppDomainSetup domainSetup = new AppDomainSetup(); domainSetup = AppDomain.CurrentDomain.SetupInformation; – Bob Nov 22 '13 at 00:28
  • What are you trying to accomplish with this? Remember that AppDomain.Load loads the assembly in the current AppDomain and NOT in the AppDomain referenced by the "domain" variable. – Panos Rontogiannis Nov 24 '13 at 17:17
  • I'm attempting to load all the referenced DLLs into the new AppDomain, referenced by the domain variable, in order to allow the code to execute in an isolated domain. – Bob Nov 25 '13 at 23:16
  • You could start with something like this http://stackoverflow.com/questions/17225276/create-custom-appdomain-and-add-assemblies-to-it/17324102#17324102 but you could also use the AppDomain.ExecuteAssembly method if you want to run an executable. – Panos Rontogiannis Nov 26 '13 at 15:41

0 Answers0