gpt4 book ai didi

c# - 找不到类型或命名空间名称 'FormatterContext' .net 4.5

转载 作者:太空宇宙 更新时间:2023-11-03 16:04:13 26 4
gpt4 key购买 nike

我的项目框架:.net 4.5
项目类型:MVC4
我添加了framework 4.0的System.Json。
我在 Model -> JsonNetFormatter.cs 中添加了以下代码,它继承了 MediaTypeFormatter 类:

protected override System.Threading.Tasks.Task<object> OnReadFromStreamAsync(Type type, System.IO.Stream stream, System.Net.Http.Headers.HttpContentHeaders contentHeaders, FormatterContext formatterContext)
{
var task = Task<object>.Factory.StartNew(() =>
{
var settings = new JsonSerializerSettings()
{
NullValueHandling = NullValueHandling.Ignore,
};

var sr = new StreamReader(stream);
var jreader = new JsonTextReader(sr);

var ser = new JsonSerializer();
ser.Converters.Add(new IsoDateTimeConverter());

object val = ser.Deserialize(jreader, type);
return val;
});

return task;
}

但是当我要构建解决方案或我的项目时,它会抛出以下错误:

找不到类型或命名空间名称“FormatterContext”(是否缺少 using 指令或程序集引用?)

我是否缺少任何 dll 或由于其他原因,它抛出错误?

最佳答案

FormatterContextMVC4 RC 版本中被移除

请引用发行说明:Release notes

来自:MSDN Forums

Formatter improvements: The methods on MediaTypeFormatter are now public to enable unit testing of custom formatters. A single formatter can now support multiple text encodings. Use BufferedMediaTypeFormatter to implement simple synchronous formatting support. FormatterContext has been removed. To get access to the request from a formatter on the server implement GetPerRequestFormatterInstance.

关于c# - 找不到类型或命名空间名称 'FormatterContext' .net 4.5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20095701/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com