Moq has a dependency hierarchy as follows
Moq 4.18.4
System.Threading.Tasks.Extensions >= 4.5.4
System.Runtime.CompilerServices.Unsafe >= 4.5.3
In my application I must use
System.Runtime.CompilerServices.Unsafe to 4.7.0
so from the Moq
definition, everything is fine..
Whe I'm trying to execute a unit test that uses AsSpan()
from System.Memory
,
it throws an exception (during Release and Debug mode).
System.IO.FileLoadException
HResult=0x80131040
Message=Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe,
Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its
dependencies. The located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)
Source=System.Memory
StackTrace:
at System.MemoryExtensions.AsSpan(String text)
at UnitTestProject1.UnitTest1.TestMethod1() in
C:\source\repos\ConsoleApp9\UnitTestProject1\UnitTest1.cs:line 13
Steps to reproduce:
Create a unit test project with the following nugets:
- Moq Version="4.20.69"
- MSTest.TestAdapter Version="2.2.8"
- MSTest.TestFramework Version="2.2.8"
- System.Memory Version="4.5.4"
- System.Runtime.CompilerServices.Unsafe Version="4.7.0"
Try to run (release or debug) and you'll get an exception on the b = a.AsSpan()
line.
namespace UnitTestProject1
{
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
string a = "asdfdsa";
var b = a.AsSpan();
}
}
}
Is it a bug? or am I missing something?