"The application has failed to start because its side-by-side configuration is incorrect."

本文介绍了一款使用Visual Studio 2008开发的exe程序在Windows Server 2008 R2上遇到的运行问题及解决办法。通过使用sxstrace.exe进行跟踪发现,缺少必要的Microsoft.VC90.CRT组件导致程序无法启动,最终通过安装vcredist得以解决。

背景:

      前段时间写了一个exe程序,一直以来运行在xp,server 2003上面,都运行良好。最近需要把它重新部署到一台新的server上面,是Windows server 2008 R2 Standard版,不想却一直不能正常运行。

 

症状:

      当双击运行程序时,弹出错误窗口,如下:

 

打开 Event Viewer,错误信息如下:

Activation context generation failed for "C:/xxx/xxxxx/xxx.exe". Dependent Assembly Microsoft.VC90.CRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.21022.8" could not be found. Please use sxstrace.exe for detailed diagnosis.

 

继续,用sxstrace.exe 来跟踪错误:

1. 开始运行

C:/Windows/system32>sxstrace.exe trace -logfile:c:/mytrace.etl
Tracing started. Trace will be saved to file c:/mytrace.etl.
Press Enter to stop tracing...

2. 双击应用程序,重现错误

3. 关闭上面运行的sxstrace.exe

4. 导出错误信息

C:/Windows/system32>sxstrace.exe parse -logfile:c:/mytrace.etl -outfile:c:/mytrace.txt
Parsing log file c:/mytrace.etl...
Parsing finished! Output saved to file c:/mytrace.txt.

 

错误信息如下:

=================
Begin Activation Context Generation.
Input Parameter:
    Flags = 0
    ProcessorArchitecture = Wow32
    CultureFallBacks = en-US;en
    ManifestPath = C:/xxx/xxxxx/xxx.exe
    AssemblyDirectory = C:/xxx/xxxxx/
    Application Config File =
-----------------
INFO: Parsing Manifest File C:/xxx/xxxxx/xxx.exe.
    INFO: Manifest Definition Identity is (null).
    INFO: Reference: Microsoft.VC90.CRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.21022.8"
    INFO: Reference: Microsoft.VC90.MFC,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.21022.8"
INFO: Resolving reference Microsoft.VC90.CRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.21022.8".
    INFO: Resolving reference for ProcessorArchitecture WOW64.
        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_32/Microsoft.VC90.CRT/9.0.21022.8__1fc8b3b9a1e18e3b/Microsoft.VC90.CRT.DLL.
                INFO: Did not find manifest for culture Neutral.
            INFO: End assembly probing.
    INFO: Resolving reference for ProcessorArchitecture x86.
        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_32/Microsoft.VC90.CRT/9.0.21022.8__1fc8b3b9a1e18e3b/Microsoft.VC90.CRT.DLL.
                INFO: Attempt to probe manifest at C:/carryquote/ServiceSHFE/Microsoft.VC90.CRT.DLL.
                INFO: Attempt to probe manifest at C:/carryquote/ServiceSHFE/Microsoft.VC90.CRT.MANIFEST.
                INFO: Attempt to probe manifest at C:/carryquote/ServiceSHFE/Microsoft.VC90.CRT/Microsoft.VC90.CRT.DLL.
                INFO: Attempt to probe manifest at C:/carryquote/ServiceSHFE/Microsoft.VC90.CRT/Microsoft.VC90.CRT.MANIFEST.
                INFO: Did not find manifest for culture Neutral.
            INFO: End assembly probing.
    ERROR: Cannot resolve reference Microsoft.VC90.CRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.21022.8".
ERROR: Activation Context generation failed.
End Activation Context Generation.

 

解决:

首先,C:/Windows/winsxs/Manifests 文件夹下面只有 x86_microsoft.vc90.mfc_1fc8b3b9a1e18e3b_9.0.30729.1_none_dcc7eae99ad0d9cf 的 manifest 和 cat文件,但是没有找到 x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_bcb86ed6ac711f91 的 cat 和 manifest 文件。

所以可能是由于服务器中并没有安装关于 vs2008 的相关组件,所以产生上述错误。

 

从microsoft 官网下载 vcredist 程序, 安装之后,一切OK。

http://www.microsoft.com/downloads/en/details.aspx?familyid=9B2DA534-3E03-4391-8A4D-074B9F2BC1BF&displaylang=en

 

在WinPE环境中运行C#编写的EXE文件时,如果提示“side-by-side configuration incorrect”错误,通常是因为WinPE缺少必要的Side-by-Side (SxS) 配置信息或相关依赖项未正确部署。C#程序通常依赖于.NET Framework或.NET Core/5+运行时,这些运行时依赖SxS机制来加载所需的组件。 ### 错误原因分析 1. **缺少Visual C++ Redistributable包**:C#程序可能依赖于某些版本的VC++运行库,而WinPE默认不包含这些库[^1]。 2. **缺少.NET Framework或.NET运行时**:如果程序是基于.NET Framework开发的,WinPE中必须手动部署.NET Framework的子集或完整的运行时[^1]。 3. **缺少或损坏的Manifest文件**:SxS配置错误通常与应用程序的Manifest文件缺失或配置不正确有关[^1]。 4. **WinPE环境限制**:WinPE是一个最小化的Windows环境,通常不包含完整的系统服务和依赖项,因此需要手动添加所需的组件。 ### 解决方法 #### 1. 添加VC++运行时库 确保WinPE中包含所需的Visual C++ Redistributable包。可以将以下文件复制到WinPE中: - `vcruntime140.dll` - `msvcp140.dll` - `concrt140.dll` - `vcomp140.dll` 将这些文件放置在WinPE的`Windows\System32`目录下,并在应用程序目录中添加一个`app.manifest`文件,内容如下: ```xml <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a9e18e5b" /> </dependentAssembly> </dependency> </assembly> ``` #### 2. 部署.NET运行时 如果程序依赖.NET Framework,需要将.NET Framework的必要组件部署到WinPE中。可以使用`dotnetfx`的精简版或使用`xcopy`方式部署.NET运行时到WinPE中。例如: -.NET Framework的DLL文件复制到WinPE的`Windows\Microsoft.NET\Framework\v4.0.30319`目录下。 - 确保在应用程序目录中包含正确的配置文件(如`app.config`或`yourapp.exe.config`)。 #### 3. 配置SxS支持 在WinPE中启用SxS支持,可以通过以下步骤: - 在构建WinPE镜像时,添加`WinPE-SecureBoot-Cfg`和`WinPE-SideBySide`组件。 - 使用`dism`命令将SxS支持添加到WinPE镜像中: ```cmd dism /Add-Package /Image:C:\WinPE\mount /PackagePath:C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-SideBySide.cab ``` #### 4. 使用静态链接或依赖项打包工具 考虑使用静态链接或工具如[Costura.Fody](https://github.com/Fody/Costura)将所有依赖项嵌入到EXE文件中,以减少对WinPE环境的依赖。这样可以避免SxS配置问题。 #### 5. 检查Manifest文件 确保应用程序的Manifest文件正确无误,并且与程序的依赖项匹配。可以使用`mt.exe`工具验证和嵌入Manifest文件: ```cmd mt.exe -manifest yourapp.exe.manifest -outputresource:yourapp.exe;1 ``` ### 示例代码:嵌入Manifest文件 ```cmd mt.exe -manifest app.manifest -outputresource:MyApp.exe;1 ``` ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值