Roslyn: MissingMethodException when using ValueTuples defined in netstandard2.0 lib from net461

Created on 29 Oct 2017  路  7Comments  路  Source: dotnet/roslyn

Microsoft Visual Studio 2017 professional, 15.4.1

Steps to reproduce

  1. Create netstandard2.0 library and define method that returns value tuple
  2. Create net461 console application and add reference to that library.
  3. Call method created in 1.

I've created sample project that reproduces issue
https://github.com/Soarc/RoslynCompilerIssue

Expected Behavior:
At least should not compile with CS8137 error, until ValueTuples reference added to net461 project.

Actual Behavior:
Throws MissingMethodException at runtime.

BTW my visual studio throws exception in very weird manner, and actual exception can only be seen in output window.

Area-Compilers Investigating

Most helpful comment

@jcouv I'm seing this issue too, as of today (Windows Update installed stuff overnight). Same .NET version as @Soarc reported above. The announcement you linked provides little info, but links to this document where two workarounds are proposed:

  1. Re-target towards .NET Framework 4.7 or 4.7.1
  2. Remove binding redirects in app.config for the assemblies that are now part of the .NET Framework.

The first is not an option for us at the moment, because the production environment is running 4.6.1 and will be for the foreseeable future.

When I attempt the second, I find no binding redirects in my app.config to start with. I tried removing <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> from the console app project file, but that gave me a couple of build warnings (see below) and then the same MissingMethodException at runtime anyway. I'm given no option to manually add binding redirects to the app.config file.

Any advice?

First build warning:

The referenced component 'System.ValueTuple' could not be found.

Second build warning:

Found conflicts between different versions of the same dependent assembly. Please set the "AutoGenerateBindingRedirects" property to true in the project file. For more information, see http://go.microsoft.com/fwlink/?LinkId=294190.

All 7 comments

Thanks for the detailed repro steps. I think there is indeed a problem, but I don't think it's with the compiler.

The compilation of the client project (targeting net461) receives a reference to C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\System.ValueTuple.dll so it has no reason to complain about ValueTuple missing.

I confirmed that the project and compiler behaviors are by design (this solution should build successfully).
Now, for the runtime error, this should work on a machine with .NET Framework 4.6.1 or 4.7 installed, but there is a known issue when running such programs on a machine with .NET Framework 4.7.1 installed.

Can you confirm that you have .NET Framework 4.7.1 installed?

image
Looks like my .netframework release version is 461308, which is installed with Windows 10 Fall Creators Update and it is .NET Framework 4.7.1.

But i still think this is a bit confusing: if i use ValueTuples in net461 project, it will not compile. But referencing empty .netstandard2.0 library will magically fix it .

.NET Framework 4.7.1 ships with a fix that affects ValueTuple type unification. More details in the announcement.

@jcouv I'm seing this issue too, as of today (Windows Update installed stuff overnight). Same .NET version as @Soarc reported above. The announcement you linked provides little info, but links to this document where two workarounds are proposed:

  1. Re-target towards .NET Framework 4.7 or 4.7.1
  2. Remove binding redirects in app.config for the assemblies that are now part of the .NET Framework.

The first is not an option for us at the moment, because the production environment is running 4.6.1 and will be for the foreseeable future.

When I attempt the second, I find no binding redirects in my app.config to start with. I tried removing <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> from the console app project file, but that gave me a couple of build warnings (see below) and then the same MissingMethodException at runtime anyway. I'm given no option to manually add binding redirects to the app.config file.

Any advice?

First build warning:

The referenced component 'System.ValueTuple' could not be found.

Second build warning:

Found conflicts between different versions of the same dependent assembly. Please set the "AutoGenerateBindingRedirects" property to true in the project file. For more information, see http://go.microsoft.com/fwlink/?LinkId=294190.

Why is this issue closed? One year later I'm still experiencing it calling a method defined in Standard 2.0 from from.NET 4.6.2
What if I can't use .NET 4.7?

CC @terrajobst

Was this page helpful?
0 / 5 - 0 ratings