Microsoft KB Archive/327421

= BUG: You cannot create delegates on non-virtual methods of value classes =

Article ID: 327421

Article Last Modified on 8/31/2005

-

APPLIES TO


 * Microsoft Visual Studio .NET 2002 Professional Edition

-



This article was previously published under Q327421



SYMPTOMS
When you try to create a delegate on a non-virtual method of a value class, you receive the following System.NotSupportedException error message in the common language runtime:

Unhandled Exception: System.NotSupportedException: Delegates on value classes can only be formed on virtual methods

at MyDel..ctor(Object object, IntPtr method)

at M.Main in c:\test\class1.cs:line 27



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
Compile and run the following code to reproduce the problem: using System;

public struct Pair {   string a;     int b;    public Pair(string av, int bv) {       a = av; b = bv; }   public string Fst {       return a;    } public int Snd {       return b;    } }

public delegate string MyDel;

class M { public static void Main {       Pair p = new Pair(&quot;hello&quot;, 59); Console.WriteLine(p.Fst); MyDel d = new MyDel(p.Fst); Console.WriteLine(d); } }

Additional query words: NotSupportedException

Keywords: kbbug kbvs2002sp1sweep KB327421

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.