Closed NiklasRosenstein closed 7 years ago
Hi,
You might want to run ILRepack with /verbose
arg to get more output.
Exception sounds strange, probably coming from ((ModuleDefinition) scope).Assembly.Name.Name
but hard to tell what is null here (and none of it should be !).
Assuming it only happens when your exe file (Newtonsoft.Json is very commonly repack'ed w/o issue), there could be something special about it, hard to guess.
Thx for the report though.
This one's from Windows with Mono (just FYI) using the /verbose
flag.
INFO: IL Repack - Version 2.0.13
VERBOSE: Runtime: ILRepack, Version=2.0.13.0, Culture=neutral, PublicKeyToken=null
INFO: ------------- IL Repack Arguments -------------
/out:build\cells\craftr\craftr-main-3.0.0-dev.exe build\cells\craftr\craftr-main-3.0.0-dev-intermediate.exe build\.nuget-artifacts\Newtonsoft.Json.10.0.3\lib\net40\Newtonsoft.Json.dll
-----------------------------------------------
INFO: Adding assembly for merge: build\cells\craftr\craftr-main-3.0.0-dev-intermediate.exe
INFO: Adding assembly for merge: build\.nuget-artifacts\Newtonsoft.Json.10.0.3\lib\net40\Newtonsoft.Json.dll
INFO: Processing references
INFO: Processing types
VERBOSE: - Importing <Module> from craftr-main-3.0.0-dev-intermediate.exe
VERBOSE: - Importing <Module>
INFO: Merging <Module>
VERBOSE: - Importing MainClass from craftr-main-3.0.0-dev-intermediate.exe
VERBOSE: - Importing MainClass
System.NotImplementedException: The method or operation is not implemented.
at Mono.Cecil.MetadataImporter.ImportScope (Mono.Cecil.IMetadataScope scope) [0x0004a] in <64e369dd574e4d42a56b1689deff9155>:0
at Mono.Cecil.MetadataImporter.ImportType (Mono.Cecil.TypeReference type, Mono.Cecil.ImportGenericContext context) [0x00098] in <64e369dd574e4d42a56b1689deff9155>:0
at Mono.Cecil.MetadataImporter.ImportMethod (Mono.Cecil.MethodReference method, Mono.Cecil.ImportGenericContext context) [0x00018] in <64e369dd574e4d42a56b1689deff9155>:0
at Mono.Cecil.MetadataImporter.ImportReference (Mono.Cecil.MethodReference method, Mono.Cecil.IGenericParameterProvider context) [0x0000e] in <64e369dd574e4d42a56b1689deff9155>:0
at Mono.Cecil.ModuleDefinition.ImportReference (Mono.Cecil.MethodReference method, Mono.Cecil.IGenericParameterProvider context) [0x0001e] in <64e369dd574e4d42a56b1689deff9155>:0
at ILRepacking.RepackImporter.Import (Mono.Cecil.MethodReference reference, Mono.Cecil.IGenericParameterProvider context) [0x0001c] in <64e369dd574e4d42a56b1689deff9155>:0
at ILRepacking.RepackImporter.CloneTo (Mono.Cecil.Cil.MethodBody body, Mono.Cecil.MethodDefinition parent) [0x0033e] in <64e369dd574e4d42a56b1689deff9155>:0
at ILRepacking.RepackImporter.CloneTo (Mono.Cecil.MethodDefinition meth, Mono.Cecil.TypeDefinition type, System.Boolean typeJustCreated) [0x0029f] in <64e369dd574e4d42a56b1689deff9155>:0
at ILRepacking.RepackImporter.Import (Mono.Cecil.TypeDefinition type, Mono.Collections.Generic.Collection`1[T] col, System.Boolean internalize) [0x0020f] in <64e369dd574e4d42a56b1689deff9155>:0
at ILRepacking.Steps.TypesRepackStep.RepackTypes () [0x00086] in <64e369dd574e4d42a56b1689deff9155>:0
at ILRepacking.Steps.TypesRepackStep.Perform () [0x00000] in <64e369dd574e4d42a56b1689deff9155>:0
at ILRepacking.ILRepack.Repack () [0x00305] in <64e369dd574e4d42a56b1689deff9155>:0
at ILRepacking.Application.Main (System.String[] args) [0x0004a] in <64e369dd574e4d42a56b1689deff9155>:0
Here's the MainClass, I don't think anything about it is special. When I do the same build not with Mono but MS C# and using ILMerge, it works.
using Newtonsoft.Json.Linq;
public class MainClass {
public static void Main(string[] args) {
string name = args.Length == 0 ? "World" : args[0];
HelloSayer.SayHello(name);
JArray array = new JArray();
array.Add("Manual text");
array.Add(new System.DateTime(2000, 5, 23));
JObject o = new JObject();
o["MyArray"] = array;
string json = o.ToString();
System.Console.WriteLine(o.ToString());
}
}
I also just tried ILRepack with assemblies compiled with MS C#, and I get a different error.
System.NotImplementedException: The method or operation is not implemented.
at Mono.Cecil.MetadataImporter.ImportScope(IMetadataScope scope)
at Mono.Cecil.MetadataImporter.ImportType(TypeReference type, ImportGenericContext context)
at Mono.Cecil.MetadataImporter.ImportMethod(MethodReference method, ImportGenericContext context)
at Mono.Cecil.MetadataImporter.ImportReference(MethodReference method, IGenericParameterProvider context)
at ILRepacking.RepackImporter.CloneTo(MethodBody body, MethodDefinition parent)
at ILRepacking.RepackImporter.CloneTo(MethodDefinition meth, TypeDefinition type, Boolean typeJustCreated)
at ILRepacking.RepackImporter.Import(TypeDefinition type, Collection`1 col, Boolean internalize)
at ILRepacking.Steps.TypesRepackStep.RepackTypes()
at ILRepacking.Steps.TypesRepackStep.Perform()
at ILRepacking.ILRepack.Repack()
at ILRepacking.Application.Main(String[] args)
Full output:
Here again it seems your exe file is being somewhat special (having ModuleReferences in metadata), was it build with VS ? which .Net version ?
Aha! Yes I compiled the HelloSayer.cs
as a Module.
$ csc -nologo -target:module -out:build\cells\craftr\craftr-lib-3.0.0-dev.netmodule C:\Users\niklas\repos\nodepy\craftr\examples\csharp\src\lib\HelloSayer.cs
If I compile it with -target:library
instead, it works (with both Mono or VS).
There's actually a mistake that the HelloSayer
was not passed to ILRepack, but it was added as a module to to the -intermediate.exe
. I'll try passing the module to ILRepack and see if that would work, too.
build with VS ? which .Net version ?
If with VS you mean "not with Mono", then yes. :) I suppose the default .Net version that CSC v2.1.0.61520 targets.? I'm not that familar with C# yet TBH 😅
Ok, netmodule don't seem to be (fully) supported by Cecil anyway, and not really widely used, did you build this way on purpose ?
Yes, I just tested passing the .netmodule
to ILRepack which gave another error (assembly could not be loaded). It seems ILMerge does not support them either and .netmodule
will always be resolved dynamically at runtime.
I only compiled it as a module for testing purposes. It seems that compiling as a library is the better way, and I'm totally fine with that.
As I understand it, ILRepack gives an error when it finds module references? Maybe it would be nice if it could work like ILMerge and just "ignore" them?
Thanks for your time :)
I don't really favor the "silent ignore" option, as it'll lead to runtime errors, I prefer compile-time ones. That being said, it could (/should) do a better job at telling you that you've got a netmodule ref (and it's not supported) or that you try to merge one (and it's not supported).
My 2 cents, if anyone wants to have a go at it.
Thx.
ILRepack Version 2.0.13
I was doing some tests with ILRepack and Mono, but I get the following error on Windows and Ubuntu (Travis CI):
I think this is not related to #96 because it's a different traceback? And also the issue was closed with a fix.
Here's the full output from installing ILRepack to compiling the source files with Mono and invoking ILRepack. Let me know if I can provide any additional information.
Spoiler
``` CSC v5.2.0.224 [INFO]: [Downloading] NuGet (build/.nuget-artifacts/nuget.exe) [INFO]: [Installing] ILRepack.2.0.13 Feeds used: https://api.nuget.org/v3/index.json Attempting to gather dependency information for package 'ILRepack.2.0.13' with respect to project '/home/travis/build/craftr-build/craftr/build/.nuget-artifacts', targeting 'Any,Version=v0.0' Gathering dependency information took 391.27 ms Attempting to resolve dependencies for package 'ILRepack.2.0.13' with DependencyBehavior 'Lowest' Resolving dependency information took 0 ms Resolving actions to install package 'ILRepack.2.0.13' Resolved actions to install package 'ILRepack.2.0.13' Retrieving package 'ILRepack 2.0.13' from 'nuget.org'. GET https://api.nuget.org/v3-flatcontainer/ilrepack/2.0.13/ilrepack.2.0.13.nupkg OK https://api.nuget.org/v3-flatcontainer/ilrepack/2.0.13/ilrepack.2.0.13.nupkg 56ms Installing ILRepack 2.0.13. Adding package 'ILRepack.2.0.13' to folder '/home/travis/build/craftr-build/craftr/build/.nuget-artifacts' Added package 'ILRepack.2.0.13' to folder '/home/travis/build/craftr-build/craftr/build/.nuget-artifacts' Successfully installed 'ILRepack 2.0.13' to /home/travis/build/craftr-build/craftr/build/.nuget-artifacts Executing nuget actions took 209.55 ms (1/8) [//craftr:lib#mkdir]: mkdir build/cells/craftr (2/8) [//craftr:Json.NET#1]: $ mono /home/travis/build/craftr-build/craftr/build/.nuget-artifacts/nuget.exe install Newtonsoft.Json -Version 10.0.3 (3/8) [//craftr:lib#csc]: $ mcs -nologo -target:module -out:build/cells/craftr/craftr-lib-3.0.0-dev.netmodule /home/travis/build/craftr-build/craftr/examples/csharp/src/lib/HelloSayer.cs [//craftr:Json.NET#1]: $ mono /home/travis/build/craftr-build/craftr/build/.nuget-artifacts/nuget.exe install Newtonsoft.Json -Version 10.0.3 Feeds used: /home/travis/.nuget/packages/ https://api.nuget.org/v3/index.json Attempting to gather dependency information for package 'Newtonsoft.Json.10.0.3' with respect to project '/home/travis/build/craftr-build/craftr/build/.nuget-artifacts', targeting 'Any,Version=v0.0' Gathering dependency information took 585.83 ms Attempting to resolve dependencies for package 'Newtonsoft.Json.10.0.3' with DependencyBehavior 'Lowest' Resolving dependency information took 0 ms Resolving actions to install package 'Newtonsoft.Json.10.0.3' Resolved actions to install package 'Newtonsoft.Json.10.0.3' Retrieving package 'Newtonsoft.Json 10.0.3' from 'nuget.org'. GET https://api.nuget.org/v3-flatcontainer/newtonsoft.json/10.0.3/newtonsoft.json.10.0.3.nupkg OK https://api.nuget.org/v3-flatcontainer/newtonsoft.json/10.0.3/newtonsoft.json.10.0.3.nupkg 15ms Installing Newtonsoft.Json 10.0.3. Adding package 'Newtonsoft.Json.10.0.3' to folder '/home/travis/build/craftr-build/craftr/build/.nuget-artifacts' Added package 'Newtonsoft.Json.10.0.3' to folder '/home/travis/build/craftr-build/craftr/build/.nuget-artifacts' Successfully installed 'Newtonsoft.Json 10.0.3' to /home/travis/build/craftr-build/craftr/build/.nuget-artifacts Executing nuget actions took 438.17 ms (4/8) [//craftr:main#csc]: $ mcs -nologo -target:exe -out:build/cells/craftr/craftr-main-3.0.0-dev-intermediate.exe -addmodule:build/cells/craftr/craftr-lib-3.0.0-dev.netmodule -reference:build/.nuget-artifacts/Newtonsoft.Json.10.0.3/lib/net40/Newtonsoft.Json.dll /home/travis/build/craftr-build/craftr/examples/csharp/src/Main.cs [//craftr:main#csc]: $ mcs -nologo -target:exe -out:build/cells/craftr/craftr-main-3.0.0-dev-intermediate.exe -addmodule:build/cells/craftr/craftr-lib-3.0.0-dev.netmodule -reference:build/.nuget-artifacts/Newtonsoft.Json.10.0.3/lib/net40/Newtonsoft.Json.dll /home/travis/build/craftr-build/craftr/examples/csharp/src/Main.cs /home/travis/build/craftr-build/craftr/examples/csharp/src/Main.cs(16,12): warning CS0219: The variable `json' is assigned but its value is never used Compilation succeeded - 1 warning(s) (5/8) [//craftr:main#ilmerge]: $ mono /home/travis/build/craftr-build/craftr/build/.nuget-artifacts/ILRepack.2.0.13/tools/ILRepack.exe /out:build/cells/craftr/craftr-main-3.0.0-dev.exe build/cells/craftr/craftr-main-3.0.0-dev-intermediate.exe build/.nuget-artifacts/Newtonsoft.Json.10.0.3/lib/net40/Newtonsoft.Json.dll [//craftr:main#ilmerge]: $ mono /home/travis/build/craftr-build/craftr/build/.nuget-artifacts/ILRepack.2.0.13/tools/ILRepack.exe /out:build/cells/craftr/craftr-main-3.0.0-dev.exe build/cells/craftr/craftr-main-3.0.0-dev-intermediate.exe build/.nuget-artifacts/Newtonsoft.Json.10.0.3/lib/net40/Newtonsoft.Json.dll INFO: IL Repack - Version 2.0.13 INFO: ------------- IL Repack Arguments ------------- /out:build/cells/craftr/craftr-main-3.0.0-dev.exe build/cells/craftr/craftr-main-3.0.0-dev-intermediate.exe build/.nuget-artifacts/Newtonsoft.Json.10.0.3/lib/net40/Newtonsoft.Json.dll ----------------------------------------------- INFO: Adding assembly for merge: build/cells/craftr/craftr-main-3.0.0-dev-intermediate.exe INFO: Adding assembly for merge: build/.nuget-artifacts/Newtonsoft.Json.10.0.3/lib/net40/Newtonsoft.Json.dll INFO: Processing references INFO: Processing types INFO: Merging