昨天,今天,明天,每天的每天,你是否都多懂得一点点...

星期二, 四月 23, 2013

Fiddler 引用 C# dll

之前失败, 后来就莫名其妙的好了。 在现在也不知道缘由。

最开始是用.net 4.0 编译--


Script Failure
OK
Failed to load script.
 c:\Users\ydeng\Documents\Fiddler2\Scripts\ForFiddler.dll
System.BadImageFormatException: Could not load file or assembly 'file:///c:\Users\ydeng\Documents\Fiddler2\Scripts\ForFiddler.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
File name: 'file:///c:\Users\ydeng\Documents\Fiddler2\Scripts\ForFiddler.dll'
   at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
   at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at Microsoft.JScript.VsaReference.Compile(Boolean throwOnFileNotFound)

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorwks.dll
Running under executable  C:\Program Files (x86)\Fiddler2\Fiddler.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: User = CHECKFREE\ydeng
LOG: Where-ref bind. Location = c:\Users\ydeng\Documents\Fiddler2\Scripts\ForFiddler.dll
LOG: Appbase = file:///C:/Program Files (x86)/Fiddler2/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\Program Files (x86)\Fiddler2\Fiddler.exe.Config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v2.0.50727\config\machine.config.
LOG: The same bind was seen before, and was failed with hr = 0x8013101b.
   at Microsoft.JScript.VsaReference.Compile(Boolean throwOnFileNotFound)
   at Microsoft.JScript.VsaReference.Compile()
   at Microsoft.JScript.Vsa.VsaEngine


出了以上错误, 于是改成 .net 2.0 编译, 还是一样。

于是注意到错误中有 Framework64 这个东西。 觉得奇怪, 32位的程序怎么找 Framework64的东西呢。

于是

在网上找了这样一行命令

"c:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64\CorFlags.exe" MyApplication.exe /32bit+

强制将FIDDLER 在32位执行。

于是得到这个错误, 错误变了:

Script Failure
OK
Failed to load script.
 c:\Users\ydeng\Documents\Fiddler2\Scripts\ForFiddler.dll
System.BadImageFormatException: Could not load file or assembly 'ForFiddler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'ForFiddler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
   at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
   at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
   at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, StackCrawlMark& stackMark)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at Microsoft.JScript.VsaReference.Compile(Boolean throwOnFileNotFound)

   at Microsoft.JScript.VsaReference.Compile(Boolean throwOnFileNotFound)
   at Microsoft.JScript.VsaReference.Compile()
   at Microsoft.JScript.Vsa.VsaEngine.DoCompile()
   at Microsoft.Vsa.BaseVsaEngine.Compile()
   at Fiddler.FiddlerScript._LoadScript(String sScriptFilename, Boolean bPlaySounds)
   at Fiddler.FiddlerScript.LoadRulesScript(Boolean bPlaySounds)


其实这是更错。 后来把fiddler 关了, 再把备份的fiddler.exe 还原回去。 就突然可以了。

好像原因就是最之前没有.net 2.0 编译。 虽然后来改了过来了, 可是因为某些原因没有生效。

现在不管是用 x86, x64, any cpu 都不出错了。

Feng

没有评论:

其它博客地址

此博客的同步博客地址: http://fengnz.wordpress.com
这里进入我的MSN SPACE.