Runtime: Windows Compat Pack: Could not load type System.Runtime.CompilerServices.IAsyncStateMachine

Created on 23 Jul 2018  路  12Comments  路  Source: dotnet/runtime

Original issue https://github.com/dotnet/core/issues/1276

_@xs2bharat commented on Feb 22_

Getting error "Could not load type 'System.Runtime.CompilerServices.IAsyncStateMachine' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'"

Issue Title

Getting error "Could not load type 'System.Runtime.CompilerServices.IAsyncStateMachine' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'"

General

I am using .net core 2.0 framework to design asp.net web api and using Microsoft.Windows.Compatibility pack to port few internally designed library

_@BetsyOstrander commented on Feb 27_
I am getting this too. No error until I added a .net standard lib for accessing Active Directory, which includes the Windows Compatibility pack.

_@CarlosOnline commented on Apr 14_
+1 getting this to with .net core 2.0 referencing .net framework project.

_@CarlosOnline commented on Jun 8_
Any status on a fix?

area-System.Runtime.CompilerServices os-windows tenet-compatibility

Most helpful comment

Closing since I have validated with @micdenny's repro that updating the version of the package fixes the issue. Do feel free to re open if people still hit this with the new package.

All 12 comments

We need isolated repro we can run locally to provide more details. Does anyone have one?
cc @danmosemsft

@karelz I did in my repo CoreFxIssue31276

Just run it, and you will get the exception calling api/values:

image

Issue also arises with .NET Core 2.0, referencing TeamFoundation & VisualStudio assemblies (v16 preview), when invoking "WorkItemTrackingHttpClient witClient = connection.GetClient();"
Results in exactly the same exception. Having compatibility package referenced...

I ran into this problem after the guidance in https://github.com/dotnet/standard/issues/506 told me to use .NET Core w/ Microsoft.Windows.Compatibility package instead of .NET Standard, to get past a differennt FileNotFoundException loading DLLs!

@karelz Why is this still tagged with needs more info? https://github.com/micdenny/CoreFxIssue31276 seems to be what you need?

The area owners didn't get to the issue yet, that's why it was not updated. Removing the label 'needs more info' now.
ping @ianhays @Anipik cc @joperezr

I see what is going on here. The problem is that the compatibility package had a bug when targeting netcoreapp2.0 instead of netcoreapp2.1, but that problem has been fixed on the new compatibility package that we just released yesterday. @jzabroski and @micdenny do you guys mind updating your ASPNETCore project to use the 2.0.1 version of the Microsoft.Windows.Compatibility package? That should fix your issue.

cc: @safern since he fixed the issue with the compatibility package.

Closing since I have validated with @micdenny's repro that updating the version of the package fixes the issue. Do feel free to re open if people still hit this with the new package.

Just for reference and future possible hits of this issue:

If you have a full framework library that uses one of this types, i.e System.ValueTuple and then reference this from a netcoreapp2.0 app that uses the Microsoft.Compatibility.Windows package, then we will get a runtime exception because the typeforward doesn鈥檛 exist:

Unhandled Exception: System.TypeLoadException: Could not load type 'System.ValueTuple`1' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
   at netfxApp.TestClass.UseTuple()
   at compatApp.Program.Main(String[] args) in E:\repos\compatPackTest\compatApp\Program.cs:line 10

The affected types are:

System.ArgIterator
System.ValueTuple
System.ValueTuple<T1>
System.ValueTuple<T1, T2>
System.ValueTuple<T1, T2, T3>
System.ValueTuple<T1, T2, T3, T4>
System.ValueTuple<T1, T2, T3, T4, T5>
System.ValueTuple<T1, T2, T3, T4, T5, T6>
System.ValueTuple<T1, T2, T3, T4, T5, T6, T7>
System.ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>
System.Diagnostics.Contracts.Internal.ContractHelper
System.Reflection.Emit.EventToken
System.Reflection.Emit.FieldToken
System.Reflection.Emit.MethodToken
System.Reflection.Emit.ParameterToken
System.Reflection.Emit.PEFileKinds
System.Reflection.Emit.PropertyToken
System.Reflection.Emit.SignatureToken
System.Reflection.Emit.StringToken
System.Reflection.Emit.TypeToken
System.Runtime.CompilerServices.IAsyncStateMachine
System.Runtime.InteropServices.AssemblyRegistrationFlags
System.Runtime.InteropServices.ExporterEventKind
System.Runtime.InteropServices.IDispatchImplAttribute
System.Runtime.InteropServices.IDispatchImplType
System.Runtime.InteropServices.InAttribute
System.Runtime.InteropServices.RegistrationClassContext
System.Runtime.InteropServices.RegistrationConnectionType
System.Runtime.InteropServices.SetWin32ContextInIDispatchAttribute
System.Collections.Generic.TreeSet<T>
System.ComponentModel.InvalidEnumArgumentException
System.IO.Compression.ZLibException
System.Net.CookieVariant
System.Net.PathList

I am facing the same issue in .Net Core 3.0. And the Microsoft.Windows,Compatibitlity also didn't solved the issue. Please update the solution for .Net Core 3.0 or 3.1

@Santhosh0505 which version of the Compatibility package are you using?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

btecu picture btecu  路  3Comments

iCodeWebApps picture iCodeWebApps  路  3Comments

Timovzl picture Timovzl  路  3Comments

sahithreddyk picture sahithreddyk  路  3Comments

matty-hall picture matty-hall  路  3Comments