app.config dependentAssembly not working

谁都会走 提交于 2021-01-27 04:06:53

问题


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:


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



来源:https://stackoverflow.com/questions/6844476/app-config-dependentassembly-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!