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 1076063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:21:31+00:00 2026-05-16T21:21:31+00:00

I am developing a C# .NET 2.0 application wherein at run-time one of two

  • 0

I am developing a C# .NET 2.0 application wherein at run-time one of two DLLs are loaded depending on the environment. Both DLLs contain the same functions, but they are not linked to the same address-offset. My question is regarding the function delegates in my application code.

public class MyClass
{
    public delegate int MyFunctionDelegate(int _some, string _args);

    public MyFunctionDelegate MyFuncToCallFrmApp;

    public MyClass() : base()
    {
        this.MyFuncToCallFrmApp = new MyFunctionDelegate(this.MyFuncToCallFrmApp); // <-- Exception thrown here.
    }

    public SomeFunction()
    {
        MyFuncToCallFrmApp(int _someOther, string _argsLocal);
    }
}

When my code executes I get an ArgumentException of “Delegate to an instance method cannot have null ‘this’.” What am I doing wrong?

  • 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-05-16T21:21:32+00:00Added an answer on May 16, 2026 at 9:21 pm

    You need to assign a valid function (hosted by some class in the dynamically loaded dll) to your delegate variable. If the functions are static methods on classes with the same name, this is straightforward:

    public MyClass() {
        this.MyFuncToCallFrmApp = ExternalClass.Function;
    }
    

    If the functions are instance methods of classes with the same name, just create an instance and do the same thing (also note that as long as the delegate is in scope, it will prevent the ExternalClass instance from being garbage-collected – you may want to store the instance as a member variable to make that clearer):

    public MyClass() {
        this.MyFuncToCallFrmApp = new ExternalClass().Function;
    }
    

    If the dynamically-loaded classes have different names, you’ll need to determine which one to call – in this example, I’m using a boolean member variable to decide whether or not to use a default assembly’s class:

    public MyClass() {
        if (this.defaultAssembly) {
            this.MyFuncToCallFrmApp = ExternalClass1.Function;
        } else {
            this.MyFuncToCallFrmApp = ExternalClass2.Function;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a C# .NET 2.0 application wherein I need to scan for
The ASP.NET web application I am developing needs to support two different types of
I'm developing an in-house .NET application that will be run on a VM (with
I developing ASP.NET application using a Swedish version of Windows XP and Visual studio
I am developing an .net application which heavely depends on plugins. The application itself
Developing a .NET WinForms application: how can I check if the window is in
I am developing a Windows .NET application (WinForms) and I need to simulate a
I am developing an ASP.NET MVC application and I want to use OpenId. What
We are developing a .NET 2.0 winform application. The application needs to access Web
I'm developing a WinForms application (.Net 3.5, no WPF) where I want to be

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.