【发布时间】:2014-11-05 16:52:42
【问题描述】:
我有一个 .net windows 服务,它需要加载两个不同版本的程序集。它在服务器 2012 R2 机器上运行。我在单独的.config 文件中使用绑定重定向,该文件在关闭</configuration> 节点(see MSDN doc)之前使用此文件加载到主app.config:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<linkedConfiguration href="file://E:\my-service\runtime.config" />
</assemblyBinding>
我的 runtime.config 包含实际的绑定重定向:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="AutoMapper" publicKeyToken="be96cd2c38ef1005" culture="neutral" />
<codeBase version="0.4.0.126" href="AutoMapper.dll" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="AutoMapper" publicKeyToken="be96cd2c38ef1005" culture="neutral" />
<codeBase version="3.2.1.0" href="AutoMapper.3.2.1\AutoMapper.dll" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
在重新启动服务器之前,这一切正常。然后我们在机器启动后在事件日志中看到这一点:
Activation context generation failed for "Service.exe".
Error in manifest or policy file "Service.exe.Config" on line 71.
The element assemblyBinding appears as a child of element configuration which is not supported by this version of Windows.
所以我运行了sxstrace.exe 工具(根据这个blog)并得到这个输出:
=================
Begin Activation Context Generation.
Input Parameter:
Flags = 0
ProcessorArchitecture = AMD64
CultureFallBacks = en-US;en
ManifestPath = E:\my-service\Service.exe
AssemblyDirectory = E:\my-service\
Application Config File = E:\my-service\Service.exe.Config
-----------------
INFO: Parsing Application Config File E:\my-service\Service.exe.Config.
ERROR: Line 71: The element assemblyBinding appears as a child of element configuration which is not supported by this version of Windows.
ERROR: Activation Context generation failed.
End Activation Context Generation.
如果我从主 app.config 中删除 linkedConfiguration,服务就会启动(尽管有不同的错误)。然后我可以重新添加它,服务可以正常启动和停止,直到机器再次重新启动。
有人知道为什么会这样吗?这是linkedConfiguration的正确用法吗?
更新
在与 Microsoft 支持人员进行了长时间且富有成效的对话后,我发现不支持将 linkedConfiguration 与嵌入式清单一起使用 (see MSDN doc)。
但是,从外部文件加载配置似乎确实存在错误。我已将此作为bug on connect 提出。
【问题讨论】:
标签: .net app-config side-by-side