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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:09:44+00:00 2026-05-30T12:09:44+00:00

I have a DLL written in C#. In this DLL there is a class

  • 0

I have a DLL written in C#. In this DLL there is a class that is defined.
Let’s assume that the code of this DLL is :

namespace unloadableDLL
{
    public class DivisionClass
    {
        public /*static*/ long Division(long x, long y)
        {
            // We deliberately do not use a try catch to catch divide by 0 exceptions
            return (x / y);
        }
    }
}

Now, I want to load dynamically this DLL in a test program. I need to see what happens if I divide by zero in the two following cases :
1) DLL is loaded directly (without using an AppDomain)
2) DLL is not loaded directly, an AppDomain is created first and then it loads the DLL.

I’m completely new in C#, by new I mean I’ve started less than 4 hours ago but I have a C++ background.

My problem is that in my test program, I need to instanciate a DivisionClass Object but this one is declared only in the DLL.
=> Resolved

My test program is

class Program
    {
        [PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
        static void Main(string[] args)
        {
            // Load the DLL
            Console.WriteLine("Attempting to load unloadableDLL");
            Assembly a = Assembly.LoadFrom("./unloadableDLL.dll");
            unloadableDLL.DivisionClass divisionObject = (unloadableDLL.DivisionClass)a.CreateInstance("unloadableDLL.DivisionClass");
            long number = divisionObject.Division(8, 2);
            Console.WriteLine(number);
        }
    }

I don’t know what but the compilers keeps telling me that Static member unloadableDLL.DivisionClass.Division(lon, long) cannot be accessed with an instance reference; qualify it with a typename instead.

Thank you all

  • 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-30T12:09:46+00:00Added an answer on May 30, 2026 at 12:09 pm

    To load into a separate AppDomain an execute the method from there – use reflection as in the following StackOverflow question. It does get involved as is typically a more advanced C# topic but the code is fairly boilerplate and for a man with C++ knowledge it shouldn’t present problems.

    For a direct call then follow the methods outlined above – i.e. reference the dll in your project and instantiate through code as per Oded (who has deleted his answer unfortunately so reproducing below)

    DivisionClass.Division(1, 2)
    

    EDIT

    If the methods are not static

    Invoking a method via reflection

      Assembly myAssembly1 = Assembly.LoadFrom("myPath\\Assembly1.dll");     
      Type myType = myAssembly1.GetType("MyClass");      
      object myObject = Activator.CreateInstance(myType);     
      myType.Invoke("myMethodName", BindingFlags.InvokeMethod, null, myObject, null); 
    

    In a separate App Domain adds to the complexity – see link.

    Also I don’t think your Division class will work as is. To call across app domains you need to employ some kind of serialisation for your classes or inherit the class from MarshalByRefObject – see this SO question. Given that this looks like a proof of concept type of thing/a ground up implementation of your class then MarshalByRefObject would be you best bet – easiest i think. That said executing across AppDomains can get fiddly.

    Invoking a method via instaniation in code

    DivisionClass divisor = new DivisionClass()
    divisor.Division(1,2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have written all the code in a silverlight class library (dll) and linked this
I have a test suite DLL written in C# that uses Selenium.This is then
I have a dll written by someone else and that has many flaws. Let's
I have a dll that was written in c++, I need to use this
I have written a class dll in Net that I have to expose to
I have a DLL that is written in C++ and I want to suppress
I have a very simple DLL written in unmanaged C++ that I access from
I have an application written in PHP that uses a COM dll written in
I have a DLL, written in XE2 that takes a PChar as a parameter
I have written a C# class library (DLL) and wondering the quickest way to

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.