Capgemini / Cauldron

C# Toolkit
MIT License
77 stars 18 forks source link

[Cauldron.Interception.Fody] Build error after code modification #59

Closed LaborJos closed 6 years ago

LaborJos commented 6 years ago

Error message at first build after code modification

Severity    Code    Description Project File    Line    Suppression State
Error       Fody: An unhandled exception occurred:
Exception:
Member 'System.Boolean System.Convert::ToBoolean(System.Object)' is declared in another module and needs to be imported
Type:
System.ArgumentException
StackTrace:
   at Mono.Cecil.MetadataBuilder.LookupToken(IMetadataTokenProvider provider) in C:\projects\cecil-xf0ml\Mono.Cecil\AssemblyWriter.cs:line 2220
   at Mono.Cecil.Cil.CodeWriter.WriteOperand(Instruction instruction) in C:\projects\cecil-xf0ml\Mono.Cecil.Cil\CodeWriter.cs:line 272
   at Mono.Cecil.Cil.CodeWriter.WriteInstructions() in C:\projects\cecil-xf0ml\Mono.Cecil.Cil\CodeWriter.cs:line 182
   at Mono.Cecil.Cil.CodeWriter.WriteResolvedMethodBody(MethodDefinition method) in C:\projects\cecil-xf0ml\Mono.Cecil.Cil\CodeWriter.cs:line 120
   at Mono.Cecil.Cil.CodeWriter.WriteMethodBody(MethodDefinition method) in C:\projects\cecil-xf0ml\Mono.Cecil.Cil\CodeWriter.cs:line 56
   at Mono.Cecil.MetadataBuilder.AddMethod(MethodDefinition method) in C:\projects\cecil-xf0ml\Mono.Cecil\AssemblyWriter.cs:line 1635
   at Mono.Cecil.MetadataBuilder.AddMethods(TypeDefinition type) in C:\projects\cecil-xf0ml\Mono.Cecil\AssemblyWriter.cs:line 1627
   at Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type) in C:\projects\cecil-xf0ml\Mono.Cecil\AssemblyWriter.cs:line 1449
   at Mono.Cecil.MetadataBuilder.AddTypes() in C:\projects\cecil-xf0ml\Mono.Cecil\AssemblyWriter.cs:line 1420
   at Mono.Cecil.MetadataBuilder.BuildTypes() in C:\projects\cecil-xf0ml\Mono.Cecil\AssemblyWriter.cs:line 1274
   at Mono.Cecil.MetadataBuilder.BuildModule() in C:\projects\cecil-xf0ml\Mono.Cecil\AssemblyWriter.cs:line 1038
   at Mono.Cecil.MetadataBuilder.BuildMetadata() in C:\projects\cecil-xf0ml\Mono.Cecil\AssemblyWriter.cs:line 1008
   at Mono.Cecil.ModuleWriter.<>c.<BuildMetadata>b__2_0(MetadataBuilder builder, MetadataReader _) in C:\projects\cecil-xf0ml\Mono.Cecil\AssemblyWriter.cs:line 136
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read) in C:\projects\cecil-xf0ml\Mono.Cecil\ModuleDefinition.cs:line 958
   at Mono.Cecil.ModuleWriter.BuildMetadata(ModuleDefinition module, MetadataBuilder metadata) in C:\projects\cecil-xf0ml\Mono.Cecil\AssemblyWriter.cs:line 135
   at Mono.Cecil.ModuleWriter.Write(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters) in C:\projects\cecil-xf0ml\Mono.Cecil\AssemblyWriter.cs:line 115
   at Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters) in C:\projects\cecil-xf0ml\Mono.Cecil\AssemblyWriter.cs:line 79
   at Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters) in C:\projects\cecil-xf0ml\Mono.Cecil\ModuleDefinition.cs:line 1154
   at InnerWeaver.WriteModule()
   at InnerWeaver.Execute()
Source:
Mono.Cecil
TargetSite:
Mono.Cecil.MetadataToken LookupToken(Mono.Cecil.IMetadataTokenProvider) VM.DAFUL.ViewModels.Pre

Second build error message after modifying code

Severity    Code    Description Project File    Line    Suppression State
Error       Fody: An unhandled exception occurred:
Exception:
Format of the executable (.exe) or library (.dll) is invalid.
Type:
System.BadImageFormatException
StackTrace:
   at Mono.Cecil.PE.ImageReader.ReadImage() in C:\projects\cecil-xf0ml\Mono.Cecil.PE\ImageReader.cs:line 47
   at Mono.Cecil.PE.ImageReader.ReadImage(Disposable`1 stream, String file_name) in C:\projects\cecil-xf0ml\Mono.Cecil.PE\ImageReader.cs:line 759
   at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters) in C:\projects\cecil-xf0ml\Mono.Cecil\ModuleDefinition.cs:line 1110
   at ContainsTypeChecker.Check(String assemblyPath, String typeName)
   at Processor.ShouldStartSinceFileChanged()
   at Processor.Inner()
   at Processor.Execute()
Source:
Mono.Cecil
TargetSite:
Void ReadImage()    VM.DAFUL.ViewModels.Pre         

If I continue building, the second error message is repeated.

Clean and build a project or solution, it will build normally. The reason for reporting the error here is that it does not happen when "Cauldron.Interception" is excluded from "Weavers.xml".

reflection-emit commented 6 years ago

Hi,

a simple full rebuild might solve the problem. The is only one place in Cauldron where a ToBoolean is added and it is actually imported. I have this problem sometimes also and until now I am not sure if this is a Cecil problem or Cauldron code problem.


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.

LaborJos commented 6 years ago

Each time a clean or rebuild project (solution) takes too long, the solution size is large. Is there any other solution?

reflection-emit commented 6 years ago

The time Cauldron takes to weave is logged in the build window. Can you tell me which of those takes long?


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

I added a Verbose attribute to the FodyWeaver.xml config. This will improve speed for a couple seconds... I hope. Example of usage:

 <Cauldron.Interception Verbose="false">
    <CustomInterceptors>
      $(ProjectDir)..\..\..\Fody\Interceptors\Cauldron.ActivatorInterceptors*.dll
      $(ProjectDir)..\..\..\Fody\Interceptors\Cauldron.BasicInterceptors*.dll
    </CustomInterceptors>
  </Cauldron.Interception>

The default value is true.

reflection-emit commented 6 years ago

I found a work around... Killing MSBuild and then building seems to eliminate the problem. Until it appears again...