我遇到了与[Mono-dev] monolinker 在“hello, world”上失败中描述的相同的问题——有什么想法吗?.
C:\monotest>type test.cs
public class Test
{
public static void Main() {
System.Console.WriteLine("BOO");
}
}
C:\monotest>"C:\Program Files (x86)\Mono-2.10.9\bin\monolinker.bat" -a "test.exe" -c link
Fatal error in Mono CIL Linker
System.ArgumentException: Member 'System.Security.AccessControl.AccessRule' is declared in another module and needs to be imported
at Mono.Cecil.MetadataBuilder.LookupToken (IMetadataTokenProvider provider) [0x00000] in <filename unknown>:0
at Mono.Cecil.SignatureWriter.MakeTypeDefOrRefCodedRID (Mono.Cecil.TypeReference type) [0x00000] in <filename unknown>:0
at Mono.Cecil.SignatureWriter.WriteTypeSignature (Mono.Cecil.TypeReference type) [0x00000] in <filename unknown>:0
at Mono.Cecil.SignatureWriter.WriteGenericInstanceSignature (IGenericInstance instance) [0x00000] in <filename unknown>:0
at Mono.Cecil.SignatureWriter.WriteTypeSignature (Mono.Cecil.TypeReference type) [0x00000] in <filename unknown>:0
at Mono.Cecil.MetadataBuilder.GetFieldSignature (Mono.Cecil.FieldReference field) [0x00000] in <filename unknown>:0
at Mono.Cecil.MetadataBuilder.AddField (Mono.Cecil.FieldDefinition field) [0x00000] in <filename unknown>:0
at Mono.Cecil.MetadataBuilder.AddFields (Mono.Cecil.TypeDefinition type) [0x00000] in <filename unknown>:0
at Mono.Cecil.MetadataBuilder.AddType (Mono.Cecil.TypeDefinition type) [0x00000] in <filename unknown>:0
at Mono.Cecil.MetadataBuilder.AddTypeDefs () [0x00000] in <filename unknown>:0
at Mono.Cecil.MetadataBuilder.BuildTypes () [0x00000] in <filename unknown>:0
at Mono.Cecil.MetadataBuilder.BuildModule () [0x00000] in <filename unknown>:0
at Mono.Cecil.MetadataBuilder.BuildMetadata () [0x00000] in <filename unknown>:0
at Mono.Cecil.ModuleWriter.<BuildMetadata>m__18 (Mono.Cecil.MetadataBuilder builder, Mono.Cecil.MetadataReader _) [0x00000] in <filename unknown>:0
at Mono.Cecil.ModuleDefinition.Read[MetadataBuilder,MetadataBuilder] (Mono.Cecil.MetadataBuilder item, System.Func`3 read) [0x00000] in <filename unknown>:0
at Mono.Cecil.ModuleWriter.BuildMetadata (Mono.Cecil.ModuleDefinition module, Mono.Cecil.MetadataBuilder metadata) [0x00000] in <filename unknown>:0
at Mono.Cecil.ModuleWriter.WriteModuleTo (Mono.Cecil.ModuleDefinition module, System.IO.Stream stream, Mono.Cecil.WriterParameters parameters) [0x00000] in <filename unknown>:0
at Mono.Cecil.ModuleDefinition.Write (System.IO.Stream stream, Mono.Cecil.WriterParameters parameters) [0x00000] in <filename unknown>:0
at Mono.Cecil.ModuleDefinition.Write (System.String fileName, Mono.Cecil.WriterParameters parameters) [0x00000] in <filename unknown>:0
at Mono.Cecil.AssemblyDefinition.Write (System.String fileName, Mono.Cecil.WriterParameters parameters) [0x00000] in <filename unknown>:0
at Mono.Linker.Steps.OutputStep.OutputAssembly (Mono.Cecil.AssemblyDefinition assembly) [0x00000] in <filename unknown>:0
at Mono.Linker.Steps.OutputStep.ProcessAssembly (Mono.Cecil.AssemblyDefinition assembly) [0x00000] in <filename unknown>:0
at Mono.Linker.Steps.BaseStep.Process (Mono.Linker.LinkContext context) [0x00000] in <filename unknown>:0
at Mono.Linker.Pipeline.Process (Mono.Linker.LinkContext context) [0x00000] in <filename unknown>:0
at Mono.Linker.Driver.Run () [0x00000] in <filename unknown>:0
at Mono.Linker.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0
我没有在 Linux 下测试过,但是引用的例子做了。在 2.10.8 和 2.10.9 下也会发生同样的情况。
我发现一个开源项目已经注释掉了对“throw CreateForeignMemberException (member);”的调用。在 Cecil 中,这是导致此问题的原因:Simple Assembly Explorer, svn/trunk/Mono.Cecil/Mono.Cecil/AssemblyWriter.cs。
GitHub 上Cecil 的主干仍然有该代码处于活动状态。我厌倦了删除我一开始不理解的支票。
在堆栈溢出问题中,是否有一个免费工具能够从 CLI 程序集中修剪未使用的代码?,Mono链接器的作者建议自己编译:
请注意,所有发布的 Mono 版本都带有链接器的编译版本,但我建议您自己编译它。
为什么我需要自己编译?我该怎么做才能让它工作?在这一点上,我真的只是在探索它的用途,但它似乎很有希望。