app.configdependentAssembly不起作用 [英] app.config dependentAssembly not working

查看:93
本文介绍了app.configdependentAssembly不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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();

我创建了一个app.config文件,并在该部分中添加了以下几行

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>

位置绝对正确.dll的名称不是很强,因此publicKeyToken ="null".我所有的版本都是1.0.0.0.当我查看引用的dll的属性时,文化"为空白.我也应该吗?看来我做错了什么吗?

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?

推荐答案

App.config不应在dll上使用,而只能与可执行文件一起使用.

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

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

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..

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

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

更新

在以下问题中找到了更多信息: C#DLL配置文件

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

这篇关于app.configdependentAssembly不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆