Visual Studio 2022 - Unexpected 'Could not load type' scenarios When Running Unit Tests with Moq and NUnit
After trying multiple solutions online, I still can't figure this out... I'm converting an old project and I've been banging my head against this for hours. I'm working with a frustrating scenario in Visual Studio 2022 when I try to run my unit tests using NUnit along with Moq. My setup includes .NET 6.0, and I have a service that I am attempting to mock. Despite the tests compiling successfully, when I execute them, I receive the following behavior message: `System.TypeLoadException: Could not load type 'MyProject.Services.IMyService' from assembly 'MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.` I have double-checked the namespace and the project references. Hereβs a snippet of the code where I configure the mock: ```csharp public class MyServiceTests { private readonly Mock<IMyService> _myServiceMock; public MyServiceTests() { _myServiceMock = new Mock<IMyService>(); } [Test] public void TestMyServiceMethod() { // Arrange _myServiceMock.Setup(s => s.SomeMethod()).Returns(true); // Act var result = _myServiceMock.Object.SomeMethod(); // Assert Assert.IsTrue(result); } } ``` I've also made sure that the `IMyService` interface is public and is located in the same assembly as the tests. I tried cleaning and rebuilding the solution, and I even reinstalled the NUnit and Moq NuGet packages. I verified that the target framework for both the main project and the test project is set to .NET 6.0. Despite these attempts, the scenario continues. Is there something I'm missing? How can I resolve this TypeLoadException when running unit tests? How would you solve this? This is part of a larger service I'm building. What's the correct way to implement this? For context: I'm using C# on Debian.