Adam Driscoll
Adam Driscoll

Reputation: 9483

AppDomain And the Current Directory

I have a class that utilizes a directory swap method for the Environment.CurrentDirectory. The code looks something like this:

 var str = Environment.CurrentDirectory;
 Environment.CurrentDirectory = Path.GetDirectoryName(pathToAssembly);
 var assembly = Assembly.Load(Path.GetFileNameWithoutExtension(pathToAssembly));
 Environment.CurrentDirectory = str;

As with my earlier post we are using this directory switching method to allow for loading of the specified assembly as well as any references assemblies, as well as unmanaged assemblies. The problem I am having is that this function is being run in two separate AppDomains. In AppDomain A (An AppDomain I create) the code works fine. In AppDomain B (the default AppDomain) it throws FileNotFoundException. For both of the calls I am trying to load the same assembly. Any clue why this would be the case?

Upvotes: 1

Views: 4865

Answers (1)

Rob Walker
Rob Walker

Reputation: 47462

This post suggests that you can't change the search path of the primary AppDomain once it is loaded -- you have to set it in the config file -- and has a number of suggestions, though they all boil down to "you can't do it in the primary AppDomain".

Upvotes: 1

Related Questions