首页 新闻 会员 周边

Question: App.Config for your DLL, failed

0
悬赏园豆:20 [已关闭问题]

desperate people take desperate measures.

这个在codeproject上看的的一个解决方案,拿来试试,不知道为什么不成功。
原文:http://www.codeproject.com/KB/dotnet/dllappconfig.aspx?msg=2823743#xx2823743xx

需求是:
给Dll添加一个Config文件是不行的. 是因为.NET一般只允许将Running application和一个Config绑定。
而程序一旦启动,The .NET Framework reads the application configuration file into a static hashtable whenever the application domain is first referenced. Once it is read, it cannot be reread or modified.

作者n10sive研究了System.Dll,发现
1.  修改ConfigurationSettings class 的静态变量"_configurationInitialized" 为false, 就可以“欺骗”.NET Framework, config file还没有读入。
2. null out the "_configSystem". 使得.NET Framework将config读入内存。

并且作者给出了包装好config参数的类,
如果你在程序中new这个类出来后,将会修改程序默认引用的myproject.vshost.exe.Config为mydll.dll.config


下面是我的理解,找他的方法做了一下,没有成功。
I have a Dll "MyDll.dll", with a "MyDll.dll.config" file:
And I have an App project,
Using this line to get the file path:
string str = MyDllConfig.ConnectionString();
but, when I debug into

MyDll.dll.Config

 

Code


"str" is MyDll.config which is under my execute app path.
but "cstr" is null!

I don't know why
ConfigurationManager.AppSettings["AlgorithmConfigFile"];
can't get the value "CashAcceptType.xml"

园子里是否有兄弟闲的有空,玩玩这个方法,呵呵。

PS:最后发现作者原来已经是CTO了,1977年就开始玩计算机软硬件了,呵呵。

Code
DylanWind的主页 DylanWind | 初学一级 | 园豆:185
提问于:2008-11-28 17:06
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册