app.config dependentAssembly不工作

时间:2011-07-27 12:43:52

标签: c# app-config

我想直接链接到编译/运行时使用的Dll。我的程序布局是这样的: Console Exe启动winform dll。该DLL使用一堆dll来执行。 Appconfig位于winform dll的项目中。基于一些阅读,winform dll是否正在寻找错误的app.config?我打算使用Assembly.LoadFrom();

执行我的DLL

我创建了一个app.config文件,并在

部分中添加了以下行
<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>

位置绝对正确。 dll没有强名称,因此publicKeyToken =“null”。我的所有版本都是1.0.0.0。当我查看我引用的dll的属性时,文化是空白的。我也应该这样吗?是否有任何看起来我做错了?

1 个答案:

答案 0 :(得分:4)

App.config不应该用在dll上,而只能用于可执行文件。

如果在可执行文件中加载dll,则dll将使用正在运行的可执行文件的配置文件,并将忽略为其定义的配置..

如果您希望可以使用从当前程序集的配置文件中获取它们的一些丑陋代码来读取配置的键。

您应该做的是将相关配置放在exe配置文件中。

<强>更新

在以下问题中找到更多信息:C# DLL config file

相关问题