Skip to content

HttpClient Exception on GetAsync method #18249

@rsalvadorg

Description

@rsalvadorg

Hi all,

since I updated from RC1 to 1.0 I'm getting an exception using HttpClient.GetAsync method.
Here the exception:

Exception type System.TypeLoadException
Exception message: Could not load type 'System.Collections.Concurrent.ConcurrentDictionary`2' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
Stack trace: at System.Net.Http.Formatting.JsonMediaTypeFormatter..ctor()
at System.Net.Http.Formatting.MediaTypeFormatterCollection.CreateDefaultFormatters()
at System.Net.Http.HttpContentExtensions.get_DefaultMediaTypeFormatterCollection()
at WebApi.Controllers.MyController.Get(String word) in C:\MyController.cs:line 30
at lambda_method(Closure , Object , Object[] )
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__28.MoveNext()

It seems a conflict between .Net4.0 and .Net4.5, my project reference "net461", IIS tries to get the method from mscorlib (net45) and it fails because it's getting actually mscorlib (net40). This method doesnt exists in mscorlib(net40) but in mscorlib(net45).

See: http://stackoverflow.com/questions/38375857/system-typeloadexception-could-not-load-type-system-reflection-runtimereflecti

Here my project.json:

{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.NETCore.Portable.Compatibility": "1.0.1",
"Microsoft.EntityFrameworkCore": "1.0.0",
"Microsoft.EntityFrameworkCore.Relational": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final",
"Microsoft.Extensions.WebEncoders.Core": "1.0.0-rc1-final",
"SapientGuardian.MySql.Data": "6.9.812",
"Microsoft.AspNetCore.Mvc.Formatters.Xml": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"MimeKit": "1.4.1",
"MailKit": "1.4.1",
"System.Xml.XmlDocument": "4.0.1",
"AspNet.Security.OAuth.Validation": "1.0.0-alpha2-final",
"OpenIddict": "1.0.0-*",
"Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0",
"Serilog": "2.1.0",
"Serilog.Sinks.File": "2.1.0",
"Microsoft.AspNet.WebApi.Client": "5.2.3"

},

"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
},

"frameworks": {

"netcoreapp1.0": {
  "imports": [
    "dotnet5.6",
    "net461"
  ]
}

},

"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},

"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},

"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},

"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions