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

Unit Tests Fail With Could not load file or assembly errors when using Entity Framework Core 2.0 #266

Closed
bigswede74 opened this issue Sep 7, 2017 · 8 comments

Comments

@bigswede74
Copy link

bigswede74 commented Sep 7, 2017

Description

After upgrading my projects to use Entity Framework Core 2.0 most of my unit tests are failing with various assembly errors. Some of the unit tests use the Entity Framework Core InMemory provider to mock database data.

System.IO.FileLoadException: Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'

System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'

System.IO.FileLoadException: Could not load file or assembly 'System.ValueTuple, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

Steps to reproduce

  1. Create a project that uses Entity Framework Core 2.0 for data access
  2. Create a test project that uses Entity Framework Core 2.0 InMemory provider to mock the data access for testing
  3. Use the memory provider to verify data in a unit test
  4. Unit test fails with below error

System.IO.FileLoadException: Could not load file or assembly 'System.ValueTuple, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

Expected behavior

UnitTests should pass

Actual behavior

Unit tests fail with below error

System.IO.FileLoadException: Could not load file or assembly 'System.ValueTuple, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

Environment

Visual Studio 2017 15.3.3
Project Console Application targeting .net 4.7 framework
Test Project with NuGetPackages

image

@AbhitejJohn
Copy link
Contributor

@bigswede74: Could you help us with a project repro please?

@bigswede74
Copy link
Author

Hello AbhitejJohn,
Attached is a sample project.
HelloWorld.zip

@AbhitejJohn
Copy link
Contributor

Thanks Brad. Will get back on this.

@bigswede74
Copy link
Author

Hello @AbhitejJohn
Any movement on this issue?
Thanks

@AbhitejJohn
Copy link
Contributor

@bigswede74: Looks like a .Net issue reported at dotnet/standard#476 and dotnet/efcore#9046. The workaround with bindingredirects worked for me on the repro you shared.

@bigswede74
Copy link
Author

@AbhitejJohn the problem with this fix is when you add the app.config file to a test project the tests disappear from the text explorer and are no longer discoverable.

see issue
https://developercommunity.visualstudio.com/content/problem/32282/test-explorer-doesnt-populate-with-tests.html

@AbhitejJohn
Copy link
Contributor

@bigswede74: That's odd. That issue seems to be talking about a stale config file. This config file Appconfig.zip works for me. Can you give it a shot please?

@bigswede74
Copy link
Author

@AbhitejJohn the assembly redirect worked.

@pvlakshm pvlakshm closed this as completed Nov 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants