Hi All,

I ran into a bug in the latest revision of Cecil (pulled from Github)
which causes a StackOverflowException to be thrown in GenericParameter
when you write an assembly definition to disk. I noticed it when I
used Cecil to modify a C#-based .exe which references an F#-based
library, but the bug is trivial to reproduce if you just load the
FSharp.Core assembly, then attempt to write it back to disk (see repro
code below). I haven't delved into Cecil innards much, but at first
glance it seems that GenericParameter gets stuck in an infinite loop
by trying to resolve it's "owner".

Hope this helps.

Cheers,
Jack

---------- Code to reproduce the bug ----------

// Load an F# assembly (e.g., FSharp.Core)
// The bug also occurs in some cases when C# projects reference an F#-
based assembly
string TargetAssemblyPath = @"C:\Program Files (x86)\Reference
Assemblies\Microsoft\FSharp\2.0\Runtime\v2.0\FSharp.Core.dll";
AssemblyDefinition FSharpAsmDef =
AssemblyDefinition.ReadAssembly(TargetAssemblyPath, new
ReaderParameters(ReadingMode.Immediate));

// Pause before writing
Console.WriteLine("Press any key to save the assembly...");
Console.ReadKey();

// Try to save the assembly to the current user's desktop
// A StackOverflowException should occur in GenericParameter (it gets
caught in an infinite loop)
FSharpAsmDef.Write(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
"Cecil-" + System.IO.Path.GetFileName(TargetAssemblyPath)));

// If we get here, everything worked
Console.WriteLine("Save successful. Press any key to exit.");
Console.ReadKey();

-- 
--
mono-cecil

Reply via email to