Ho una soluzione API Web (con targeting .NET 4.6) con un paio di progetti .NET Core abbastanza leggeri. Ho impacchettato i progetti .NET Core come pacchetto NuGet e li ho installati nel progetto Web API.L'argomento Type 'System.Net.Http.Headers.MediaTypeHeaderValue' viola il vincolo del parametro type 'T'
Tutto si comporta bene, ma durante l'esecuzione, ottengo la seguente eccezione quando l'applicazione è in fase di inizializzazione.
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
Ho controllato in Object Browser e MediaTypeHeaderValue
fa implementare ICloneable
. Qualche idea su cosa potrebbe causare questo?
Devo anche dire che va bene quando sostituisco i progetti .NET Core con versioni .NET 4.6.
Modifica
Come per la risposta di Johnathan, sono riuscito a farlo funzionare aggiornando project.json utilizzare System.Net.Http 4.0.0.0 for .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"
}
}
}
Impostazione a 4.0.0 o andare a .Net 4.6 non risolto qui .... Ho letto un sacco online, ma non può risolvere il problema qui. Mi potete aiutare? –
sono stati fatti progressi su questo problema? –