Search code examples
c#mockingmoqlibrariescode-testing

Adding Moq to a test project causes a pseudo-random could not load library issue


One of my colleagues has added a test project to the master branch that includes a Moq reference. Its not even busing used at the time, simply having the reference causes the build and website to fail:

enter image description here

I called it a pseudo random issue in the title because I've also have that happen with the same error but:

System.Buffers

Once it's set, it's pretty consistent, so no clue what the trigger is to throw on a different library.

If I remove the website from the solution, the code builds correctly, but the website still shows the issue in the browser (as you would expect, I guess).

If I remove Moq and all of the traces adding that exist for the dependency (and it's children), the build is working again


Another reason why I call it a pseudo random issue is that I suspect that what I see is a symptom of the issue. Not the issue itself. It just so happens to trigger on System.Runtime.CompilerServices.Unsafe or whatever.


Any ideas / tips on what I can do to:
  1. Find the actual issue
  2. Come up with a solution?

PS: In case it could be important, we are on a deterministic build, not the default.


Solution

  • With more time passed it's clear that its an architectural fault. A thorough restructuring is needed to fix that so sadly no easy answer can be provided for this.