On 1/5/09, Daniel Cazzulino <[email protected]> wrote:
> fixed!

Cool!

> [Fact]
> public void CecilRepro()
> {
>  var asm =
> AssemblyFactory.GetAssembly(this.GetType().Assembly.Location);
>  var listOfObject =
> asm.MainModule.Import(typeof(List<object>));
>  var method = asm.MainModule.Types.Cast<TypeDefinition>()
>  .Where(t => t.FullName == this.GetType().FullName)
>  .Single()
>  .Methods.Cast<MethodDefinition>()
>  .Where(m => m.Name == "CecilRepro")
>  .Single();
>
>  var il = method.Body.CilWorker;
>  var argsVar = new VariableDefinition(listOfObject);
>  method.Body.Variables.Add(argsVar);
>  il.InsertBefore(method.Body.Instructions[0],
>  il.Create(OpCodes.Newobj, listOfObject));
> }
>
> fails with:
>
> TestCase
> 'Moq.Tests.Instrumentation.InstrumentationFixture.FailsToImport'
> failed: System.ArgumentException : opcode
>  at Mono.Cecil.Cil.CilWorker.Create(OpCode opcode,
> TypeReference type)
> D:\Code\moq\UnitTests\Instrumentation\InstrumentationFixture.cs(49,0):
> at
> Moq.Tests.Instrumentation.InstrumentationFixture.FailsToImport()

That's because newobj wants a MethodReference that should be the
actual constructor, not the type.

What if you pass the result of the Import of the constructor of
List<object> to newobj?

-- 
Jb Evain  <[email protected]>

--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---

Reply via email to