Skip to content

Instantly share code, notes, and snippets.

@dtchepak
Created June 28, 2012 23:22
Show Gist options
  • Save dtchepak/3014681 to your computer and use it in GitHub Desktop.
Save dtchepak/3014681 to your computer and use it in GitHub Desktop.
[SOLVED] NSub error on mono when built with vs2012 tools
-- Sorted, see https://gist.github.com/3014681#gistcomment-360816
~/dev/git/mononsub % gmcs -sdk:4 Program.cs -reference:NSubstitute.dll
Missing method .ctor in assembly /Users/dave/dev/git/mononsub/NSubstitute.dll, type System.Runtime.Versioning.TargetFrameworkAttribute
Can't find custom attr constructor image: /Users/dave/dev/git/mononsub/NSubstitute.dll mtoken: 0x0a00085a
~/dev/git/mononsub % dmcs Program.cs -reference:newsub40/NSubstitute.dll
Missing method .ctor in assembly /Users/dtchepak/dev/git/mononsub/newsub40/NSubstitute.dll, type System.Runtime.CompilerServices.ExtensionAttribute
Can't find custom attr constructor image: /Users/dtchepak/dev/git/mononsub/newsub40/NSubstitute.dll mtoken: 0x0a000850
-- No error when using NSubstitute.dll built via vs2010 tools.
-- Only happens with vs2012 tools, and in the DLL targeting net40 (the net35 one works ok).
-- Current nuget/github version is built w/vs2012 (http://nsubstitute.github.com/).
-- http://bit.ly/nsubbuilds latest is vs2010 tools (login as guest).
-- Program.cs
using System;
using NSubstitute;
public class Program {
public static void Main() {
var foo = Substitute.For<IFoo>();
foo.Foo = "hello";
Console.WriteLine(foo.Foo);
}
public interface IFoo { string Foo { get; set; }}
}
@dtchepak
Copy link
Author

@shiftkey compared manifests of the net40 DLLs on nuget and the one on the build server, found the following difference:

[mscorlib]System.Runtime.CompilerServices.ExtensionAttribute (from vs2012 tools build)
versus
[System.Core]System.Runtime.CompilerServices.ExtensionAttribute (from build server build)

@dtchepak
Copy link
Author

Mono version (on OS X):

~/dev/git/mononsub % mono --version
Mono JIT compiler version 2.10.9 (tarball Mon May 7 20:25:51 EDT 2012)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
TLS: normal
SIGSEGV: normal
Notification: kqueue
Architecture: x86
Disabled: none
Misc: debugger softdebug
LLVM: yes(2.9svn-mono)
GC: Included Boehm (with typed GC)
~/dev/git/mononsub % dmcs --version
Mono C# compiler version 2.10.9.0

@dsplaisted
Copy link

This is an issue with how the ilmerge is being done. See this blog post for how to fix it: http://www.mattwrock.com/post/2012/02/29/What-you-should-know-about-running-ILMerge-on-Net-45-Beta-assemblies-targeting-Net-40.aspx

@dtchepak
Copy link
Author

@dsplaisted Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment