我有完全不使用Newtonsoft.Json库HttpSelfHostServer程序,但我得到以下错误:我不使用Newtonsoft.Json,但我得到一个错误说,它不能被发现
Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
at System.Net.Http.Formatting.JsonMediaTypeFormatter..ctor()
at System.Net.Http.Formatting.MediaTypeFormatterCollection.CreateDefaultFormatters()
at System.Net.Http.Formatting.MediaTypeFormatterCollection..ctor()
at System.Web.Http.HttpConfiguration.DefaultFormatters()
at System.Web.Http.HttpConfiguration..ctor(HttpRouteCollection routes)
at System.Web.Http.SelfHost.HttpSelfHostConfiguration..ctor(Uri baseAddress)
at System.Web.Http.SelfHost.HttpSelfHostConfiguration..ctor(String baseAddress)
我的代码:
using System;
using System.Web.Http;
using System.Web.Http.SelfHost;
using System.Runtime.InteropServices;
using System.IO;
var selfHostConfiguraiton = new HttpSelfHostConfiguration("http://localhost:8080"); <- Error
selfHostConfiguraiton.Routes.MapHttpRoute(
name: "DefaultApiRoute",
routeTemplate: "endpoints/{controller}",
defaults: null);
using (var server = new HttpSelfHostServer(selfHostConfiguraiton))
{
Console.WriteLine("Server started");
server.OpenAsync().Wait();
}
我确实在其他项目中使用Json.NET,但没有这个。
错误发生在这条线
var selfHostConfiguraiton = new HttpSelfHostConfiguration("http://localhost:8080");
并且在app.config中它没有提及。
感谢您的建议。
WebAPI内部使用'Json.NET'。 –