It appears that this bug only occurs if I have the VS 2010 debugger attached
to the assembly that tries to read the test assembly.
If I start the application in Debug mode, but without the debugger attached,
read the assembly, and attach the debugger afterwards, everything works fine
(though I haven't tried actually saving the new assembly yet).Very weird.

Any idea what's causing it?

2011/3/25 Gábor Kozár <[email protected]>

> Hey,
>
> http://kezziny.myip.hu:81/cecil-crashing.zip
>
> Hope it helps! The binaries are compiled in Debug mode - I don't know
> whether that's relevant - so I've also attached the pdb files.
>
> 2011/3/25 Jb Evain <[email protected]>
>
>> Hi, could you attach or upload the binary that triggers the crash
>> somewhere ?
>>
>> Thanks !
>>
>> On Thursday, March 24, 2011, ShdNx <[email protected]> wrote:
>> > Hey,
>> >
>> > I'm trying to read a small test assembly using
>> > AssemblyDefinition.ReadAssembly, and I get the following exception:
>> >
>> > System.TypeInitializationException: The type initializer for
>> > 'Mono.Cecil.Metadata.TableHeap' threw an exception.
>> >    at Mono.Cecil.Metadata.TableHeap..ctor(Section section, UInt32
>> > start, UInt32 size)
>> >    at Mono.Cecil.PE.ImageReader.ReadMetadataStream(Section section)
>> >    at Mono.Cecil.PE.ImageReader.ReadMetadata()
>> >    at Mono.Cecil.PE.ImageReader.ReadImage()
>> >    at Mono.Cecil.PE.ImageReader.ReadImageFrom(Stream stream)
>> >    at Mono.Cecil.ModuleDefinition.ReadModule(Stream stream,
>> > ReaderParameters parameters)
>> >    at Mono.Cecil.ModuleDefinition.ReadModule(String fileName,
>> > ReaderParameters parameters)
>> >    at Mono.Cecil.ModuleDefinition.ReadModule(String fileName)
>> >    at Mono.Cecil.AssemblyDefinition.ReadAssembly(String fileName)
>> >    at MyProgram.Main(String[] args) in C:\Dev\...\Program.cs:line 44
>> >    at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,
>> > String[] args)
>> >    at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly,
>> > String[] args)
>> >    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
>> > assemblySecurity, String[] args)
>> >    at
>> > Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
>> >    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
>> >    at System.Threading.ExecutionContext.Run(ExecutionContext
>> > executionContext, ContextCallback callback, Object state, Boolean
>> > ignoreSyncCtx)
>> >    at System.Threading.ExecutionContext.Run(ExecutionContext
>> > executionContext, ContextCallback callback, Object state)
>> >    at System.Threading.ThreadHelper.ThreadStart()
>> >
>> > Here is the InnerException:
>> >
>> > System.ArgumentException: Value does not fall within the expected
>> > range.
>> >    at
>> > System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(Array
>> > array, RuntimeFieldHandle fldHandle)
>> >    at Mono.Cecil.Metadata.TableHeap..cctor()
>> >
>> > The test assembly I'm trying to load is a tiny .NET 4 console
>> > application, here is the complete source code:
>> >
>> > class Program
>> > {
>> >     [Cached]
>> >     private static string _SomeExpensiveMethod()
>> >     {
>> >         Console.WriteLine("Expensive operation...");
>> >         return "stuff";
>> >     }
>> >
>> >     [Cached]
>> >     private static StringBuilder _GetBuilder()
>> >     {
>> >         Console.WriteLine("Creating builder...");
>> >         return new StringBuilder();
>> >     }
>> >
>> >     static void Main(string[] args)
>> >     {
>> >         string r1 = _SomeExpensiveMethod();
>> >         Console.WriteLine("Res: " + r1);
>> >         string r2 = _SomeExpensiveMethod();
>> >         Console.WriteLine("Res: " + r2);
>> >
>> >         _GetBuilder();
>> >         _GetBuilder();
>> >
>> >         Console.ReadKey();
>> >     }
>> > }
>> >
>> > The only thing worth mentioning are the CachedAttributes: they are
>> > custom attributes from a project-referenced assembly.
>> > What is interesting is that when I try to run my application in the
>> > post-build event of the test project above, it works fine - I get the
>> > error when I start the application directly. At first I thought that
>> > it was some issue with relative paths, but the paths are relative in
>> > the post-build event as well.
>> >
>> > I have also seen this exception earlier when trying to open an
>> > obfuscated assembly (my test assembly is NOT obfuscated), but I
>> > thought it was because of the obfuscation. Now I'm not so sure.
>> >
>> > Mono.Cecil version 0.9.4.0, binaries only. I could download the source
>> > code, but that would mean installing git, which I'd never use
>> > afterwards, and I hate having programs lying around.
>> >
>> > Any hints?
>> > Thank you very much in advance! And thanks for this great library!
>> >
>> > --
>> > --
>> > mono-cecil
>>
>> --
>> --
>> mono-cecil
>
>
>

-- 
--
mono-cecil

Reply via email to