Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to instantiate a class that is declared in a C# DLL?
    primarykey
    data
    text
    <p>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 :</p> <pre><code>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); } } } </code></pre> <p>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.</p> <p>I'm completely new in C#, by new I mean I've started less than 4 hours ago but I have a C++ background.</p> <p>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</p> <p>My test program is </p> <pre><code>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); } } </code></pre> <p>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.</p> <p>Thank you all</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload