Question

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";
Was it helpful?

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.

OTHER TIPS

See this SO question: How to add folder to assembly search path at runtime in .NET?

or you can add a <codebase> tag to your config, specifying where to search for assemblies, and add a reference to app2's dependencies.

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="MyAssembly2"  culture="neutral" publicKeyToken="307041694a995978"/>
            <codeBase version="1.0.1524.23149" href="FILE://C:/Myassemblies/MyAssembly2.dll"/>
         </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top