csnemes / tracer

Tracing rewriter using Fody
Apache License 2.0
93 stars 26 forks source link

InvalidProgramException; "Common Language Runtime detected an invalid program." #110

Open cameron-foreflight opened 3 years ago

cameron-foreflight commented 3 years ago

Running my project in Release mode with Tracer.Serilog.Fody weaved in causes this exception on startup. When I remove the weaver from my FodyWeavers.xml or switch to Debug mode, the app continues running just fine.

csnemes commented 3 years ago

Could you please run PEVerify on the release mode assembly?

cameron-foreflight commented 3 years ago

Getting a bunch of The system cannot find the file specified. errors whenever I run PEVerify on the assembly, both with Tracer and without. Don't have a lot of experience using this tool, what specifically are you looking for?

csnemes commented 3 years ago

The reason for the invalid program exception is that Tracer messes up the IL code when adding trace functionality. PEVerify tool can check if the IL code and the metadata in the assembly are correct and can point out any problem. PEVerify can be run from developer's command prompt if you're using Visual Studio. I need to figure out what construct in your code causes this problem.

cameron-foreflight commented 3 years ago

Not finding a lot on PEVerify, so just don't know what is causing all of the The system cannot find the file specified. errors when I run from command prompt. I am getting this both without Tracer weaved in and with Tracer weaved in.

csnemes commented 3 years ago

Another option would be to add VerifyAssembly="true" to the Weavers element in the FodyWeavers.xml. It should run this PE verification after weaving and output the problem.

cameron-foreflight commented 3 years ago

Added that and built, and now have a lot of Unable to resolve token.(Error: 0x80131869) messages. Using ILSpy, I'm able to go in and see those methods and constructors and ensure they exist though.

cameron-foreflight commented 3 years ago

Should PEVerify, and Tracer.Serilog for that matter, work for UWP projects?

csnemes commented 3 years ago

Theoretically yes, but I've never tried it. Are you using some special language construct where this error appears? Could you give some minimal reproduction source code so I can debug into it? Anyway I'll create a small UWP project and check if it can be rewritten with tracer.

cameron-foreflight commented 3 years ago

No special language construct that I'm aware of. I'll see if I can put something together, but won't have a lot of time this week. Were you able to check Tracer with a small UWP project?

csnemes commented 3 years ago

I created a minimal UWP (just some buttons on a screen) and it works both in debug and release mode. One difference is that I used NLog, not Serilog. I'll check if it makes any difference.