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
Run the functional tests:
....\packages\xunit.runner.console.2.2.0\tools\xunit.console.exe bin\Debug\EntityFramework.SqlServerCompact.Legacy.FunctionalTests.dll
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
You may want to switch from using packages.config
to PackageReference. In my experience things generally work better with .NET Standard that way.
How do I do that with an existing project?
Found Nate's guide: http://www.natemcmaster.com/blog/2017/03/09/vs2015-to-vs2017-upgrade/
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>
Great, let me try that!
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?
Hmm... You shouldn't need it, but does adding the following help?
<PropertyGroup>
<RuntimeIdentifier>win7-x86</RuntimeIdentifier>
</PropertyGroup>
Nope!
Did you close and re-open the solution? NuGet (in VS) may be in a bad state.
Yes, no dice...
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.
Tried that - no luck at all, back to square one.
Add-BindingRedirect did not add any app.config at all.
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>
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.
Yes, tested the binding redirect, works.
@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.
@ajcvickers Yes, I am able to run the tests with the binding redirect added manually, and the xunit console runner. As metioned here: https://github.com/aspnet/EntityFramework/issues/9053#issuecomment-312905678 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....
@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?
Yeah, full framework support got a bit more tricky with preview2. I was able to get going with
NETStandard.Library.NETFramework
<ImplicitlyExpandDesignTimeFacades>false</ImplicitlyExpandDesignTimeFacades>
@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....)
@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?
Yes!
Okay, thanks. Your feedback is greatly appreciated and will be communicated up.
Thanks for that, I fully understand that we are all in a state of transition to .NET Standard, and things are in flux
@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
Closing this as no-repro. Please re-open if it still repros with latest VS and msbuild-based NuGet (PackageReference).
@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
Yes 3 and 4 shouldn't be needed with the new VS tools.
As for the binding redirects those will still be needed but you should be able to get them auto-generated for your test projects by ensuring the following properties are set in your project:
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
Please try that out and see if it fixes your issue.
@weshaggard Thanks for the info, all interesting. but cannot see how this improves the experience for devs creating a classic .exe project ?? Is the AutGenerate.... setting always true??
Just so that @weshaggard doesn't have to post it twice, here is an excerpt from his answer at
https://github.com/ErikEJ/EntityFramework.SqlServerCompact/issues/463#issuecomment-314212330:
Yes for any new .NET Framework .exe projects AutoGenerateBindingRedirects is set to true so unless they explicitly set it to false or are pulling forward an old project that didn't have it set then they will get the redirects automatically generated.
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/
@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.
@thomaswolff
Ignore my last message....this worked for me
"BindingRedirects": "[ { \"ShortName\": \"System.ValueTuple\", \"RedirectToVersion\": \"4.0.2.0\", \"PublicKeyToken\": \"cc7b13ffcd2ddd51\" } ]"
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?
@philip-reed That looks like the wrong version number! Make sure to use VS 2017 15.3 or later
@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:
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>
@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.
For anyone having issues with this, here is a great workaround for Azure Functions
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.
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"
@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.
@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
`
it's EntityFramework core project that seems to be throwing this.
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...
@FransBouma It works fine for me in a classic unit test csproj with the binding redirect:
https://github.com/ErikEJ/EntityFramework.SqlServerCompact/blob/master/test/EntityFramework.SqlServerCompact.FunctionalTests/app.config#L15
@ErikEJ hmm. You use nunit? As I couldn't get it to work whatever I tried. A new csproj format with these: https://github.com/dotnet/sdk/issues/1070 worked.
@fransbouma as you can see from the tests i use xunit and execute with testdriven.net
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?
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.
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
@jessetabak - Please file a new issue, with the description & repro steps of the issue you are seeing.
@smitpatel I resolved the issue, apparently I also needed to install the Microsoft.EntityFrameworkCore.Sqlite nuget package in the startup project
Most helpful comment
I was able to get it working with a binding redirect.