The type or namespace name 'FormatterContext' could not be found .net 4.5

女生的网名这么多〃 提交于 2020-01-04 05:51:07

问题


My project framework : .net 4.5
Project Type : MVC4
I have added System.Json of framework 4.0.
I have following code into Model -> JsonNetFormatter.cs and it's inheriting MediaTypeFormatter class:

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;
        }

but when i am going to build solution or my project, it's throwing following error :

The type or namespace name 'FormatterContext' could not be found (are you missing a using directive or an assembly reference?)

Am i missing any dll or because of something else, it's throwing an error?


回答1:


FormatterContext is removed in MVC4 RC Version

Please refer the Release Notes: Release notes

from : 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.



来源:https://stackoverflow.com/questions/20095701/the-type-or-namespace-name-formattercontext-could-not-be-found-net-4-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!