I would agree with you here Fabian, put up a link to connect and I
will vote for it.

Cheers,

Greg

On 8/1/07, Fabian Schmied <[EMAIL PROTECTED]> wrote:
> I've been pointed to something strange I'd like to confirm as a bug
> before reporting it on MS Connect: when using the ldtoken IL
> instruction on a method token in a specific scenario, I get
> unverifiable code, although a callvirt instruction on the same method
> token is verifiable.
>
> Consider the following program (C#; IL should be attached to this
> message if the list lets it through):
>
> using System;
> using System.Collections.Generic;
>
> class Program
> {
>   static void Main ()
>   {
>     new Implementer ().GenericTestMethod (new List<string> ());
>   }
> }
>
> public interface GenericTestInterface<T> where T : IEnumerable<string>
> {
>   string GenericTestMethod<T2> (T2 obj) where T2 : T;
> }
>
> public class Implementer : GenericTestInterface<List<string>>
> {
>   public string GenericTestMethod<T2> (T2 obj) where T2: List<string>
>   {
>     GenericTestInterface<List<string>> ifc = this;
>     return ifc.GenericTestMethod<T2> (null);
>   }
> }
>
> When compiling and disassembling this program,
> Implementer.GenericTestMethod contains the following IL code (line
> 108):
>
> IL_000d:  callvirt   instance string class
> GenericTestInterface`1<class
> [mscorlib]System.Collections.Generic.List`1<string>>::GenericTestMethod<!!0>(!!0)
>
> This is verifiable and works without any problems (i.e. running the
> program yields a StackOverflowException, as expected).
>
> Now add a ldtoken instruction for the same method:
>
> IL_000d:  callvirt          instance string class
> GenericTestInterface`1<class
> [mscorlib]System.Collections.Generic.List`1<string>>::GenericTestMethod<!!0>(!!0)
>           ldtoken    method instance string class
> GenericTestInterface`1<class
> [mscorlib]System.Collections.Generic.List`1<string>>::GenericTestMethod<!!0>(!!0)
>           pop
>
> This will lead to a verification error:
>
> [IL]: Error: [C:\Documents and
> Settings\fabian.schmied\Desktop\Temp\ConsoleApplication19\ConsoleApplication19\bin\Debug\test.exe
> : Implementer::GenericTestMethod[T2]][offset 0x00000012][token
> 0x2B000001]System.Security.VerificationException: Method
> GenericTestInterface`1[System.Collections.Generic.List`1[System.String]].GenericTestMethod:
> type argument 'T2' violates the constraint of type parameter 'T2'.
> [HRESULT 0x8013150D]
>
> I don't believe this error is correct. First, the implementer's T2
> doesn't violate the constraint of the interface's T2. Second, if I can
> use a callvirt on the token, I should also be able to use ldtoken on
> it, right? (ILDASM's "Show token values"/"Show bytes" options confirm
> that the same token is used in both instructions.)
>
> Any thoughts on this?
>
> Fabian
>
> ===================================
> This list is hosted by DevelopMentor(r)  http://www.develop.com
>
> View archives and manage your subscription(s) at http://discuss.develop.com
>
>


--
Studying for the Turing test

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to