请帮我翻译这个问题,我正在使用AsyncCtpLibrary和C#5 ctp编译器编写控制台应用程序。第一次运行一个等待的代码时,我遇到了这个错误:
System.BadImageFormatException was unhandled
Message=An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
Source=AsyncCtpLibrary
StackTrace:
Server stack trace:
at [...].<Execute>d__1c.MoveNext()
at [...].Execute()
at [...].<Move>d__1d.MoveNext() in[..]:line 266
Exception rethrown at [0]:
at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.<SetException>b__1(Object state)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
InnerException:
我是否遗漏了可以引用的dll文件?
重要新信息
我的失败方法如下:
public async override Task<bool> Execute()
{
//do stuff
await stuff;
//do other stuff
await base.Execute()
//do other stuff
return true;
}
我遵循了Jon Skeet的建议,试图逐步重现错误,现在我可以确定,await base.Execute()这一行是致命的!如果我将该行注释掉,一切都可以运行,如果我留下它,调用我的方法会立即失败(而不是在到达base.Execute()时)。所以我认为ctp编译器做了一些奇怪的事情。为什么?我应该永远不要做什么?这个bug有多大?
旧内容:
编辑:
至于32位/64位问题,我的系统是32位的(在虚拟机内),据我所知AsyncCtpLibrary.dll不包含非托管代码。所有我的项目(类库和单个控制台应用程序)都有像这样的构建选项卡:
可能还有什么问题吗?
编辑: 我还检查了Fusion日志查看器,AsyncCtpLibrary已经加载,没有任何错误:
*** Assembly Binder Log Entry (6/10/2011 @ 9:04:11 PM) ***
The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\Users\Daver\Documents\Visual Studio 2010\Projects\[...]\bin\Debug\MyApp.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = WIN-N74LV38NLV3\Daver
LOG: DisplayName = AsyncCtpLibrary, Version=1.0.4107.18181, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/Users/Daver/Documents/Visual Studio 2010/Projects/[...]/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyApp.exe
Calling assembly : MyLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Daver\Documents\Visual Studio 2010\Projects\[...]\bin\Debug\MyApp.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: AsyncCtpLibrary, Version=1.0.4107.18181, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Users/Daver/Documents/Visual Studio 2010/Projects/[...]/bin/Debug/AsyncCtpLibrary.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Users\Daver\Documents\Visual Studio 2010\Projects\[...]\bin\Debug\AsyncCtpLibrary.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: AsyncCtpLibrary, Version=1.0.4107.18181, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Binding succeeds. Returns assembly from C:\Users\Daver\Documents\Visual Studio 2010\Projects\[...]\bin\Debug\AsyncCtpLibrary.dll.
LOG: Assembly is loaded in default load context.
我也检查了由编译器生成的
<Execute>d__1c
类的 MoveNext() 方法的IL代码,它所引用的程序集([assemblyName])仅有mscorlib、System.Core和AsyncCtpLibrary。
我检查了我的dll和AsyncCtpLibrary的清单,我的清单中写着
.corflags 0x00000003 // ILONLY 32BITREQUIRED
,而AsyncCtpLibrary则写着.corflags 0x00000009 // ILONLY
,我不确定这是否可能是问题所在。请帮帮我,我已经没有更多的想法了!