试图通过法“System.Web.Helpers.Json..cctor()”访问方法“System.Web.Helpers.Json.CreateSerializer()'失败 [英] Attempt by method 'System.Web.Helpers.Json..cctor()' to access method 'System.Web.Helpers.Json.CreateSerializer()' failed

查看:629
本文介绍了试图通过法“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.CreateSerializer()'失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆