【问题标题】:'System.InvalidProgramException' occurred in RestSharp.dll on PC, on Laptop works fine'System.InvalidProgramException' 发生在 PC 上的 RestSharp.dll 中,在笔记本电脑上工作正常
【发布时间】:2016-08-12 14:31:04
【问题描述】:

所以我有 2 个项目的这个解决方案。我将整个解决方案从运行良好的笔记本电脑转移到出现此错误的 PC:

System.InvalidProgramException 未处理 HResult=-2146233030
Message=JIT 编译器遇到内部限制。
来源=RestSharp StackTrace: 在 RestSharp.Deserializers.XmlDeserializer.GetElementByName(XElement 根,XName 名称) 在 RestSharp.Deserializers.XmlDeserializer.GetValueFromXml(XElement 根, XName 名称,PropertyInfo 道具) 在 RestSharp.Deserializers.XmlAttributeDeserializer.GetValueFromXml(XElement 根、XName 名称、PropertyInfo 属性) 在 RestSharp.Deserializers.XmlDeserializer.Map(对象 x,XElement 根) 在 RestSharp.Deserializers.XmlDeserializer.Deserialize[T](IRestResponse 回复) 在 WolframAlphaNET.WolframAlpha.GetResponse[T](RestRequest request) 中 i:\VS_Projects_Shared\CCProject\WolframAlpha.NET\WolframAlpha.cs:line 390 在 i:\VS_Projects_Shared\CCProject\WolframAlpha.NET\WolframAlpha.cs:line 中的 WolframAlphaNET.WolframAlpha.Query(字符串查询) 374 在 CCProject.Search.button1_Click(Object sender, EventArgs e) 中 i:\VS_Projects_Shared\CCProject\CCProject\Search.cs:第 54 行 在 System.Windows.Forms.Control.OnClick(EventArgs e) 在 System.Windows.Forms.Button.OnClick(EventArgs e) 在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs 事件) 在 System.Windows.Forms.Control.WmMouseUp(消息和 m,MouseButtons 按钮,Int32 点击) 在 System.Windows.Forms.Control.WndProc(消息和 m) 在 System.Windows.Forms.ButtonBase.WndProc(消息和 m) 在 System.Windows.Forms.Button.WndProc(消息和 m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息和 m) 在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam) 在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(味精和味精) 在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 原因, Int32 pvLoopData) 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 原因,ApplicationContext 上下文) 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 原因,ApplicationContext 上下文) 在 System.Windows.Forms.Application.RunDialog(窗体) 在 System.Windows.Forms.Form.ShowDialog(IWin32Window 所有者) 在 System.Windows.Forms.Form.ShowDialog() 在 CCProject.Form1.button2_Click(Object sender, EventArgs e) 中 我:\VS_Projects_Shared\CCProject\CCProject\Form1.cs:第 97 行 在 System.Windows.Forms.Control.OnClick(EventArgs e) 在 System.Windows.Forms.Button.OnClick(EventArgs e) 在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs 事件) 在 System.Windows.Forms.Control.WmMouseUp(消息和 m,MouseButtons 按钮,Int32 点击) 在 System.Windows.Forms.Control.WndProc(消息和 m) 在 System.Windows.Forms.ButtonBase.WndProc(消息和 m) 在 System.Windows.Forms.Button.WndProc(消息和 m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息和 m) 在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam) 在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(味精和味精) 在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 原因, Int32 pvLoopData) 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 原因,ApplicationContext 上下文) 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 原因,ApplicationContext 上下文) 在 System.Windows.Forms.Application.Run(窗体 mainForm) 在 i:\VS_Projects_Shared\CCProject\CCProject\Program.cs:line 19 中的 CCProject.Program.Main() 在 System.AppDomain._nExecuteAssembly(RuntimeAssembly 程序集,字符串 [] 参数) 在 System.AppDomain.nExecuteAssembly(RuntimeAssembly 程序集,字符串 [] 参数) 在 System.AppDomain.ExecuteAssembly(字符串 assemblyFile,证据 assemblySecurity,String [] args) 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在 System.Threading.ThreadHelper.ThreadStart_Context(对象状态) 在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext、ContextCallback 回调、对象状态、布尔值 保留SyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback 回调, 对象状态, Boolean 保留SyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback 回调,对象状态) 在 System.Threading.ThreadHelper.ThreadStart() InnerException:

这行代码是 WolframAlpha.NET 的一部分 https://github.com/Genbox/WolframAlpha.NET

   private T GetResponse<T>(RestRequest request)
    {
        RestResponse response = (RestResponse)_client.Execute(request);
        XmlAttributeDeserializer deserializer = new XmlAttributeDeserializer();
        T results = deserializer.Deserialize<T>(response); //this line
        return results;
    }

以下是 PEVerify.exe 结果:

C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 工具>PEVerify.exe I:\ VS_Projects_Shared\CalorieCounter\CalorieCounter\bin\Debug\CalorieCounter.exe

Microsoft (R) .NET Framework PE 验证程序。版本 4.0.30319.33440 版权所有 (c) 微软公司。保留所有权利。

所有类和方法 我:\VS_Projects_Shared\CalorieCounter\CalorieCounter\bin\Debug\C alorieCounter.exe 已验证。

C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 工具>PEVerify.exe I:\ VS_Projects_Shared\CalorieCounter\CalorieCounter\bin\Debug\CalorieCounter.exe /md /il

Microsoft (R) .NET Framework PE 验证程序。版本 4.0.30319.33440 版权所有 (c) 微软公司。保留所有权利。

所有类和方法 我:\VS_Projects_Shared\CalorieCounter\CalorieCounter\bin\Debug\C alorieCounter.exe 已验证。

C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 工具>PEVerify.exe I:\ VS_Projects_Shared\CalorieCounter\CalorieCounter\bin\Debug\WolframAlpha.NET.dll

Microsoft (R) .NET Framework PE 验证程序。版本 4.0.30319.33440 版权所有 (c) 微软公司。保留所有权利。

所有类和方法 我:\VS_Projects_Shared\CalorieCounter\CalorieCounter\bin\Debug\W olframAlpha.NET.dll 已验证。

C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 工具>PEVerify.exe I:\ VS_Projects_Shared\CalorieCounter\CalorieCounter\bin\Debug\RestSharp.dll

Microsoft (R) .NET Framework PE 验证程序。版本 4.0.30319.33440 版权所有 (c) 微软公司。保留所有权利。

所有类和方法 我:\VS_Projects_Shared\CalorieCounter\CalorieCounter\bin\Debug\R estSharp.dll 已验证。

【问题讨论】:

  • 您只能移动源代码,然后重新创建解决方案,甚至是项目。这应该有效。
  • HRESULT 映射到以下 Win32 API 错误代码:COR_E_INVALIDPROGRAM: A program contained invalid IL or bad metadata. Usually this is a compiler bug. 您是否在 PC 和笔记本电脑上使用相同版本的 .NET Framework?编译器在 4.5 和 4.6.1 afaik 之间发生了变化。
  • @toadflakz 我从未安装过 4.6。我在 PC 和笔记本电脑上都只有 4.5.1

标签: c# visual-studio restsharp


【解决方案1】:

当翻译的 Microsoft 中间语言 (MSIL) 指令包含无效命令时,将引发错误 InvalidProgramException。由于无效或损坏的 MSIL 指令,即时 (JIT) 编译器不能再继续编译 MSIL 指令,并且 JIT 编译器会抛出 InvalidProgramException。 For more information look here。这可能意味着包含 GetResponse() 函数的已翻译文件(EXE 或 DLL)已损坏,需要重新翻译。另外两种可能性是您的 PC 上的 MSIL 翻译器有错误,或者捆绑到 EXE 或 DLL 中的 .NET Framework JIT 编译器有错误。您可以通过运行PEverify tool 来验证您的 EXE 或 DLL 中的 MSIL 代码来找出确切的问题。在上面链接的信息页面上,按照“如何解决 InvalidProgramException 异常”中的说明进行操作。运行 PEverify 后,请将结果添加到问题的末尾。

[编辑]

我一直在寻找其他解决方案来解决您的问题。 One solution I found 是将您的 Intellisense 设置更改为“仅显示事件”或完全关闭。我不知道为什么会这样,但据报道它是一种解决方案。

【讨论】:

  • 它说在笔记本电脑和 PC 上找不到文件或有错误的标题 oO,我使用什么 PEVerify.exe(v8.0、v8.1A)并不重要,而且我没有任何文件选择验证,任何 exe 或 dll 都会出现相同的错误。
  • 请将 PEverify 工具的完整结果发布到问题的末尾。我们需要知道所涉及的具体错误代码。还包括您使用的命令。例如:...NETFX 4.6.1 工具> PEVerify.exe "C:\Users[用户名]\Documents\Visual Studio 2015\Projects\Test\Test\bin\Debug\Test.exe"
  • 有添加的结果提问,所有验证ok
猜你喜欢
  • 1970-01-01
  • 2013-08-23
  • 1970-01-01
  • 2018-06-20
  • 2017-07-05
  • 1970-01-01
  • 2020-09-27
  • 1970-01-01
  • 2020-08-02
相关资源
最近更新 更多