8
votes

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?

1
A first chance exception of type 'System.IO.FileNotFoundException' occurred in BmsReplayAnalysis.dll A first chance exception of type 'System.TypeInitializationException' occurred in BmsReplayAnalysis.dll Could not load file or assembly 'MessageInterface, Version=1.0.0.0, Culture=neurtral,PublicKeyToken=null' or one of its dependencies. The system cannot find the file specifiedJason
Can you add your clarification to the question?Ryan Gates
Was my answer helpul? If so, accept it so others can use it as well. If it wasn't, did you find a different solution to your problem?Adam Tal
To be honest, it has been so long that i cannot remember what solution i went with. I believe that i always directly accessed the Dlls from the same path i would have used if running standalone and removed the dependent assemblies as a whole.Jason

1 Answers

4
votes

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