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

Linux compilation fails using Mono on Moq 4.8+ #864

Closed
bdb-stack opened this issue Jul 24, 2019 · 6 comments
Closed

Linux compilation fails using Mono on Moq 4.8+ #864

bdb-stack opened this issue Jul 24, 2019 · 6 comments

Comments

@bdb-stack
Copy link

Hi there, I'm not sure if this would be a Moq or a Mono issue, but thought I'd post here just in case. Compilation is failing on Linux while trying to reference Moq.dll with Mono. The issue first arises in 4.8.0-rc1 and is still present in 4.12.0.

Linux Version: Red Hat 6.5 (Santiago)
Mono Versions Tested: 5.14 and 6.0.0
Assembly Versions:

  • Castle.Core.dll 4.4.0
  • System.Runtime.CompilerServices.Unsafe.dll 4.5.2
  • System.Threading.Tasks.Extensions.dll 4.5.3

Compiling a C# HelloWorld program with an added 'using Moq;' statement fails with the following error message:
-> mcs Program.cs -r:Moq.dll
-> error CS0009: Metadata file '/project/Moq.dll' does not contain valid metadata

In fact, the program doesn't need to have the 'using Moq;' statement for compilation to fail, the '-r:Moq.dll' in the mcs command is enough to generate this error message. I have also tried referencing all the Moq dependencies but I get the same error message. Any help would be greatly appreciated.

@stakx
Copy link
Contributor

stakx commented Jul 24, 2019

What is the targeted framework?

@bdb-stack
Copy link
Author

Our project is targeting .NET 4.6.1.

@stakx
Copy link
Contributor

stakx commented Jul 24, 2019

I am fairly confident that this will turn out to be either a Mono tooling issue or, even more likely, a problem with your project configuration/setup.

I'll still take a look at it, but in order to do so, please post or link to a minimal code repo that I can build using Mono to repro the error. Or, provide precise and complete repro instructions. (Above, you first suggested that you call the compiler directly; your second post hinted at the existence of a project, i.e. MSBuild. A repo would clear things up a lot, otherwise I just have to guess.)

Without a repro, I'll close this issue in a few days' time.

@bdb-stack
Copy link
Author

Thanks for the response. Here's a link to a minimal code repo:
https://github.com/debiebrett/Moq-Compile-Error

I can reproduce the error with the command "mcs test.cs -r:Moq.dll"

Let me know if this is enough for you to reproduce.

@stakx
Copy link
Contributor

stakx commented Jul 24, 2019

OK, I could reproduce this using the mono:5.14 Docker image. This is definitely not a problem with the provided Moq.dll per se (which appears to be the .NET Framework DLL for Moq 4.8.0). This instead appears to be a problem with the way you invoke the C# compiler.

I tried two things, both of which made that compilation error you reported go away:

  1. I added the following Repro.csproj file and then compiled it using msbuild /r Repro.csproj:

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <TargetFramework>net45</TargetFramework>
      </PropertyGroup>
      <ItemGroup>
        <Reference Include="Moq.dll"/>
      </ItemGroup>
    </Project>
  2. Alternatively, I used csc program.cs /target:library /r:Moq.dll to compile the program, instead of mcs.

Note that newer versions of Mono now ship with the Roslyn C# compiler (i.e. csc from the dotnet/roslyn repo) as well as the cross-platform msbuild (that might be the same one you'd get when invoking .NET Core's dotnet msbuild). I suspect you might be better off using these newer tools instead of the (legacy?) Mono tools like mcs and xbuild.

I'm closing this issue, since the two suggestions above both result in successful compilation. Please do let us know whether this helped you.

@stakx stakx closed this as completed Jul 24, 2019
@bdb-stack
Copy link
Author

Great, thanks for the help. We'll be looking into switching our project over to use the Roslyn C# compiler.

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