【发布时间】:2019-06-13 03:59:45
【问题描述】:
您好,当我发布它时,我的 WebService 上出现此跟随错误,
- 找不到方法: 'System.Collections.ObjectModel.Collection`1 System.Net.Http.Formatting.MediaTypeFormatter.get_SupportedMediaTypes()'。
但是当我在 VS 调试模式下使用它时,它不会发生。 我已经用谷歌搜索了它并尝试在 webconfig 上使用程序集引用,但它没有用 有什么建议吗?
这是我当前的 webconfig 文件
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<system.web>
<customErrors mode="Off"/>
</system.web>
<system.webServer>
<httpErrors errorMode="Detailed" />
</system.webServer>
<system.web>
<httpRuntime executionTimeout="3000000" maxRequestLength="1048576" />
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<authentication mode="Windows" />
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
</system.web>
<runtime>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0"/>
</dependentAssembly>
</runtime>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttp" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000" />
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
这是抛出错误的类
class WebApiConfig
{
public static void Register(HttpConfiguration configuration)
{
configuration.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
configuration.Routes.MapHttpRoute("API Default", "api/{controller}/{id}",
new { id = RouteParameter.Optional });
}
}
【问题讨论】:
-
你能显示 web.config 添加“程序集参考”吗? (我不知道你的意思)
-
@CiubotariuFlorin 我认为 OP 指的是binding redirect。 OP:您可能需要添加版本号(visual studio、.net 框架、dll 版本)
-
嘿!我刚刚更新了 web.config 代码,我正在使用的版本是程序集 System.Net.Http.Formatting, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
标签: c# web-services