.comment-link {margin-left:.6em;}


.. Hello Earthling .. \o/ :)

Delegates to Value Type Members in Rotor 1.0
Friday, October 14, 2005

In rotor 1.0, you cannot call a value type's struct method through a delegate. This is a restriction in v1.0 of the .net framework that was removed from the later versions. For example, if you compile and execute the following code:

using System;
namespace intro

struct mystruct
public void valuetypemethod()
Console.WriteLine("method called from delegate.");

class CMain
public delegate void dlgassign ();
public static void Main()
mystruct at = new mystruct();
dlgassign fnptr = new dlgassign ( at.valuetypemethod );
fnptr ();

It'll give you the following error:
Unhandled Exception: System.NotSupportedException: Delegates on value classes can only be formed on virtual methods
at System.Delegate.NeverCallThis(Object target, IntPtr slot)
at intro.CMain.Main()
If you look at where it is raised, you'll come to \sscli\clr\src\vm\comdelegate.cpp COMDelegate::DelegateConstruct which is declared as

// This is the single constructor for all Delegates. The compiler
// doesn't provide an implementation of the Delegate constructor. We
// provide that implementation through an ECall call to this method.
ReflectBaseObject* refThisUNSAFE,
Object* targetUNSAFE,
SLOT method)
The following code raises the error:
pMeth = pTarg->GetUnboxingMethodDescForValueClassMethod(pMeth);
if (pMeth == NULL) COMPlusThrow(kNotSupportedException,

if you comment the line:
pMeth = pTarg->GetUnboxingMethodDescForValueClassMethod(pMeth);

and than build corlibs again, it fixes the error. To quickly rebuild the sscli with this change, goto \sscli\clr\src\vm and type "build -c". Once the build is complete, goto \sscli\clr\src and type "build" (without -c option) and press enter. This will build the sscli with your changes. Now try running the above application again (you do not need to the compile the exe again with csc because the error was generated by the vm and we just built it again). It'll give the following message:
method called from delegate.

Now you can have delegates to value type's methods and call them too.

Nice blog. Have you seen your google rating? BlogFlux It's Free and you can add a Little Script to your site that will tell everyone your ranking. I think yours was a 3. I guess you'll have to check it out.

In the news today.

Congress and the Bush administration want seriously degrade organic standards. The word organic will no longer carry
any value if we let them.

Stop the Sneak Attack in Congress on Organic Standards

Congress will vote on this issue soon!

Use below link, read more and then use link within this
article to send email to your Congresspersons.


Informative blog. Check out my gnome kde blog.
Now you could find Classes for a multitude of subjects on your area , like auto cad online class and they could be found by visiting auto cad online class
Calling ALL Affiliates!!
Now here is the deal of the month. Hurry ....only 24 places left for the Affiliate Bootbamp at FX Networking
comment spam SUCKS yaar.........
Sure man it does.
Post a Comment

Links to this post:

Create a Link

<< Home


MSDN Blogs
Joel Pobar
Don Syme

Muhammad Ali
Lahore Food Blog

Tech Blog



June 2004   July 2004   August 2004   September 2004   October 2004   November 2004   December 2004   February 2005   April 2005   June 2005   July 2005   September 2005   October 2005   November 2005   June 2007   December 2007   January 2008   March 2008   April 2008   June 2008   October 2008   February 2009   May 2009   June 2009   July 2009   August 2009   March 2011   June 2011   July 2011   September 2011   October 2011   November 2011   December 2012   May 2013   October 2013   May 2014   March 2015   July 2015   August 2015   December 2015   March 2016   July 2016   October 2016   November 2016   July 2017   December 2017   May 2018  

This page is powered by Blogger. Isn't yours?