IL offsets missing when silverlight assembly is compiled in release mode

8

I followed these instructions to add IL offsets to Silverlight stack traces. This works great when building in DEBUG mode however our production/qa build process compiles everything using RELEASE mode which seems to loose the IL offset information. In release mode all the IL offsets end up being "0xffffffff". Using reflector to compare the debug/release assemblies I noticed the DebuggableAttribute was used differently.

DEBUG build:

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: ComVisible(false)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.EnableEditAndContinue | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.Default)]
[assembly: AssemblyConfiguration("Debug")]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows=true)]
[assembly: Extension]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: CompilationRelaxations(8)]
[assembly: TargetFramework("Silverlight,Version=v5.0", FrameworkDisplayName="Silverlight 4")]
[assembly: AssemblyCopyright("Copyright @ Foo Company 2010-2012")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyTitle("Foo.Ria.Bar")]
[assembly: AssemblyCompany("Foo Company")]
[assembly: AssemblyProduct("Foo Product")]

vs RELEASE build:

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: ComVisible(false)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows=true)]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyTitle("Foo.Ria.Bar")]
[assembly: AssemblyTrademark("")]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: CompilationRelaxations(8)]
[assembly: TargetFramework("Silverlight,Version=v5.0", FrameworkDisplayName="Silverlight 4")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyCompany("Foo Company")]
[assembly: AssemblyProduct("Foo Product")

MSDN says

The DebuggableAttribute class controls how the runtime treats code within the module. The runtime might track extra information about generated code, and it might disable certain optimizations based on the values contained within this attribute.

Does anyone have experience tweaking the DebuggableAttribute settings? Is there any workaround that doesn't involve disabling optimizations entirely (DebuggingModes.DisableOptimizations)?

.net
silverlight
il
asked on Stack Overflow Sep 4, 2012 by Jeremy Danyow

1 Answer

0

The DebuggableAttribute is added by the compiler to control the JIT code generation. In fact, code gets generated differently when it is supposed to be debuggable and certain optimizations do not take place.

If you need to tweak the assembly generated, you need to dump the IL, alter the attribute and recompile it back via: ildasm creates a human readable IL source that can be altered by a convetional text editor, while ilasm is used to recompile it back.

This process can be automated in your build. Just remember that you are messing up with something generated by the compiler and not supposed to be touched.

Important: the assembly needs to be signed again in case strong name and/ir authenticode is used.

answered on Stack Overflow Dec 5, 2019 by Yennefer

User contributions licensed under CC BY-SA 3.0