Hey,

It's hard to say exactly without some context. This error message is a
pretty generic one in PEverify which can mean anything from «this
token doesn't exist» to «I can't resolve the assembly in which this
type is defined».

In that case, I think peverify doesn't know what !0 is.

What's in targetMethod for this invocation? I suspect it's something
of the form:

>   IL_00bd:  ldtoken    method instance !0[] class 
> [mscorlib]System.Collections.Generic.List`1<int32>::ToArray()

As you can see in the metadata the generic arguments (here the return
type of ToArray) are not resolved in the instantiation. At runtime
you'd indeed get a int[]. In the metadata you need to resolve in the
generic context.

Jb

On Thu, Sep 4, 2014 at 6:51 AM, Philip_L <[email protected]> wrote:
> Has anyone previously run into this issue with Cecil? I tried running
> PEVerify against my modified assembly, and it gives me this output:
>
> Microsoft (R) .NET Framework PE Verifier.  Version  4.0.30319.33440
> Copyright (c) Microsoft Corporation.  All rights reserved.
>
> [IL]: Error: [...\Deflector.NET\Deflect
> or\Deflector.Tests\bin\Debug\output.dll :
> SampleLibrary.SampleClassWithConstruct
> orCall::DoSomething][mdToken=0x6000006][offset 0x00000124] Unable to resolve
> tok
> en.
> 1 Error(s) Verifying output.dll
>
> Offset 0x124 looks like this:
>
>
>   IL_0124:  ldtoken    !0[]
>   IL_0129:  call       class [mscorlib]System.Type
> [mscorlib]System.Type::GetTypeFromHandle(valuetype
> [mscorlib]System.RuntimeTypeHandle)
>
> Here's the C# code snippet that emits the IL:
>
> // Save the return type
> var getTypeFromHandle = module.Import(GetTypeFromHandle);
>
> var returnType = targetMethod.ReturnType;
> IL.Emit(OpCodes.Ldtoken, returnType);
> IL.Emit(OpCodes.Call, getTypeFromHandle);
>
> In this case, the return type is supposed to be just an array of int32s, but
> I don't know why it substitutes the !0 instead of an int array type. Is this
> the expected behavior for Cecil?
>
> Here's the complete method IL dump:
>
> .method public hidebysig instance void  DoSomething() cil managed
> {
>   .custom instance void
> [Deflector]Deflector.MethodCallsAlreadyInterceptedAttribute::.ctor() = ( 01
> 00 00 00 )
>   // Code size       353 (0x161)
>   .maxstack  7
>   .locals init (class [mscorlib]System.Collections.Generic.List`1<int32>
> V_0,
>            int32[] V_1,
>            class [System]System.Collections.Generic.Stack`1<object> V_2,
>            object V_3,
>            class [Deflector]Deflector.IInvocationInfo V_4,
>            class [Deflector]Deflector.IMethodCall V_5,
>            object V_6,
>            class [mscorlib]System.Type[] V_7,
>            class [mscorlib]System.Type[] V_8,
>            class [mscorlib]System.Reflection.MethodBase[] V_9,
>            class [mscorlib]System.Collections.Generic.IDictionary`2<class
> [mscorlib]System.Reflection.MethodBase,class
> [Deflector]Deflector.IMethodCall> V_10,
>            class [Deflector]Deflector.IMethodCallProvider V_11)
>   IL_0000:  call       class [Deflector]Deflector.IMethodCallProvider
> [Deflector]Deflector.MethodCallProviderRegistry::GetProvider()
>   IL_0005:  stloc      V_11
>   IL_0009:  newobj     instance void class
> [mscorlib]System.Collections.Concurrent.ConcurrentDictionary`2<class
> [mscorlib]System.Reflection.MethodBase,class
> [Deflector]Deflector.IMethodCall>::.ctor()
>   IL_000e:  stloc      V_10
>   IL_0012:  ldloc      V_11
>   IL_0016:  brfalse    IL_008a
>   IL_001b:  ldc.i4     0x2
>   IL_0020:  newarr     [mscorlib]System.Reflection.MethodBase
>   IL_0025:  stloc      V_9
>   IL_0029:  ldloc      V_9
>   IL_002d:  ldc.i4     0x0
>   IL_0032:  ldtoken    method instance !0[] class
> [mscorlib]System.Collections.Generic.List`1<int32>::ToArray()
>   IL_0037:  ldtoken    class
> [mscorlib]System.Collections.Generic.List`1<int32>
>   IL_003c:  call       class [mscorlib]System.Reflection.MethodBase
> [mscorlib]System.Reflection.MethodBase::GetMethodFromHandle(valuetype
> [mscorlib]System.RuntimeMethodHandle,
>
> valuetype [mscorlib]System.RuntimeTypeHandle)
>   IL_0041:  stelem.ref
>   IL_0042:  ldloc      V_9
>   IL_0046:  ldc.i4     0x1
>   IL_004b:  ldtoken    method instance void class
> [mscorlib]System.Collections.Generic.List`1<int32>::.ctor()
>   IL_0050:  ldtoken    class
> [mscorlib]System.Collections.Generic.List`1<int32>
>   IL_0055:  call       class [mscorlib]System.Reflection.MethodBase
> [mscorlib]System.Reflection.MethodBase::GetMethodFromHandle(valuetype
> [mscorlib]System.RuntimeMethodHandle,
>
> valuetype [mscorlib]System.RuntimeTypeHandle)
>   IL_005a:  stelem.ref
>   IL_005b:  ldloc      V_11
>   IL_005f:  ldloc      V_6
>   IL_0063:  ldtoken    method instance void
> SampleLibrary.SampleClassWithConstructorCall::DoSomething()
>   IL_0068:  ldtoken    SampleLibrary.SampleClassWithConstructorCall
>   IL_006d:  call       class [mscorlib]System.Reflection.MethodBase
> [mscorlib]System.Reflection.MethodBase::GetMethodFromHandle(valuetype
> [mscorlib]System.RuntimeMethodHandle,
>
> valuetype [mscorlib]System.RuntimeTypeHandle)
>   IL_0072:  ldloc      V_9
>   IL_0076:  ldloc      V_10
>   IL_007a:  ldc.i4     0x0
>   IL_007f:  ldc.i4.1
>   IL_0080:  newobj     instance void
> [mscorlib]System.Diagnostics.StackTrace::.ctor(int32,
>
> bool)
>   IL_0085:  callvirt   instance void
> [Deflector]Deflector.IMethodCallProvider::AddMethodCalls(object,
>
> class [mscorlib]System.Reflection.MethodBase,
>
> class [mscorlib]System.Collections.Generic.IEnumerable`1<class
> [mscorlib]System.Reflection.MethodBase>,
>
> class [mscorlib]System.Collections.Generic.IDictionary`2<class
> [mscorlib]System.Reflection.MethodBase,class
> [Deflector]Deflector.IMethodCall>,
>
> class [mscorlib]System.Diagnostics.StackTrace)
>   IL_008a:  nop
>   IL_008b:  nop
>   IL_008c:  newobj     instance void class
> [mscorlib]System.Collections.Generic.List`1<int32>::.ctor()
>   IL_0091:  stloc.0
>   IL_0092:  ldloc.0
>   IL_0093:  newobj     instance void class
> [System]System.Collections.Generic.Stack`1<object>::.ctor()
>   IL_0098:  stloc      V_2
>   IL_009c:  ldloc      V_10
>   IL_00a0:  ldtoken    method instance !0[] class
> [mscorlib]System.Collections.Generic.List`1<int32>::ToArray()
>   IL_00a5:  ldtoken    class
> [mscorlib]System.Collections.Generic.List`1<int32>
>   IL_00aa:  call       class [mscorlib]System.Reflection.MethodBase
> [mscorlib]System.Reflection.MethodBase::GetMethodFromHandle(valuetype
> [mscorlib]System.RuntimeMethodHandle,
>
> valuetype [mscorlib]System.RuntimeTypeHandle)
>   IL_00af:  callvirt   instance bool class
> [mscorlib]System.Collections.Generic.IDictionary`2<class
> [mscorlib]System.Reflection.MethodBase,class
> [Deflector]Deflector.IMethodCall>::ContainsKey(!0)
>   IL_00b4:  brfalse    IL_0158
>   IL_00b9:  ldloc      V_10
>   IL_00bd:  ldtoken    method instance !0[] class
> [mscorlib]System.Collections.Generic.List`1<int32>::ToArray()
>   IL_00c2:  ldtoken    class
> [mscorlib]System.Collections.Generic.List`1<int32>
>   IL_00c7:  call       class [mscorlib]System.Reflection.MethodBase
> [mscorlib]System.Reflection.MethodBase::GetMethodFromHandle(valuetype
> [mscorlib]System.RuntimeMethodHandle,
>
> valuetype [mscorlib]System.RuntimeTypeHandle)
>   IL_00cc:  callvirt   instance !1 class
> [mscorlib]System.Collections.Generic.IDictionary`2<class
> [mscorlib]System.Reflection.MethodBase,class
> [Deflector]Deflector.IMethodCall>::get_Item(!0)
>   IL_00d1:  stloc      V_5
>   IL_00d5:  ldloc      V_5
>   IL_00d9:  brfalse    IL_0158
>   IL_00de:  stloc      V_6
>   IL_00e2:  ldloc      V_6
>   IL_00e6:  ldtoken    method instance !0[] class
> [mscorlib]System.Collections.Generic.List`1<int32>::ToArray()
>   IL_00eb:  ldtoken    class
> [mscorlib]System.Collections.Generic.List`1<int32>
>   IL_00f0:  call       class [mscorlib]System.Reflection.MethodBase
> [mscorlib]System.Reflection.MethodBase::GetMethodFromHandle(valuetype
> [mscorlib]System.RuntimeMethodHandle,
>
> valuetype [mscorlib]System.RuntimeTypeHandle)
>   IL_00f5:  ldc.i4     0x0
>   IL_00fa:  ldc.i4.1
>   IL_00fb:  newobj     instance void
> [mscorlib]System.Diagnostics.StackTrace::.ctor(int32,
>
> bool)
>   IL_0100:  ldc.i4     0x0
>   IL_0105:  newarr     [mscorlib]System.Type
>   IL_010a:  stloc      V_7
>   IL_010e:  ldloc      V_7
>   IL_0112:  ldc.i4     0x0
>   IL_0117:  newarr     [mscorlib]System.Type
>   IL_011c:  stloc      V_8
>   IL_0120:  ldloc      V_8
>   IL_0124:  ldtoken    !0[]
>   IL_0129:  call       class [mscorlib]System.Type
> [mscorlib]System.Type::GetTypeFromHandle(valuetype
> [mscorlib]System.RuntimeTypeHandle)
>   IL_012e:  ldloc      V_2
>   IL_0132:  callvirt   instance !0[] class
> [System]System.Collections.Generic.Stack`1<object>::ToArray()
>   IL_0137:  newobj     instance void
> [Deflector]Deflector.InvocationInfo::.ctor(object,
>
> class [mscorlib]System.Reflection.MethodBase,
>
> class [mscorlib]System.Diagnostics.StackTrace,
>
> class [mscorlib]System.Type[],
>
> class [mscorlib]System.Type[],
>
> class [mscorlib]System.Type,
>
> object[])
>   IL_013c:  stloc      V_4
>   IL_0140:  ldloc      V_5
>   IL_0144:  ldloc      V_4
>   IL_0148:  callvirt   instance object
> [Deflector]Deflector.IMethodCall::Invoke(class
> [Deflector]Deflector.IInvocationInfo)
>   IL_014d:  unbox.any  !0[]
>   IL_0152:  ldnull
>   IL_0153:  br         IL_015e
>   IL_0158:  nop
>   IL_0159:  callvirt   instance !0[] class
> [mscorlib]System.Collections.Generic.List`1<int32>::ToArray()
>   IL_015e:  nop
>   IL_015f:  stloc.1
>   IL_0160:  ret
> } // end of method SampleClassWithConstructorCall::DoSomething
>
> --
> --
> --
> mono-cecil
> ---
> You received this message because you are subscribed to the Google Groups
> "mono-cecil" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.

-- 
-- 
--
mono-cecil
--- 
You received this message because you are subscribed to the Google Groups 
"mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to