Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a .NET console app that references a DLL. It runs fine if the DLL is in the same folder as the EXE but I would like to put the DLL in a different folder. How can I do that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
409 views
Welcome To Ask or Share your Answers For Others

1 Answer

If the DLL is in a sub folder you can add this folder to the AppDomain private path.

The private bin path of an AppDomain cannot be changed once the AppDomain has been created (AppDomain.AppendPrivatePath is obsolete), if you don't want to create a new AppDomain, you can modify the probing element in the App.config.

If it's not in a sub folder, things get more complicated, you can load the assembly using its full path, but if it references other assembly, the CLR won't be able to resolve the dependencies.

If you want to resolve dependencies, you can add an handler to AppDomain.AssemblyResolve and fetch the needed assembly in your specific folder.

Another possibility is to place this DLL (and dependencies) in the GAC.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...