试图通过法“System.Web.Helpers.Json..cctor()”访问方法“System.Web.Helpers.Json.CreateSerializer()'失败

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

我使用 System.Web.Helpers.Json 反序列化一些JSON成在NET 4.动态下面的行失败,出现此错误: 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);

在响应是漫长的,但有效的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。它出现的内容是pretty的多少无关。当这是运行在一个全新的控制台应用程序或LINQPad,它将按预期工作。但是,如果你尝试从品牌运行相同的code新的Windows窗体应用程序,它与上述错误barfs。

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?

推荐答案

我忘了这个问题,我发现我的答案在此期间。我认为这是什么地方在微软的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.CreateSerial

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

发布评论

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

>www.elefans.com

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