Search code examples
c#appdomainshadow-copy

AppDomain ExecuteAssembly Could not load file or assembly


I have an app (app1) that loads another app (app2) like this:

this._appDomain.ExecuteAssembly(assemblyName);

I'm getting this error when that line executes:

Could not load file or assembly Foo...

App2 has a reference to Foo. If I add a reference to Foo in app1, it works. The problem is that I don't want app1 to reference Foo. App1's main purpose is to detect new versions of app2 on a network share, unload app2, copy the new binaries, then start app2 again using the line above. After doing that, if app1 has the old Foo in there, then app2 will use that instead of Foo in its own running directory.

How can I make it so that only app2 refereces Foo, yet app1 will still load app2 without that error?

Note: I am using shadow copying, and it is working when app1 has a reference to Foo.

appDomainSetup.ShadowCopyFiles   = "true";

Solution

  • See AppDomainSetup.ApplicationBase . You can specify the base application directory for your app domain via this property. The ApplicationBase is essentially the starting point for assembly probing. In addition, you can specify additional private bin paths using the the AppDomainSetup.PrivateBinPath. This allows the probing to search additional directories. There are code examples in the MSDN pages.