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

Moq dependency uprev is not working as expected #1432

Open
mhnir opened this issue Oct 26, 2023 · 1 comment
Open

Moq dependency uprev is not working as expected #1432

mhnir opened this issue Oct 26, 2023 · 1 comment

Comments

@mhnir
Copy link

mhnir commented Oct 26, 2023

Describe the Bug

Moq has a dependency hierarchy as follows
System.Threading.Tasks.Extensions >= 4.5.4
System.Runtime.CompilerServices.Unsafe >= 4.5.3

In my application I use
System.Runtime.CompilerServices.Unsafe to 4.7.0

so from the Moq definition, everything is fine..

But trying to execute a unit test that uses AsSpan() from System.Memory
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();
        }
    }
}

Expected Behavior

following the dependency definition, Moq should work with System.Runtime.CompilerServices.Unsafe 4.7.0

Exception with Stack Trace

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

Version Info

Target Framework is net4.6.2.
Using SDK csproj

Referenced packages:
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"

Additional Info

@mhnir mhnir added the bug label Oct 26, 2023
@kzu kzu added discussion and removed bug labels Dec 6, 2023
@kzu
Copy link
Contributor

kzu commented Dec 6, 2023

Sounds like you'd need a binding redirect for that assembly

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

2 participants