Capgemini / Cauldron

C# Toolkit
MIT License
76 stars 18 forks source link

OutOfMemoryException on build intercepted project #46

Closed rualmar closed 6 years ago

rualmar commented 6 years ago

I have a project (ProcessManager.sll) using Cauldron.Interception. On that same project I have referenced a custom reports NuGet which itself references some ActiveRreports dll.

When building the original ProcessManager.dll project I get this error (i obfuscated project paths as Report_NuGet_Local_Path)

MSBUILD : error : Fody/Cauldron.Interception: Exception Type: Exception
1>MSBUILD : error : Source: FodyIsolated
1>MSBUILD : error : Could not read '[Report_NuGet_Local_Path]\ActiveReports.Document.dll'.
1>MSBUILD : error : ------------------------
1>MSBUILD : error :    at AssemblyResolver.GetAssembly(String file, ReaderParameters parameters) in C:\projects\fody\FodyIsolated\AssemblyResolver.cs:line 46
1>MSBUILD : error :    at AssemblyResolver.Resolve(AssemblyNameReference assemblyNameReference, ReaderParameters parameters) in C:\projects\fody\FodyIsolated\AssemblyResolver.cs:line 69
1>MSBUILD : error :    at AssemblyResolver.Resolve(AssemblyNameReference assemblyNameReference) in C:\projects\fody\FodyIsolated\AssemblyResolver.cs:line 57
1>MSBUILD : error :    at Cauldron.Interception.Cecilator.CecilatorBase.<GetAllAssemblyDefinitions>b__24_0(AssemblyNameReference x)
1>MSBUILD : error :    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
1>MSBUILD : error :    at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
1>MSBUILD : error :    at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
1>MSBUILD : error :    at Cauldron.Interception.Cecilator.CecilatorBase.GetAllAssemblyDefinitions(IEnumerable`1 target, List`1 result)
1>MSBUILD : error :    at Cauldron.Interception.Cecilator.CecilatorBase.GetAllAssemblyDefinitions(IEnumerable`1 target)
1>MSBUILD : error :    at Cauldron.Interception.Cecilator.CecilatorBase..ctor(WeaverBase weaver)
1>MSBUILD : error :    at Cauldron.Interception.Cecilator.Extension.CreateBuilder(WeaverBase weaver)
1>MSBUILD : error :    at Cauldron.Interception.Cecilator.WeaverBase.Execute()
1>MSBUILD : error : ------------------------
1>MSBUILD : error : Exception Type: OutOfMemoryException
1>MSBUILD : error : Source: mscorlib
1>MSBUILD : error : Exception of type 'System.OutOfMemoryException' was thrown.
1>MSBUILD : error : ------------------------
1>MSBUILD : error :    at System.IO.BinaryReader.ReadBytes(Int32 count)
1>MSBUILD : error :    at Mono.Cecil.PE.ImageReader.ReadDebugHeader() in C:\projects\cecil\Mono.Cecil.PE\ImageReader.cs:line 357
1>MSBUILD : error :    at Mono.Cecil.PE.ImageReader.ReadImage() in C:\projects\cecil\Mono.Cecil.PE\ImageReader.cs:line 89
1>MSBUILD : error :    at Mono.Cecil.PE.ImageReader.ReadImage(Disposable`1 stream, String file_name) in C:\projects\cecil\Mono.Cecil.PE\ImageReader.cs:line 759
1>MSBUILD : error :    at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters) in C:\projects\cecil\Mono.Cecil\ModuleDefinition.cs:line 1092
1>MSBUILD : error :    at AssemblyResolver.GetAssembly(String file, ReaderParameters parameters) in C:\projects\fody\FodyIsolated\AssemblyResolver.cs:line 42
1>MSBUILD : error : ------------------------
1>MSBUILD : error : 
1>MSBUILD : error : Fody: An unhandled exception occurred:
1>MSBUILD : error : Exception:
1>MSBUILD : error : Could not read '[Report_NuGet_Local_Path]\ActiveReports.Document.dll'.
1>MSBUILD : error : StackTrace:
1>MSBUILD : error :    at AssemblyResolver.GetAssembly(String file, ReaderParameters parameters) in C:\projects\fody\FodyIsolated\AssemblyResolver.cs:line 46
1>MSBUILD : error :    at AssemblyResolver.Resolve(AssemblyNameReference assemblyNameReference, ReaderParameters parameters) in C:\projects\fody\FodyIsolated\AssemblyResolver.cs:line 69
1>MSBUILD : error :    at AssemblyResolver.Resolve(AssemblyNameReference assemblyNameReference) in C:\projects\fody\FodyIsolated\AssemblyResolver.cs:line 57
1>MSBUILD : error :    at Cauldron.Interception.Cecilator.CecilatorBase.<GetAllAssemblyDefinitions>b__24_0(AssemblyNameReference x)
1>MSBUILD : error :    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
1>MSBUILD : error :    at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
1>MSBUILD : error :    at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
1>MSBUILD : error :    at Cauldron.Interception.Cecilator.CecilatorBase.GetAllAssemblyDefinitions(IEnumerable`1 target, List`1 result)
1>MSBUILD : error :    at Cauldron.Interception.Cecilator.CecilatorBase.GetAllAssemblyDefinitions(IEnumerable`1 target)
1>MSBUILD : error :    at Cauldron.Interception.Cecilator.CecilatorBase..ctor(WeaverBase weaver)
1>MSBUILD : error :    at Cauldron.Interception.Cecilator.Extension.CreateBuilder(WeaverBase weaver)
1>MSBUILD : error :    at Cauldron.Interception.Cecilator.WeaverBase.Execute()
1>MSBUILD : error :    at lambda_method(Closure , Object )
1>MSBUILD : error :    at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 198
1>MSBUILD : error :    at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 100
1>MSBUILD : error : Source:
1>MSBUILD : error : FodyIsolated
1>MSBUILD : error : TargetSite:
1>MSBUILD : error : Mono.Cecil.AssemblyDefinition GetAssembly(System.String, Mono.Cecil.ReaderParameters)
1>MSBUILD : error : Exception of type 'System.OutOfMemoryException' was thrown.
1>MSBUILD : error : StackTrace:
1>MSBUILD : error :    at System.IO.BinaryReader.ReadBytes(Int32 count)
1>MSBUILD : error :    at Mono.Cecil.PE.ImageReader.ReadDebugHeader() in C:\projects\cecil\Mono.Cecil.PE\ImageReader.cs:line 357
1>MSBUILD : error :    at Mono.Cecil.PE.ImageReader.ReadImage() in C:\projects\cecil\Mono.Cecil.PE\ImageReader.cs:line 89
1>MSBUILD : error :    at Mono.Cecil.PE.ImageReader.ReadImage(Disposable`1 stream, String file_name) in C:\projects\cecil\Mono.Cecil.PE\ImageReader.cs:line 759
1>MSBUILD : error :    at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters) in C:\projects\cecil\Mono.Cecil\ModuleDefinition.cs:line 1092
1>MSBUILD : error :    at AssemblyResolver.GetAssembly(String file, ReaderParameters parameters) in C:\projects\fody\FodyIsolated\AssemblyResolver.cs:line 42
1>MSBUILD : error : Source:
1>MSBUILD : error : mscorlib
1>MSBUILD : error : TargetSite:
1>MSBUILD : error : Byte[] ReadBytes(Int32)
1>MSBUILD : error : 

I've googled about it and found Fody has some trouble via Cecil with certain versions of Mono. Is there any workaround for this? I've been using Cauldron.Interceptor with other projects with no problems, only get this when I combine it with those dlls.

reflection-emit commented 6 years ago

From looking at the StackTrace, you are right it is a Cecil problem. For my part I could try to exclude dlls, but if they are reference I don’t think I can stop Cecil from loading/reading them. But still I will try, maybe I will find a workaround.


Firma: Capgemini Deutschland GmbH Aufsichtsratsvorsitzender: Antonio Schnieder • Geschäftsführer: Dr. Michael Schulte (Sprecher) • Jost Förster • Dr. Peter Lempp • Dr. Volkmar Varnhagen

Amtsgericht Berlin-Charlottenburg, HRB 98814 This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.

rualmar commented 6 years ago

So there's no way of making Fody/Cauldron.Interception not reading those dlls, isn't it? (via Fodyweavers.xml or something).

reflection-emit commented 6 years ago

Without code change… No… Because as you can see, the exception happens when Cauldron calls Resolve in Cecil. Resolve is essential though, so there is no way of avoiding it. Cauldron copies the original method body into an emptied method. The copying requires also to read the IL instructions per instructions. So if a method has a type that is in that dll, Cauldron will ask Cecil to resolve it. There it fails. I have to see what to do about this. Maybe I can skip (If that works) resolve, if the OutOfMemoryException is thrown.


Firma: Capgemini Deutschland GmbH Aufsichtsratsvorsitzender: Antonio Schnieder • Geschäftsführer: Dr. Michael Schulte (Sprecher) • Jost Förster • Dr. Peter Lempp • Dr. Volkmar Varnhagen

Amtsgericht Berlin-Charlottenburg, HRB 98814 This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.

reflection-emit commented 6 years ago

Can you please check if your issues are fixed with 2.0.22

rualmar commented 6 years ago

Of course! I won't be on my pc until tomorow, but I'll check it as soon as I can and give you feedback. Thank you!

rualmar commented 6 years ago

I had some free time so I could test it before i thought. Unfortunately it keeps giving the same error with the same exact stack trace 😢

reflection-emit commented 6 years ago

Hmm… Is there any possibility that you can send me a test project?


Firma: Capgemini Deutschland GmbH Aufsichtsratsvorsitzender: Antonio Schnieder • Geschäftsführer: Dr. Michael Schulte (Sprecher) • Jost Förster • Dr. Peter Lempp • Dr. Volkmar Varnhagen

Amtsgericht Berlin-Charlottenburg, HRB 98814 This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.

rualmar commented 6 years ago

Not the current one I'm using, since is too big and full of internal references/nugets/... but I'll try to set up a project with only the ActiveReports references and see if it still gives this error and send it to you.

reflection-emit commented 6 years ago

Cool thank… That would help a lot.


Firma: Capgemini Deutschland GmbH Aufsichtsratsvorsitzender: Antonio Schnieder • Geschäftsführer: Dr. Michael Schulte (Sprecher) • Jost Förster • Dr. Peter Lempp • Dr. Volkmar Varnhagen

Amtsgericht Berlin-Charlottenburg, HRB 98814 This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.

reflection-emit commented 6 years ago

This should be gone on the latest version.