使用sxstrace.exe调试Windows应用程序运行时动态链接库的加载异常


sxstrace.exe Windows 系统自带的一个非常强大的工具,用于跟踪应用程序运行时动态链接库的加载情况。下面举一个案例,使用 sxstrace.exe 调试应用程序启动时抛出的"side-by-side"的加载异常。

 

在一台 WindowsServer 2008 R2 的系统中安装 python2.7 ,安装完成后运行 python.exe ,结果弹出下面的错误:

•ueaap aÅOl_u poa aga asn 601 aua,xa uoqe3!ldde aga aas aseald • pancnu! uoqeÅn6gucn asnzaq :ueas oa pal!' seq uoqe3!ldde agl axa

 

启动失败可能与动态链接库的加载有关,这时使用sxstrace.exe进行跟踪,首先以管理员权限打开 cmd ,输入下面的命令开始追踪:

C:\Users\daniel>sxstrace parse -logfile:c:\myTrace.log

 

接着,复现上面的问题(报错)。

 

复现完成后,在 cmd 窗口使用 ENTER 键停止 trace

C:\Users\daniel>sxstracetrace -logfile:c:\myTrace.log

Tracing started.Trace will be saved to file c:\myTrace.log.

Press Enter to stoptracing...

C:\Users\daniel>

 

日志文件已经保存到上面指定的c:\myTrace.log 中,但是这个文件内容并不是可读的,需要进一步进行解析,使用下面的命令将日志文件内容解析为可读的内容:

C:\Users\daniel>sxstraceParse -logfile:c:\myTrace.log -outfile:c:\mysxsTrace.txt

Parsinglog file c:\myTrace.log...

Parsingfinished! Output saved to file c:\mysxsTrace.txt.

 

打开解析后得到的文件c:\mysxsTrace.txt,内容如下:

=================

Begin Activation Context Generation.

Input Parameter:

Flags = 0

ProcessorArchitecture = AMD64

CultureFallBacks = en-US;en

ManifestPath = C:\Python27\python.exe

AssemblyDirectory = C:\Python27\

Application Config File =

-----------------

INFO: Parsing Manifest File C:\Python27\python.exe.

INFO: Manifest Definition Identity is (null).

INFO: Reference: Microsoft.VC90.CRT,processorArchitecture="amd64",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",v

ersion="9.0.21022.8"

INFO: Resolving reference Microsoft.VC90.CRT,processorArchitecture="amd64",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version=

"9.0.21022.8".

INFO: Resolving reference for ProcessorArchitecture amd64.

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_64\Microsoft.VC90.CRT

\9.0.21022.8__1fc8b3b9a1e18e3b\Microsoft.VC90.CRT.DLL.

INFO: Attempt to probe manifest at C:\Python27\Microsoft.VC90.CRT.DLL.

INFO: Attempt to probe manifest at C:\Python27\Microsoft.VC90.CRT.MANIFEST.

INFO: Manifest found at C:\Python27\Microsoft.VC90.CRT.MANIFEST.

INFO: End assembly probing.

INFO: Resolving reference Microsoft.VC90.CRT.mui,language="*",processorArchitecture="amd64",publicKeyToken="1fc8b3b9a1e18e3b

",type="win32",version="9.0.21022.8".

INFO: Resolving reference for ProcessorArchitecture amd64.

INFO: Resolving reference for culture en-US.

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_64\Microsoft.VC90.CRT.mui\9.0.21022.8_en-US_1fc8b3b9a1e18e3b\Microsoft.VC90.CRT.mui.DLL.

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 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_64\Microsoft.VC90.CRT.mui\9.0.21022.8_en_1fc8b3b9a1e18e3b\Microsoft.VC90.CRT.mui.DLL.

INFO: Did not find manifest for culture en.

INFO: End assembly probing.

INFO: Parsing Manifest File C:\Python27\Microsoft.VC90.CRT.MANIFEST.

INFO: Manifest Definition Identity is Microsoft.VC90.CRT,processorArchitecture="amd64",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",v

ersion="9.0.30729.1".

ERROR: Component identity found in manifest does not match the identity of the component requested. Reference is Microsoft.VC90.CRT,processorArchitecture="amd64",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",v

ersion="9.0.21022.8". Definition is Microsoft.VC90.CRT,processorArchitecture="amd64",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",v

ersion="9.0.30729.1".

ERROR: Activation Context generation failed.

End Activation Context Generation.

 

查看上面的报错,发现报错信息还是比较明确的:

INFO: Parsing Manifest File C:\Python27\Microsoft.VC90.CRT.MANIFEST.

INFO: Manifest Definition Identity is Microsoft.VC90.CRT,processorArchitecture="amd64",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",ve

rsion="9.0.30729.1".

ERROR: Component identity found in manifest does not match the identity of the component requested. Reference is Microsoft.VC90.CRT,processorArchitecture="amd64",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",ve

rsion="9.0.21022.8". Definition is Microsoft.VC90.CRT,processorArchitecture="amd64",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",ve

rsion="9.0.30729.1".

ERROR: Activation Context generation failed.

End Activation Context Generation.

 

即在解析 C:\Python27\Microsoft.VC90.CRT.MANIFEST 文件时,发现需要引用的 Microsoft.VC90.CRT 的版本是 9.0.21022.8,但是 manifest 文件中定义的版本是9.0.30729.1,导致加载失败。

 

所以我们找到 C:\Python27\Microsoft.VC90.CRT.MANIFEST 文件,打开发现版本定义确实不是要引用的版本:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">

<noInheritable/>

<assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.30729.1" processorArchitecture="amd64" publicKeyToken="1fc8b3b9a1e18e3b"/>

<file name="msvcr90.dll" hashalg="SHA1" hash="24af0511e0ed6e84a0eaa542b5ed940cb93f6112">

<asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#">

<dsig:Transforms>

<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"/>

</dsig:Transforms>

<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>

<dsig:DigestValue>w+rhQEheVo6YaL7c+bf9GNxDIe0=</dsig:DigestValue>

</asmv2:hash>

</file>

<file name="msvcp90.dll" hashalg="SHA1" hash="c1647c8ab25a2bc28ad379da402808c710a038ac">

<asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#">

<dsig:Transforms>

<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"/>

</dsig:Transforms>

<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>

<dsig:DigestValue>aF4dNBhwwplOmPhrRVfVKH/0zvM=</dsig:DigestValue>

</asmv2:hash>

</file>

<file name="msvcm90.dll" hashalg="SHA1" hash="6ca953c26a9fc967bececb5b0ca087d6506cc432">

<asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#">

<dsig:Transforms>

<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"/>

</dsig:Transforms>

<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>

<dsig:DigestValue>h3+MSJByEnLrOAWSdH5H/mFaEaM=</dsig:DigestValue>

</asmv2:hash>

</file>

</assembly>

 

找到原因后,将这个版本修改为 9.0.21022.8,然后再次运行python.exe,运行正常:

 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值