此代码:Json.NET说:“操作可能破坏运行时”下的.NET 4中,但不是在.NET 3.5
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
var client = new WebClient();
client.Headers.Add("User-Agent", "Nobody");
var response = client.DownloadString(new Uri("http://www.hanselman.com/smallestdotnet/json.ashx"));
var j = JsonConvert.DeserializeObject<SmallestDotNetThing>(response);
}
public class SmallestDotNetThing
{
public DotNetVersion latestVersion { get; set; }
public List<DotNetVersion> allVersions { get; set; }
public List<DotNetVersion> downloadableVersions { get; set; }
}
public class DotNetVersion
{
public int major { get; set; }
public int minor { get; set; }
public string profile { get; set; }
public int? servicePack { get; set; }
public string url { get; set; }
}
}
}
会抛出异常“操作可能破坏运行”的反序列化时使用.NET 4下的.NET 4版JSON.NET。
但是,将目标切换到3.5(以及将JSON.NET引用更改为3.5版)效果很好。我使用NuGet的JSON.NET。
想法?
我没有得到一个在我的机器上在.NET 4下运行相同的错误。有几个人表示他们遇到过这个错误,但我还没有弄清楚原因是什么。 – 2011-04-01 21:42:23
奇怪。我在7 x64 SP1 ...你? – 2011-04-07 18:44:58
Windows 7 x64也是如此。 – 2011-04-09 01:52:45