dotnet / ILMerge

ILMerge is a static linker for .NET Assemblies.
MIT License
1.23k stars 170 forks source link

OutOfMemoryException error when merging NodaTime #29

Open ghost opened 6 years ago

ghost commented 6 years ago

When I try to use ILMerge to merge a C# DLL that uses NodaTime, I get the following error: 1>[NuGet Packages Dir]\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.targets(87,5): error : ILMerge.Merge: There were errors reported in NodaTime's metadata. 1>[NuGet Packages Dir]\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.targets(87,5): error : Exception of type 'System.OutOfMemoryException' was thrown.

It seems like there is an error merging in NodaTime's PDB because the build is successful if I manually remove the NodaTime PDB. Another workaround is to set ILMergeDebugInfo option to false.

In my case I'm using VS2017, with a C# project targeting .NET 4.7. I use NuGet to pull in the NodaTime and ILMerge dependencies. The specific packages are:

As a temporary workaround, is it possible to tell ILMerge to ignore the NodaTime PDB (without disabling merging of PDBs of other dependencies and generation of a PDB for the primary assembly)?

mike-barnett commented 6 years ago

Do you know if that PDB is in the new portable PDB format? I've heard that ILMerge is not able to deal with such PDB files. If you can package the repro into a zip file and send it to me, then I can take a look. Sorry for the problem!

ghost commented 6 years ago

No need to apologies.

NodaTime does publish their library as both a .NET 4.5 and .NETStandard 1.3 library. I can confirm that the .NET 4.5 library is what's being referenced by my project and the PDB also comes from the .NET 4.5 library.

I've attached a test solution that demonstrates the error: ILMergeTest.zip

Thanks for the quick reply.

mike-barnett commented 6 years ago

I looked into it and believe that the PDB file in NodaTime's net45 directory is the new portable PDB format. At least, it's format as seen in ILMerge looks to be the same as the one in NodaTime's netstandard1.3 directory. You should check with the authors of NodaTime to confirm. ILMerge is not able to read that new format. If you can open a new issue for modifying ILMerge to selectively ignore certain PDB files, then I can try to get time to get to that. Thanks!

ghost commented 6 years ago

Hi Mike,

Thanks for the update. I have contacted the NodaTime NuGet package author to confirm whether the net45 directory's PDB is in the portable PDB format.

I shall create a new task for the work to ignore certain PDB files.

If I may, what is the progress on support for the new portable PDB format in ILMerge?

lextm commented 6 years ago

@colin-sim Read #11.