在 ASP.NET MVC 應(yīng)用程序 (.NET 4.7) 中,我在HttpResponseMessage. 此方法是在 .NET Standard 2.0 項(xiàng)目中創(chuàng)建的。在調(diào)試和使用 IIS Express 時(shí),它工作得很好。但是當(dāng)發(fā)布到服務(wù)器時(shí),它返回“找不到方法”錯(cuò)誤。在服務(wù)器 (Windows Server 2008) 上安裝了所有需要的框架。當(dāng)我在調(diào)用擴(kuò)展方法的方法中使用 try/catch 時(shí),錯(cuò)誤變得很清楚。在開(kāi)發(fā)過(guò)程中,我希望它能在服務(wù)器上運(yùn)行。我是否缺少任何其他 .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); } } } } }提前致謝!
發(fā)布 ASP.NET MVC 應(yīng)用程序時(shí)找不到擴(kuò)展方法
翻過(guò)高山走不出你
2022-12-24 14:40:48