在machine.config中忽略.NET assemblyBinding配置
我有一种情况,我需要能够根据它们的部分名称在GAC中加载程序集。为了做到这一点我已经添加以下到我的app.config文件:
I have a situation where I need to be able to load assemblies in the GAC based on their partial names. In order to do this I have added the following to my app.config file:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="MyAssembly"
fullName= "MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0123456789abcdef"/>
</assemblyBinding>
</runtime>
这完全符合我的想法。但是,如果我在我的machine.config文件中放置相同的元素,它似乎被忽略,我尝试加载MyAssembly时得到FileNotFoundExceptions。
This works exactly the way I want it to. However, if I place the same element in my machine.config file, it seems to be ignored, and I get FileNotFoundExceptions when trying to load MyAssembly.
以下是当元素在我的app.config中,并且绑定成功:
The following is the assembly binding log when the element is in my app.config, and the bind succeeds:
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Documents and Settings\jon_scheiding\My Documents\Source\Testing\Test Projects 1\Cmd\bin\Debug\Testers.Cmd.vshost.exe.config
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Partial reference qualified from config file. New reference: MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0123456789abcdef.
LOG: Post-policy reference: MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0123456789abcdef
LOG: Found assembly by looking in the GAC.
LOG: Binding succeeds. Returns assembly from C:\WINDOWS\assembly\GAC_MSIL\MyAssembly\1.0.0.0__b20f4683c1030dbd\MyAssembly.dll.
LOG: Assembly is loaded in default load context.
对比我的配置在machine.config中的日志, :
Contrast that with the log when my configuration is in machine.config, and the bind fails:
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Documents and Settings\jon_scheiding\My Documents\Source\Testing\Test Projects 1\Cmd\bin\Debug\Testers.Cmd.vshost.exe.config
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Documents and Settings/jon_scheiding/My Documents/Source/Testing/Test Projects 1/Cmd/bin/Debug/MyAssembly.DLL.
LOG: Attempting download of new URL file:///C:/Documents and Settings/jon_scheiding/My Documents/Source/Testing/Test Projects 1/Cmd/bin/Debug/MyAssembly/MyAssembly.DLL.
LOG: Attempting download of new URL file:///C:/Documents and Settings/jon_scheiding/My Documents/Source/Testing/Test Projects 1/Cmd/bin/Debug/MyAssembly.EXE.
LOG: Attempting download of new URL file:///C:/Documents and Settings/jon_scheiding/My Documents/Source/Testing/Test Projects 1/Cmd/bin/Debug/MyAssembly/MyAssembly.EXE.
LOG: All probing URLs attempted and failed.
问题似乎是第四行,政策目前不适用于参考。
The problem seems to be the fourth line, "Policy not being applied to reference at this time." However, I can find very little documentation on what this message means, or how to address it.
如何让框架识别我的<运行时>元素?
How can I get the framework to recognize my <runtime> element?
提前感谢!
t从machine.config中读取qualifyAssebmly配置,它只从应用程序配置文件中读取它。
The framework won't read qualifyAssebmly configuration from machine.config, it only reads it from your application configuration file.
框架确实识别您的runtim元素,但它不识别qualifyAssembly元素。
The framework does recognize your runtim element, however it does not recognize the qualifyAssembly element.