错误的 IL 格式 - 奇怪的 .NET 错误

Phi*_*lip 3 c# sql-server asp.net azure azure-web-app-service

我通过 Azure 中的 .NET 应用程序随机收到此错误消息。

关于该错误的可用信息似乎非常有限,我想知道是否有人知道可能是什么原因造成的?

它似乎是在调用某个存储过程时发生的,但它真的很难重新创建并且随机发生。

System.BadImageFormatException: Bad IL format.
 at System.Data.SqlClient.SqlConnection.ValidateAndReconnect(Action beforeDisconnect, Int32 timeout)
 at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
 at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite, String method)
 at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName)
 at System.Data.SqlClient.SqlCommand.BeginExecuteNonQuery(AsyncCallback callback, Object stateObject)
 at System.Threading.Tasks.TaskFactory`1.FromAsyncImpl(Func`3 beginMethod, Func`2 endFunction, Action`1 endAction, Object state, TaskCreationOptions creationOptions)
 at System.Data.SqlClient.SqlCommand.ExecuteNonQueryAsync(CancellationToken cancellationToken)
Run Code Online (Sandbox Code Playgroud)

ric*_*sch 9

这可能是因为处理器体系结构不匹配:例如,在使用 32 位时加载 64 位程序集会导致这种情况。

要检查的一些事项:

  • 如果您的应用程序使用 32 位组件,请确保它始终作为 32 位应用程序运行。
  • 确保您没有使用使用不同版本的 .NET Framework 创建的组件。
  • 确保文件映像是有效的托管程序集或模块。

而且,就列表中的第一项而言:

如果应用程序项目的Platform target属性设置为AnyCPU,则编译的应用程序可以在 64 位或 32 位模式下运行。当它作为 64 位应用程序运行时,即时 (JIT) 编译器生成 64 位本机代码。如果应用程序依赖于 32 位托管或非托管组件,则该组件将无法在 64 位模式下加载。要更正此问题,请将项目的平台目标属性设置为x86并重新编译。

来源:故障排除异常:System.BadImageFormatException