Ryan You
Ryan You

Reputation: 73

Load Custom Configuration Sections from assembly in different folder

I have a C# application to load custom configuration section from assembly in different folder.

For example:

AppBase: C:\Code

Assembly Folder: C:\Lib\My.Core.dll

I have error says "System can't find specific file". I understand it is caused by different folder. Can I reference it in absolute path?

Here is my config file:

<section name="regional" type="My.Core.RegionalSection, My.Core" />

Can I make it something like

<section name="regional" type="My.Core.RegionalSection, C:\Lib\My.Core" />

Upvotes: 1

Views: 1337

Answers (1)

Hans Passant
Hans Passant

Reputation: 941455

No, you cannot specify a path in a type description. The CLR looks for assemblies in the GAC or the directory that contains the startup EXE. You can let it look in subdirectories by using the <probing> element in your .config file. Other paths that are completely unrelated to the startup EXE directory requires implementing the AppDomain.AssemblyResolve event.

Deploying DLLs in the same directory as the EXE is a wise thing to do. It avoids DLL Hell.

Upvotes: 3

Related Questions