无法从程序集中加载类型System.Runtime.Versioning.TargetFrameworkAttribute

8

我正在尝试使用mono编译一个使用Newtonsoft.Json.dll库的程序。

编译命令:

gmcs Program.cs etcetera.cs -r:Newtonsoft.Json.dll -r:Argotic.Core.dll

结果:

Missing method .ctor in assembly Newtonsoft.Json.dll, type System.Runtime.Versioning.TargetFrameworkAttribute
Can't find custom attr constructor image: Newtonsoft.Json.dll mtoken: 0x0a000053

然后在尝试运行程序(mono Program.exe)时,会抛出以下错误:

Unhandled Exception: System.TypeLoadException: Could not load type 'System.Runtime.Versioning.TargetFrameworkAttribute' from assembly 'Newtonsoft.Json'.

  at my_program.CJSONStuff.serialize (System.Collections.Generic.Dictionary`2 obj) [0x00000] in <filename unknown>:0 

  at my_program.TheObjDB.getAllSerialized () [0x00000] in <filename unknown>:0 

  at my_program.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'System.Runtime.Versioning.TargetFrameworkAttribute' from assembly 'Newtonsoft.Json'.

  at my_program.CJSONStuff.serialize (System.Collections.Generic.Dictionary`2 obj) [0x00000] in <filename unknown>:0 

  at my_program.TheObjDB.getAllSerialized () [0x00000] in <filename unknown>:0 

  at my_program.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 

我以前从未使用过mono,也不知道发生了什么...但也许这意味着DLL不能被使用,因为它还没有与mono一起编译?如果是这种情况,这是否意味着我除非也有源代码,否则无法在mono中使用任何第三方DLL?

1个回答

6
因为默认的Mono使用v2.0运行时,但NuGet正在使用v4.0。这可以通过在Mono上定义运行时参数来解决:
mono --runtime=v4.0.30319 NuGet.exe

来源:http://monomvc.wordpress.com/2012/03/06/nuget-on-mono/

本文介绍了如何在Mono平台上使用NuGet,主要包括以下步骤: 1. 安装Mono 2. 安装NuGet 3. 配置NuGet源 4. 使用NuGet添加或删除包 此外,还提供了一些常见问题的解决方案。

谢谢,这在Windows上运行得很好!另外,Linux显示“此应用程序支持的运行时版本不可用,使用默认运行时v1.1.4322”,但那似乎是完全不同的问题。我会在可以的时候接受答案。 - natli
你有检查过这个线程吗:https://dev59.com/_2435IYBdhLWcg3wlRIf - Tarik
是的,看起来 apt-get install mono-complete 安装了版本为2.6.7,而我需要至少2.8才能运行 .net 4.0... 看来我得从源代码安装2.10.. 唉。还是谢谢你! - natli
顺便问一下,我想知道为什么你必须覆盖运行时使用的内容?根据 mono 的 man 页面,只有在尝试在不同于目标运行时的运行时上运行程序集时才需要这样做,也许它只是回退到了你所拥有的内容。 - markmnl

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接