Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MissingMethodException when using ValueTuples defined in netstandard2.0 lib from net461 #22903

Closed
Soarc opened this issue Oct 29, 2017 · 7 comments

Comments

@Soarc
Copy link

Soarc commented Oct 29, 2017

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.

@jcouv jcouv added this to the 15.later milestone Oct 29, 2017
@jcouv jcouv self-assigned this Oct 29, 2017
@jcouv
Copy link
Member

jcouv commented Oct 30, 2017

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.

@jcouv
Copy link
Member

jcouv commented Oct 30, 2017

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?

@Soarc
Copy link
Author

Soarc commented Oct 31, 2017

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 .

@jcouv jcouv modified the milestones: 15.6, 15.7 Jan 4, 2018
@jaredpar jaredpar closed this as completed Jan 8, 2018
@jcouv
Copy link
Member

jcouv commented Jan 9, 2018

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

@tomasaschan
Copy link

@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.

@almarax
Copy link

almarax commented Oct 23, 2018

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?

@jaredpar
Copy link
Member

CC @terrajobst

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants