Tôi có một giải pháp API Web (nhắm mục tiêu .NET 4.6) với một vài dự án .NET Core khá nhẹ trong đó. Tôi đã đóng gói các dự án .NET Core thành một gói NuGet và cài đặt chúng vào dự án Web API.Loại đối số 'System.Net.Http.Headers.MediaTypeHeaderValue' vi phạm ràng buộc của tham số kiểu 'T'
Mọi thứ đều ổn, nhưng khi chạy, tôi nhận được ngoại lệ sau khi ứng dụng đang khởi tạo.
Method System.Net.Http.CloneableExtensions.Clone: type argument 'System.Net.Http.Headers.MediaTypeHeaderValue' violates the constraint of type parameter 'T'.
[VerificationException: Method System.Net.Http.CloneableExtensions.Clone: type argument 'System.Net.Http.Headers.MediaTypeHeaderValue' violates the constraint of type parameter 'T'.]
System.Net.Http.Formatting.MediaTypeConstants.get_ApplicationJsonMediaType() +0
System.Net.Http.Formatting.JsonMediaTypeFormatter..ctor() +64
System.Net.Http.Formatting.MediaTypeFormatterCollection.CreateDefaultFormatters() +41
System.Web.Http.HttpConfiguration.DefaultFormatters(HttpConfiguration config) +26
System.Web.Http.HttpConfiguration..ctor(HttpRouteCollection routes) +214
System.Web.Http.GlobalConfiguration.<CreateConfiguration>b__0() +60
System.Lazy`1.CreateValue() +411
System.Lazy`1.LazyInitValue() +183
System.Lazy`1.get_Value() +75
System.Web.Http.GlobalConfiguration.get_Configuration() +27
Runpath.Platform.Web.DependencyResolution.StructureMapBootStrapper.Initialise() in C:\Code3\Runpath\Markets\Platform\Main - Copy\Runpath.Platform.Web\DependencyResolution\StructureMapBootStrapper.cs:15
Runpath.Platform.Web.WebApiApplication.Application_Start() in C:\Code3\Runpath\Markets\Platform\Main - Copy\Runpath.Platform.Web\Global.asax.cs:30
[HttpException (0x80004005): Method System.Net.Http.CloneableExtensions.Clone: type argument 'System.Net.Http.Headers.MediaTypeHeaderValue' violates the constraint of type parameter 'T'.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +493
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +176
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +364
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +303
[HttpException (0x80004005): Method System.Net.Http.CloneableExtensions.Clone: type argument 'System.Net.Http.Headers.MediaTypeHeaderValue' violates the constraint of type parameter 'T'.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +770
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +195
Tôi đã kiểm tra trong Trình duyệt đối tượng và MediaTypeHeaderValue
thực hiện ICloneable
. Bất cứ ý tưởng những gì có thể gây ra điều này?
Tôi cũng nên nói rằng điều đó là tốt khi tôi thay thế các dự án .NET Core bằng phiên bản .NET 4.6.
Sửa
Theo phản ứng Johnathan, tôi quản lý để làm cho nó làm việc bằng cách cập nhật project.json sử dụng System.Net.Http 4.0.0.0 cho .NET 4.6:
{
"version": "1.0.3-*",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"net46": {
"dependencies": {
"System.Net.Http": "4.0.0"
}
},
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
Đặt thành 4.0.0 hoặc truy cập .Net 4.6 không được giải quyết ở đây .... Tôi đọc rất nhiều trực tuyến nhưng tôi không thể khắc phục ở đây. Bạn có thể giúp tôi được không? –
có bất kỳ tiến bộ nào được thực hiện đối với vấn đề này không? –