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

[2.0 provider] Unable to run EF Core specifications tests in .NET 4.6.1 class library #9046

Closed
ErikEJ opened this issue Jul 2, 2017 · 52 comments

Comments

@ErikEJ
Copy link
Contributor

ErikEJ commented Jul 2, 2017

Trying to run functional tests with preview2 from a .NET 4.6.1 class library (SQLCE functional tests)

Exception message:
     System.IO.FileLoadException : Could not load file or assembly 'System.ValueTuple, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
      Stack Trace:
           at Microsoft.EntityFrameworkCore.Metadata.Internal.TableMapping.GetTableMappings(IModel model)

This is blocking me from updating the SQLCE EF Core provider to EF Core 2.0

Steps to reproduce

Run the functional tests:
....\packages\xunit.runner.console.2.2.0\tools\xunit.console.exe bin\Debug\EntityFramework.SqlServerCompact.Legacy.FunctionalTests.dll

Further technical details

EF Core version: 2.0 preview2 (from Nuget.org feed)
Database Provider: SQL CE
Operating system: Win 10 1703
IDE: VS 2017 15.3 preview 3

Branch: https://github.com/ErikEJ/EntityFramework.SqlServerCompact/tree/prev2-prep

@ErikEJ ErikEJ changed the title [2.0 provider] Unable to run test in .NET 4.6.1 class library [2.0 provider] Unable to run EF Core specifications tests in .NET 4.6.1 class library Jul 3, 2017
@bricelam
Copy link
Contributor

bricelam commented Jul 3, 2017

You may want to switch from using packages.config to PackageReference. In my experience things generally work better with .NET Standard that way.

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Jul 3, 2017

How do I do that with an existing project?

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Jul 3, 2017

@bricelam
Copy link
Contributor

bricelam commented Jul 3, 2017

That's more than necessary. You can use "old" csproj just with PackageReference items instead of Reference items.

For example, instead of this...

<ItemGroup>
  <Reference Include="Microsoft.EntityFrameworkCore.Relational.Specification.Tests, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
    <HintPath>..\..\packages\Microsoft.EntityFrameworkCore.Relational.Specification.Tests.2.0.0-preview2-25099\lib\net46\Microsoft.EntityFrameworkCore.Relational.Specification.Tests.dll</HintPath>
  </Reference>
  <!-- (and it's dozens of dependencies) -->
</ItemGroup>

...you can delete the packages.config file and change the *.csproj to this:

<ItemGroup>
  <PackageReference Include="Microsoft.EntityFrameworkCore.Relational.Specification.Tests">
    <Version>2.0.0-preview2-25099</Version>
  </PackageReference>
</ItemGroup>

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Jul 3, 2017

Great, let me try that!

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Jul 3, 2017

Getting this after changing to PackageReference only:

1>C:\Program Files (x86)\Microsoft Visual Studio\Preview\Community\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.targets(178,5): error : Your project.json doesn't have a runtimes section. You should add '"runtimes": { "win": { } }' to your project.json and then re-run NuGet restore.

Should I install the 2.0 SDK?

@bricelam
Copy link
Contributor

bricelam commented Jul 3, 2017

Hmm... You shouldn't need it, but does adding the following help?

<PropertyGroup>
  <RuntimeIdentifier>win7-x86</RuntimeIdentifier>
</PropertyGroup>

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Jul 3, 2017

Nope!

@bricelam
Copy link
Contributor

bricelam commented Jul 3, 2017

Did you close and re-open the solution? NuGet (in VS) may be in a bad state.

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Jul 3, 2017

Yes, no dice...

@bricelam
Copy link
Contributor

bricelam commented Jul 3, 2017

Well, scratch that idea then. Keep the packages.config files.

Try deleting the App.config files in the tests and running Add-BindingRedirect from PMC.

Also ensure you're targeting .NET Framework 4.6.1 everywhere.

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Jul 3, 2017

Tried that - no luck at all, back to square one.

Add-BindingRedirect did not add any app.config at all.

@BradBarnich
Copy link

BradBarnich commented Jul 4, 2017

I was able to get it working with a binding redirect.

<dependentAssembly>
        <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Jul 4, 2017

Thanks very much, Brad! I will try it out - but not really a sustainable, long term solution, given that NuGet does not even add this binding redirect.

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Jul 4, 2017

Yes, tested the binding redirect, works.

@ajcvickers
Copy link
Contributor

@ErikEJ Are you unblocked now?

If there are issues doing things that should work but don't seem to, then it would be great if you could file issues against NuGet.

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Jul 5, 2017

@ajcvickers Yes, I am able to run the tests with the binding redirect added manually, and the xunit console runner. As metioned here: #9053 (comment) I do not have any hopes of ever being able to ship a 2.0-preview2-final provider, sadly. Hope the issue gets fixed, and that there will be proper support for .NET 4.6.1 based providers by RTM....

@ajcvickers
Copy link
Contributor

@ErikEJ Very sorry to hear that Erik, but it's not completely clear to me what it is that is blocking you. Is it that the development experience for external contributors is just too hard/inefficient, or there still something specific blocking you from releasing?

@BradBarnich
Copy link

Yeah, full framework support got a bit more tricky with preview2. I was able to get going with

  1. upping to .net 4.6.1 (was 4.6)
  2. that binding redirect
  3. referencing NETStandard.Library.NETFramework
  4. <ImplicitlyExpandDesignTimeFacades>false</ImplicitlyExpandDesignTimeFacades>

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Jul 5, 2017

@ajcvickers
1: Requiring Visual Studio 2017 15.3 preview 3 - this is acceptables/understandable an due to .NET Standard 2.0)
2: The System.ValueTuple binding redirect, which you must add manually - kind of showstopper (yes, I know I can do Nuget app.config tricks, but....)

@ajcvickers
Copy link
Contributor

ajcvickers commented Jul 5, 2017

@ErikEJ So your're saying you can't release it because then your customers would need to manually add the binding direct, and that's not acceptable?

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Jul 5, 2017

Yes!

@ajcvickers
Copy link
Contributor

Okay, thanks. Your feedback is greatly appreciated and will be communicated up.

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Jul 6, 2017

Thanks for that, I fully understand that we are all in a state of transition to .NET Standard, and things are in flux

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Jul 6, 2017

@BradBarnich I is my understanding that 3 and 4 on your list are fixed by using VS 2017 15.3 preview 3, and yes, .NET 4.6.1 is now the minimum requirement for EF Core

@thomaswolff
Copy link

Just wanted to leave a comment here in case someone developing an Azure Function App is having problems with setting up a binding redirect for System.ValueTuple. Read this blog post for a solution: https://codopia.wordpress.com/2017/07/21/how-to-fix-the-assembly-binding-redirect-problem-in-azure-functions/

@jculverwell
Copy link

@thomaswolff

With regards to the article https://codopia.wordpress.com/2017/07/21/how-to-fix-the-assembly-binding-redirect-problem-in-azure-functions/
Can you share what you config setting you were using to get System.ValueTuple working. I'm using

"BindingRedirects": "[ { \"ShortName\": \"System.ValueTuple\", \"RedirectToVersion\": \"4.4.0\", \"PublicKeyToken\": \"cc7b13ffcd2ddd51\" } ]"

and it is saying it can't find the assembly.

@jculverwell
Copy link

@thomaswolff

Ignore my last message....this worked for me

"BindingRedirects": "[ { \"ShortName\": \"System.ValueTuple\", \"RedirectToVersion\": \"4.0.2.0\", \"PublicKeyToken\": \"cc7b13ffcd2ddd51\" } ]"

@philip-reed
Copy link

Hi,

I have been trying to follow each of the discussions about the System.ValueTuple issue but im stuggling to understand. I get the same error @ErikEJ mentions at the start of this when i try to run a unit test that uses UseInMemoryDatabase for EF Core. Each of my projects target Framework 4.7.

I have tried adding the following to my unit test project, but it doesnt appear to have any effect:
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>

I have also tried putting the following in app.config of my test project:

<dependentAssembly> <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" /> <bindingRedirect oldVersion="0.0.0.0-4.6.0.0" newVersion="4.6" /> </dependentAssembly>

Have I put these in the wrong place or have i missed something else?

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Aug 25, 2017

@philip-reed That looks like the wrong version number! Make sure to use VS 2017 15.3 or later

@philip-reed
Copy link

@ErikEJ
Hi Erik, I am using VS 2017 15.3.2.
Am I correct in thinking the binding redirect should be in the app.config of the unit test project?

I had tried various version numbers for System.ValueTuple when trying this, and 4.6 was just the latest attempt. If i look in the bin folder of my web project (the one under test) i have the following for System.ValueTuple, and this is where i got the version number from:

capture

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Aug 25, 2017

Product version != Assembly version
This is what I have in my 4.6.1 test project (why not stay at 4.6.1?)

<dependentAssembly> <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" /> <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> </dependentAssembly>

@philip-reed
Copy link

@ErikEJ I swear i tried that, but it is working now, thank you.

I started at version 4.6.1, and tried 4.7 to see if it resolved this issue, seems happy now either way.

Thanks again.

@VividDigital
Copy link

For anyone having issues with this, here is a great workaround for Azure Functions

@codearoo
Copy link

codearoo commented Sep 1, 2017

We have this issue new, with .Net 2.0 Core. Using VS 2017 15.3.3.
Installed ValueTuple even with Nuget for the project wanting, but it's still bombing with the
System.ValueTuple, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.

Have not done the binding redirect.. kind of perplexed that this issue is still here to begin with.

@codearoo
Copy link

codearoo commented Sep 1, 2017

Interesting... I searched for the cc7b13ffcd2ddd51 key, and it's finding it in app.config files as a different lib:
assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"

@smitpatel
Copy link
Contributor

@codearoo - Can you run dotnet --info to find out which version of dotnet you are using? there was breaking change from 2.0 preview to RTM in dotnet around DiagnosticSource.

@codearoo
Copy link

codearoo commented Sep 1, 2017

@smitpatel
`
.NET Command Line Tools (2.0.0)

Product Information:
Version: 2.0.0
Commit SHA-1 hash: cdcd1928c9

Runtime Environment:
OS Name: Windows
OS Version: 10.0.15063
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.0.0\

Microsoft .NET Core Shared Framework Host

Version : 2.0.0
Build : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d
`

@codearoo
Copy link

codearoo commented Sep 1, 2017

it's EntityFramework core project that seems to be throwing this.

@FransBouma
Copy link

I ran into the same issue.

In vs2017 15.3.2, I have a classic csproj using .NET 4.6.2 with my unit tests for EF Core 2.0. When I create a DbContext derived type instance, I get:

System.IO.FileLoadException : Could not load file or assembly 'System.ValueTuple, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
  Exception doesn't have a stacktrace

When I use the binding redirect I don't get the exception anymore but the test which caused this also doesn't run anymore, so the bindingredirect isn't really usable.

Will try with a csproj in the new format to see whether that works...

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Sep 4, 2017

@FransBouma
Copy link

@ErikEJ hmm. You use nunit? As I couldn't get it to work whatever I tried. A new csproj format with these: dotnet/sdk#1070 worked.

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Sep 4, 2017

@FransBouma as you can see from the tests i use xunit and execute with testdriven.net

@codearoo
Copy link

codearoo commented Sep 8, 2017

Just to update, it does work when I manually add this to app.config (have to create the file for projects that don't need one)
<dependentAssembly> <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" /> <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> </dependentAssembly>

But it's really kind of messed up.. For every project that uses the EntityFramework Core 2.0 stuff I have to add this secret sauce.. Microsoft isn't fixing this?

@evil-shrike
Copy link

Hi!

I'm sorry resurrecting this old closed issue but I'm having one of the mentioned error in my project:

Microsoft.NuGet.targets(178,5): error : Your project.json doesn't have a runtimes section. You should add '"runtimes": { "win": { } }' to your project.json and then re-run NuGet restore.

and really have no idea where to look after reading everything google found. All details are in the SO question. But briefly what was the reason of "Your project.json doesn't have a runtimes section" error? All subsequent suggestions on bindingRedirects puzzle me as I thought binding redirects happens at runtime but the error happens at build time.

@jessetabak
Copy link

I'm still having still problem, above solutions did not work, any suggestions?

EF Core version: 2.1.0-preview2-final
Database Provider: SQLite
Operating system: Win 10 1607
IDE: VS 2017 15.5.7

@smitpatel
Copy link
Contributor

@jessetabak - Please file a new issue, with the description & repro steps of the issue you are seeing.

@jessetabak
Copy link

@smitpatel I resolved the issue, apparently I also needed to install the Microsoft.EntityFrameworkCore.Sqlite nuget package in the startup project

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
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