microsoft / testfx

MSTest framework and adapter
MIT License
732 stars 254 forks source link

MSTest resolved wrong assembly when using struct from different version of the same Nuget package #3864

Closed tvlEIVA closed 2 weeks ago

tvlEIVA commented 2 weeks ago

Describe the bug

using a struct Microsoft.EntityFrameworkCore.DbContextId from Microsoft.EntityFrameworkCore (3.1.32 together with 3.1.14 ) This is the exception when running a test using MSTest framework System.IO.FileLoadException: Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=3.1.14.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Steps To Reproduce

Check the attached .zip file containing a minimal example of how to reproduce the issue. The example is using Microsoft.EntityFrameworkCore for a general use case. ProjectWithLowerVersion is using version 3.1.14 of Microsoft.EntityFrameworkCore

ProjectWithHigherVersion is using version 3.1.32 of Microsoft.EntityFrameworkCore

Both test projects UnitTestMSTest (using the latest MSTest framework) and UnitTestNUnit (using NUnit as test framework) doing the same test

Expected behavior

The test using MSTestProject and NUnit succeed

Actual behavior

The test using MSTestProject failed but the one using NUnit succeed

Test project

TestNugetsConflict.zip

Evangelink commented 2 weeks ago

Hi @tvlEIVA,

Thanks for the repro project. I confirm that I can reproduce the issue locally.

After a quick investigation, I see that the issue is not present using MSTest runner (see https://devblogs.microsoft.com/dotnet/introducing-ms-test-runner/). Are you able to migrate to our new runner? If not, could you please let us know what is preventing you to migrate?

tvlEIVA commented 2 weeks ago

Hi Amaury, I've tried using MSTest runner in my project and I confirm that there is no longer issue with my tests. Thanks a lot for your help!