Hi,
I need help to workaround the following scenario - a null reference
when attempting to write an assembly that is written in cpp.
how to reproduce:
- In VStudio2010 create a .Net assembly by choosing Visual C++\CLR
\Class Library. Build
  - I've added an empty method that accepts an int by it maybe
redundant
- Run the following code:
            string fileName = @"c:\dev\examples\cecil
\InjectCodeToAssembly\CallAndInjectApp\bin\Debug\UnsafeLib.dll";
            AssemblyDefinition assemblyDefinition =
AssemblyDefinition.ReadAssembly(fileName, new
ReaderParameters{ReadingMode =ReadingMode.Immediate});
            assemblyDefinition.MainModule.Attributes=
ModuleAttributes.ILOnly;
            assemblyDefinition.Write(fileName);

You hit the following exception:
System.ArgumentException occurred
  Message=Value does not fall within the expected range.
  Source=Mono.Cecil
  StackTrace:
       at Mono.Cecil.MetadataBuilder.AddPInvokeInfo(MethodDefinition
method) in c:\Dev\examples\cecil\CeCil_Sources\jbevain-
cecil-2a65765\Mono.Cecil\AssemblyWriter.cs:line 1461

It hits the ArgumentException here
        void AddPInvokeInfo (MethodDefinition method)
                {
                        var pinvoke = method.PInvokeInfo;
                        if (pinvoke == null)
                                throw new ArgumentException ();


Thanks, Gad

-- 
--
mono-cecil

Reply via email to