Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8787671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:56:54+00:00 2026-06-13T21:56:54+00:00

I am trying to convert from a generic delegate to a named delegate. With

  • 0

I am trying to convert from a generic delegate to a named delegate.

With the result being in spirit of the following (not valid C#):

Action<CustomClass> act = ???;
CustomDelegate d = act;

I have tried

CustomDelegate d = act.Invoke;
CustomDelegate d = new CustomDelegate( act );
CustomDelegate d = new CustomDelegate( x => act(x) );
CustomDelegate d = new CustomDelegate( act.Invoke );

All of which fail at run time giving an ArgumentException with the error

Delegate to an instance method cannot have null ‘this’.

The top of the stack which is not my code is:

at System.MulticastDelegate.ThrowNullThisInDelegateToInstance()

at System.MulticastDelegate.CtorClosed(object target, IntPtr methodPtr)

How to I convert a delegate such that I do not get an exception?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:56:55+00:00Added an answer on June 13, 2026 at 9:56 pm

    I ultimately found the answer by trying @DiegoMijelshon’s solution for a question on casting delegates. With that solution I got a NullReferenceException instead of the ArgumentException. Thus I found the issue was because the Action<> I had was null (it was a parameter). Thus, a null check such as the following fixed my issue.

    CustomDelegate d = adt == null ? null : act.Invoke;
    // Though, I actually went with @DiegoMijelshon solution to avoid extra indirection.
    

    I then went and looked with reflector (which I should have done sooner) and found that it is indeed a null check on the parameter that causes ThrowNullThisInDelegateToInstance to be called.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert a date from yyyy-mm-dd to dd-mm-yyyy (but not in
I'm trying to convert my rubyonrails project from sqlite3 to MySQL by following: Convert
There is some code that I'm trying to convert from IList to IEnumerable :
Trying to convert output from a rest_client GET to the characters that are represented
I'm trying to convert an animation from cocos2d to cocos2d-x but to no avail.
I'm trying to convert my site from using tables to just using css and
I am trying to convert some pages from my app to use cfc's, and
I'm trying to convert some code from Richfaces 4 showcase to use CDI instead
I am new to JAVA, I am trying to convert an input from a
I'm trying to convert a series of bytes from hex to bin using bash.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.