尝试通过方法“System.Web.Helpers.Json..cctor()"访问方法“System.Web.Helpers.Json.CreateSerializer()"失败

编程入门 行业动态 更新时间:2024-10-26 12:32:28
本文介绍了尝试通过方法“System.Web.Helpers.Json..cctor()"访问方法“System.Web.Helpers.Json.CreateSerializer()"失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 System.Web.Helpers.Json 在 NET 4 中将一些 JSON 反序列化为 dynamic.以下行失败并出现此错误:TypeInitializationException:尝试通过方法System.Web.Helpers.Json..cctor()"访问方法System.Web.Helpers.Json.CreateSerializer()"失败.

I am using System.Web.Helpers.Json to deserialize some JSON into dynamic in NET 4. The following line fails with this error: TypeInitializationException: Attempt by method 'System.Web.Helpers.Json..cctor()' to access method 'System.Web.Helpers.Json.CreateSerializer()' failed.

var json = Json.Decode(response);

response 很长但有效的 JSON.这里可能有什么问题?我已经尝试了 LINQPad 和一个简短的手工 JSON 并且它有效.这是某种配置问题吗?

The response is lengthy but valid JSON. What could be the matter here? I have tried LINQPad with a short handcrafted JSON and it worked. Is this a configuration issue of some sort?

这是实际的示例 JSON.看起来内容几乎无关紧要.当它在全新的控制台应用程序或 LINQPad 中运行时,它会按预期工作.但是,如果您尝试从全新的 Windows 窗体应用程序运行相同的代码,则会出现上述错误.

Here is the actual sample JSON. It appears the content is pretty much irrelevant. When this is run in a brand new Console application or LINQPad, it works as expected. But if you try to run the same code from a brand new Windows Forms application, it barfs with the above error.

var json = Json.Decode("{"r":{"0":{"id":"2"},"1":{"id":"33"}}}");

实际上,这与项目类型无关.如果正在调试项目,则会引发异常.如果只是运行,则不会发生异常.很奇怪吧?

Actually, it turns out this has nothing to do with project types. The exception is thrown if the project is being debugged. If it is simply run, the exception does not occur. Strange, eh?

推荐答案

我忘记了这个问题,同时我找到了我的答案.我认为它在 Microsoft 的 Connect 站点上的某个地方,但我不确定.所以现在让我们分享一下.

I forgot about this question and I found my answer in the meantime. I think it was somewhere on Microsoft's Connect site but I am not sure. So let's share it now.

基本上,为了解决此问题,您需要确保在调试"下的项目设置中取消选中启用 Visual Studio 托管进程".我不确定为什么会发生这种情况,但这绝对是一种修复"它的方法.一旦我发现了这一点,我就停止了寻找答案.对我来说已经足够了.

Basically, in order to workaround this problem you need to make sure "Enable the Visual Studio hosting process" is unchecked in your project's settings under Debug. I am not sure why it's happening but this is definitely a way to "fix" it. I stopped searching for answers once I found out about this. It was good enough for me.

更多推荐

尝试通过方法“System.Web.Helpers.Json..cctor()"访问方法“System.Web.Helpers.Json.Create

本文发布于:2023-11-12 07:46:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580913.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   Web   System   Helpers   CreateSerializer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!