找不到方法:“ System.String System.String.Format(System.IFormatProvider,System.String,System.Object)”

时间:2019-04-19 19:21:43

标签: c# asp.net iis

我有两台服务器,但运行的设置大致相同-IIS,SQL Server等。一个给我这个错误,而另一个没有。我从Visual Studio向两个发布了相同的代码。

它们都在运行.NET CLR Version v4.0.30319,我相信它是4.5

Some answers说您必须定位另一个版本,如果我在Visual Studio中更改它,一切都会中断,事实并非如此。同样,相同的代码在其他服务器上运行。

Other answers说,某些旧的DLL可能是原因。我没有部署到工作服务器上,所以也许复制了一些较新的DLL?但是我怎么知道?

此外,该错误似乎不是在我的代码中,而是在框架和Umbraco中,所以我认为我不应该进行更新字符串函数之类的事情:

[MissingMethodException: Method not found: 'System.String System.String.Format(System.IFormatProvider, System.String, System.Object)'.]
   System.Net.Http.Headers.MediaTypeHeaderValue.CheckMediaTypeFormat(String mediaType, String parameterName) +0
   System.Net.Http.Headers.MediaTypeHeaderValue..ctor(String mediaType) +33
   System.Net.Http.Formatting.MediaTypeConstants..cctor() +45

[TypeInitializationException: The type initializer for 'System.Net.Http.Formatting.MediaTypeConstants' threw an exception.]
   System.Net.Http.Formatting.JsonMediaTypeFormatter..ctor() +99
   System.Net.Http.Formatting.MediaTypeFormatterCollection.CreateDefaultFormatters() +49
   System.Web.Http.HttpConfiguration..ctor(HttpRouteCollection routes) +255
   System.Web.Http.GlobalConfiguration.<CreateConfiguration>b__0() +78
   System.Lazy`1.CreateValue() +14308960
   System.Lazy`1.LazyInitValue() +524
   Umbraco.Web.WebBootManager.InitializeResolvers() +1530
   Umbraco.Core.CoreBootManager.Initialize() +814
   Umbraco.Web.WebBootManager.Initialize() +19
   Umbraco.Core.UmbracoApplicationBase.StartApplication(Object sender, EventArgs e) +244

[HttpException (0x80004005): The type initializer for 'System.Net.Http.Formatting.MediaTypeConstants' threw an exception.]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +588
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +181
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +322
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +402
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +452

[HttpException (0x80004005): The type initializer for 'System.Net.Http.Formatting.MediaTypeConstants' threw an exception.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +646
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +778

通常,Google上没有太多信息,因此不确定该怎么做。欢迎任何见识!

1 个答案:

答案 0 :(得分:3)

如果您检出documentation,则该过载似乎仅在.NET 4.6上可用。服务器可能具有不同的.NET Framework版本。

.NET 4.5上最近的重载:

Format(IFormatProvider, String, Object[])

.NET 4.6上有完全相同的重载:

Format(IFormatProvider, String, Object)

确保两台服务器均已正确安装.NET 4.6。