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

bug(assembly-loading): creating a moq of an interface in a third-party assembly can sometimes throw a FileNotFoundException #299

Closed
dmccaffery opened this issue Nov 17, 2016 · 2 comments

Comments

@dmccaffery
Copy link

I created a simple reproduction in a repo: https://github.com/dmccaffery/moq-repro

execute reproduce.sh or reproduce.ps1 to use an isolated copy of dotnet core 1.1, or simply do:

dotnet restore
dotnet test

in each project under the test folder. One will work, one will not. The only difference between the two is a different version of the same dependency. The one that fails is actually the current production version of the dependency.

@stakx
Copy link
Contributor

stakx commented Jun 4, 2017

I can't get your reproduce.ps1 to run without errors (it fails at the very beginning when it tries to download .NET Core or something), so I just looked at the actual test code and ran below program with the following NuGet package dependencies. It ran successfully.

  • Microsoft.NETCore.App 1.1.2
  • Microsoft.Build.Framework 15.1.1012 (I also tried version 15.1.262-preview5)
  • Moq 4.7.25 (I also tried version 4.6.38-alpha)
using Microsoft.Build.Framework;
using Moq;

class Program
{
    static void Main()
    {
        Mock.Of<IBuildEngine>();
        Mock.Of<IBuildEngine4>();
    }
}

Could you please update your repro code to current versions of .NET Core, Microsoft.Build.Framework, and Moq, and see if the error persists?

@stakx
Copy link
Contributor

stakx commented Jun 21, 2017

Having a look at this again. I believe the error you encountered might be due to the way how Microsoft.Build.Framework version 14.3.0 is made up.

According to the package page on NuGet.org, this package does target .NET Standard 1.3 (since the page lists dependencies for that target). If you download and extract the package, you will see the following contents:

lib\net45\Microsoft.Build.Framework.dll
ref\net45\Microsoft.Build.Framework.dll
ref\netstandard1.3\Microsoft.Build.Framework.dll
Microsoft.Build.Framework.nuspec

Note the absence of a lib\netstandard1.3 folder with the actual assembly. (This would be the relevant one, as net45 should be unusable on the .NET Core platform.) The assembly under ref\netstandard1.3 appears to be a reference assembly; it does not contain any working implementations, and it will not get copied to your program's output directory. Therefore, I would assume that if you do not have version 14.3.0 of Microsoft.Build.Framework installed system-wide, you're going to get the FileNotFoundException.

Contrast this with Microsoft.Build.Framework version 15.1.262-preview5. This package does contain the assembly for the relevant platform:

lib\net46\Microsoft.Build.Framework.dll
lib\net46\Microsoft.Build.Framework.xml
lib\netstandard1.3\Microsoft.Build.Framework.dll
lib\netstandard1.3\Microsoft.Build.Framework.xml
Microsoft.Build.Framework.nuspec

So in conclusion, I would say that this is not an error with Moq, but with the way how that Microsoft NuGet package was made available.

@stakx stakx closed this as completed Jun 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants