在ASP.NET MVC应用程序(.NET 4.7)中,我在HttpResponseMessage
上使用了一个扩展方法。此方法在.NET Standard 2.0项目中创建。在调试和使用IIS Express时,它运行正常。
但是当发布到服务器时,它会返回“找不到方法”错误。在服务器(Windows Server 2008)上安装了所有需要的框架。
当我在调用扩展方法的方法中使用try / catch时,错误变得清晰。
在开发中,我期待它在服务器上运行。我错过了任何其他.NET框架吗?还是其他任何人都可以作为解决方案?
HttpResponseMessage response = client.GetAsync(UserManAPI).Result;
if (response.IsSuccessStatusCode)
{
apiResponse = response.Content.ReadAsStringAsync().Result;
}
else
response.ThrowReynaersException();
public static void ThrowReynaersException(this HttpResponseMessage response)
{
if (response.StatusCode == HttpStatusCode.OK)
{
using (var dataStream =
response.Content.ReadAsStreamAsync().Result)
{
if (dataStream != null)
{
var jsonResponse = JsonValue.Load(dataStream);
if (jsonResponse != null)
{
var rex =
JsonConvert.DeserializeObject<ReynaersException(jsonResponse,
new ReynaersExceptionConverter());
if (rex != null) throw rex;
var ex = JsonConvert.DeserializeObject<Exception>(jsonResponse, new ExceptionConverter());
if (ex != null) throw ex.ToReynaersException();
throw new
ReynaersException(ErrorResourcesKeys.DefaultMessage);
}
}
}
}
}
提前致谢!
在web.config中尝试此操作或使用Nuget Package重新安装'System.Net.Http'
<configuration>
<system.web>
<compilation>
<assemblies>
<add assembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</assemblies>
</compilation>
</system.web>
</configuration>