Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

app.config dependentAssembly not working

Tags:

c#

app-config

I would like to directly link to Dlls that are used at compile/runtime. My program layout is this: Console Exe launches a winform dll. That dll uses a bunch of dlls to perform. The Appconfig is located in the project of the winform dll. Based on some reading, is the winform dll looking for the wrong app.config? I am intending on executing my dll using Assembly.LoadFrom();

I created an app.config file and added the following lines inside the section

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="CommonConversions"
                              publicKeyToken="null"
                              culture="neutral" />
            <codeBase version="1.0.0.0"
                      href="file://C://BMS_ACTD//bin//DX//Globals//CommonConversions.dll"/>
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="GlobalConstants"
                              publicKeyToken="null"
                              culture="neutral" />
            <codeBase version="1.0.0.0"
                      href="file://C://BMS_ACTD//bin//DX//Globals//GlobalConstants.dll"/>
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="MessageInstance"
                              publicKeyToken="null"
                              culture="neutral" />
            <codeBase version="1.0.0.0"
                      href="file://C://BMS_ACTD//bin//DX//Globals//MessageInstance.dll"/>
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="MessageInterface"
                              publicKeyToken="null"
                              culture="neutral" />
            <codeBase version="1.0.0.0"
                      href="file://C://BMS_ACTD//bin//DX//Globals//MessageInterface.dll"/>
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="ToolsInterface"
                              publicKeyToken="null"
                              culture="neutral" />
            <codeBase version="1.0.0.0"
                      href="file://C://BMS_ACTD//bin//DX//Globals//ToolsInterface.dll"/>
        </dependentAssembly>
    </assemblyBinding>
</runtime>

The location is definitely correct. The dlls are not strongly named, hence the publicKeyToken="null". all my versions are 1.0.0.0. When i look at the properties of my referenced dll, the Culture is blank. SHould mine be as well? Is there is anything that it appears i am doing wrong?

like image 827
Jason Avatar asked Jul 27 '11 12:07

Jason


1 Answers

App.config shouldn't be used upon a dll but only with an executable.

If you load a dll within an executable the dll will be using the config file of the running executable and will ignore the config defined for him..

If you wish you can read the keys of the config using some ugly code that takes them from the config file of the current assembly..

What you SHOULD do is to put the relevant configuration in the exe config file.

Update

Found further information in the following question: C# DLL config file

like image 90
Adam Tal Avatar answered Oct 21 '22 18:10

Adam Tal