并排配置错误,无法解析引用 mscorlib

Posted

技术标签:

【中文标题】并排配置错误,无法解析引用 mscorlib【英文标题】:Side By Side Configuration error, Cannot resolve reference mscorlib 【发布时间】:2016-01-31 17:54:31 【问题描述】:

我有 delphi 应用程序 (hostproject.exe),我想使用无注册技术的 .net com 对象 (NetSide.dll)。

应用程序启动时,显示 Side by Side Configuration 错误和 sxtrace 日志:

无法解析引用 mscorlib,publicKeyToken="b77a5c561934e089", 版本=“4.0.0.0”。

hostproject.exe.manifest

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>    
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity type="win32" name="client" version="1.0.0.0" />
  <dependency>
      <dependentAssembly>
          <assemblyIdentity type="win32" name="NetSide.sxs" version="1.0.0.0" processorArchitecture="msil"/>
      </dependentAssembly>
  </dependency>
</assembly>

NetSide.sxs.manifest

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity type="win32" name="NetSide.sxs" version="1.0.0.0"  processorArchitecture="msil"/>
  <clrClass clsid="E6C4A866-F58C-415E-9745-E0E7812B4386" progid="NetSide.Class1" threadingModel="Both" name="NetSide.Class1" runtimeVersion="v4.0.30319"/>
  <file name="NetSide.dll" hashalg="SHA1"/>   
  <dependency>
    <dependentAssembly>
        <assemblyIdentity name="mscorlib" version="4.0.0.0"  processorArchitecture="x86"  publicKeyToken="b77a5c561934e089"/>
    </dependentAssembly>
  </dependency>
</assembly>

sxstrace 日志如下:

=================
Begin Activation Context Generation.
Input Parameter:
    Flags = 0
    ProcessorArchitecture = Wow32
    CultureFallBacks = en-US;en
    ManifestPath = G:\Debug\HostProject.exe.Manifest
    AssemblyDirectory = G:\Debug\
    Application Config File = 
-----------------
    INFO: Parsing Manifest File G:\Debug\HostProject.exe.Manifest.
    INFO: Manifest Definition Identity is client11,type="win32",version="1.0.0.0".
    INFO: Reference: NetSide.sxs,processorArchitecture="msil",type="win32",version="1.0.0.0"
    INFO: Resolving reference NetSide.sxs,processorArchitecture="msil",type="win32",version="1.0.0.0".
    INFO: Resolving reference for ProcessorArchitecture msil.
        INFO: Resolving reference for culture Neutral.
            INFO: Applying Binding Policy.
                INFO: No binding policy redirect found.
            INFO: Begin assembly probing.
                INFO: Did not find the assembly in WinSxS.
                INFO: Attempt to probe manifest at G:\Debug\NetSide.sxs.DLL.
                INFO: Attempt to probe manifest at G:\Debug\NetSide.sxs.MANIFEST.
                INFO: Manifest found at G:\Debug\NetSide.sxs.MANIFEST.
            INFO: End assembly probing.
INFO: Resolving reference NetSide.sxs.mui,language="&#x2a;",processorArchitecture="msil",type="win32",version="1.0.0.0".
    INFO: Resolving reference for ProcessorArchitecture msil.
        INFO: Resolving reference for culture en-US.
            INFO: Applying Binding Policy.
                INFO: No binding policy redirect found.
            INFO: Begin assembly probing.
                INFO: Did not find the assembly in WinSxS.
                INFO: Did not find manifest for culture en-US.
            INFO: End assembly probing.
        INFO: Resolving reference for culture en.
            INFO: Applying Binding Policy.
                INFO: No binding policy redirect found.
        INFO: Begin assembly probing.
            INFO: Did not find the assembly in WinSxS.
            INFO: Did not find manifest for culture en.
        INFO: End assembly probing.
INFO: Parsing Manifest File G:\Debug\NetSide.sxs.MANIFEST.
    INFO: Manifest Definition Identity is NetSide.sxs,processorArchitecture="msil",type="win32",version="1.0.0.0".
        INFO: Reference: mscorlib,publicKeyToken="b77a5c561934e089",version="4.0.0.0"
        INFO: Resolving reference mscorlib,publicKeyToken="b77a5c561934e089",version="4.0.0.0".
        INFO: Resolving reference for ProcessorArchitecture mscorlib,publicKeyToken="b77a5c561934e089",version="4.0.0.0".
        INFO: Resolving reference for culture Neutral.
            INFO: Applying Binding Policy.
                INFO: No publisher policy found.
                INFO: No binding policy redirect found.
            INFO: Begin assembly probing.
                INFO: Did not find the assembly in WinSxS.
                INFO: Attempt to probe manifest at C:\Windows\assembly\GAC\mscorlib\4.0.0.0__b77a5c561934e089\mscorlib.DLL.
                INFO: Attempt to probe manifest at G:\Debug\mscorlib.DLL.
                INFO: Attempt to probe manifest at G:\Debug\mscorlib.MANIFEST.
                INFO: Attempt to probe manifest at G:\Debug\mscorlib\mscorlib.DLL.
                INFO: Attempt to probe manifest at G:\Debug\mscorlib\mscorlib.MANIFEST.
                INFO: Did not find manifest for culture Neutral.
            INFO: End assembly probing.
    ERROR: Cannot resolve reference mscorlib,publicKeyToken="b77a5c561934e089",version="4.0.0.0".
ERROR: Activation Context generation failed.
End Activation Context Generation.

【问题讨论】:

【参考方案1】:

从 NetSide.sxs 和 processorArchitecture 中删除对 mscorlib 的依赖:

<!-- We depend on the assembly NetSide.sxs -->
<dependency>
    <dependentAssembly>
        <assemblyIdentity type="win32" 
            name="NetSide.sxs" 
            version="1.0.0.0" 
            language="*"/>
    </dependentAssembly>
</dependency>


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblyIdentity type="win32" name="NetSide.sxs" version="1.0.0.0" />

  <clrClass clsid="E6C4A866-F58C-415E-9745-E0E7812B4386" progid="NetSide.Class1" threadingModel="Both" name="NetSide.Class1">
  </clrClass>

  <file name="NetSide.dll">
  </file>
</asmv1:assembly>

【讨论】:

以上是关于并排配置错误,无法解析引用 mscorlib的主要内容,如果未能解决你的问题,请参考以下文章

c#引用其它程序的程序集时报错

应用程序无法启动,因为它的并排配置不正确

Visual Studio 2010:无法解析目标框架“.NETFramework,Version=v4.0”的 mscorlib

opengl程序在别人电脑上vs上运行没问题,在我电脑上就一直报连接错误,觉得是glew配置问题。

运行 Qt Creator 时出现并排错误

TortoiseProc Launch failed: 应用程序无法启动,因为它的并排配置不正确