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