What I have now (which successfully loads the plug-in) is this:
Assembly myDLL = Assembly.LoadFrom("my.dll");
IMyClass myPluginObject = myDLL.CreateInstance("MyCorp.IMyClass") as IMyClass;
This only works for a class that has a constructor with no arguments. How do I pass in an argument to a constructor?
...
I am trying to create an instance of a COM object. I have the class name that implements the interface and I get a CLSID by using CLSIDFromProgID(). So since I am getting a CLSID I thought everything should be fine from now on. However when I do a call to CreateInstance and pass in the CLSID, I get an error saying "Class not registered"....
After much help from all my StackOverFlow brethren, I managed to create a C++ DLL that calls my C# classes via COM and passes data back and forth to an external application. There was much celebration in the kingdom after that code started working.
Now I have a new problem. I'm expanding the DLL so that it can call different classes (al...
I have a website that on user-demand compiles a class on the fly and deposits the dll(named Equation.dll) in a subdirectory of the website. The administrator can recompile at any time. However, once an instance of the class has been created, the message "The process cannot access the file because it is being used by another process" is...
I am trying to create an instance of a typed dataset dynamically in my code at runtime. I have the type available to me, but when I try to do this:
object obj = Activator.CreateInstance(Type.GetType("TYPED DATASET TYPE HERE"));
The problem is the type doesn't seem to be valid according to the code when I try and run it. What could I b...
I am using (a slightly extended version of) the following code in a factory-pattern style function:
public class SingleItemNew : CheckoutContext
{
public BookingContext Data { get; set; }
public SingleItemNew(BookingContext data)
{
Data = data;
}
}
public CheckoutContext findContext(BookingContext...
I need a performance enhanced Activator.CreateInstance() and came across this article by Miron Abramson that uses a factory to create the instance in IL and then cache it. (I've included code below from Miron Abramson's site in case it somehow disappears). I'm new to IL Emit code and anything beyond Activator.CreateInstance() for instant...
My scenario is that I have a .net application (let's say a Console App) that creates AppDomains. It then needs to create instances and call methods on Types that are in that AppDomain. Each AppDomain has a specific directory where are it's dependecies should be, which is not under (or even near) the Console Apps directory. Here's my s...
Using the CreateInstance method of the TypeConverter class, it's possible to edit the properties of an immutable object - such as a font.
However, unlike the font class, there's some properties in my class that i'd like to be browsable but readonly - even though CreateInstance is supported.
Is there an attribute that supports this?
ET...
According to How the Runtime Locates Assemblies step 2 is Checking for Previously Referenced Assemblies.
However, in the code below you can see that this is definitely not happening. In the first line, an assembly is loaded (which should make it a "previously referenced assembly" for all future calls.)
However, a couple lines later wh...
Hi guys
I want to create an instance of a type that I specify in a generic method that I have. This type has a number of overloaded constructors. I'd like to be able to pass arguments to the constructors, but
Activator.CreateInstance<T>()
doesn't see to have this as an option.
Is there another way to do it?
Thanks
Dave
...
Hi,
I have my custom class Customer with its properties. I added DataContract mark above the class and DataMember to properties and it was working fine, but I'm calling a service class's function, passing customer instance as parameter and some of my properties get 0 values.
While debugging I can see my properties values and after it g...
What is the difference between Activator.CreateInstance and factory? Can they be used interchangeably? Or stil do we need a factory pattern?
...
Help, here is the idea:
External.dll
IMyClass NewCreated = (IMyClass)Activator.CreateInstance(Namespace.MyClass).UnWrap();
Asp.Net WebSite
App_Code
Namespace.MyClass.cs
Bin
External.dll
Is that even posible?
I have tried, a lot of posible combinations, like:
Assembly.GetCallingAssembly().CreateInstance("Namespa...
I'm using the following code to access the Windows Explorer Shell's band site service:
Guid GUID_TrayBandSiteService = new Guid(0xF60AD0A0, 0xE5E1, 0x45cb, 0xB5, 0x1A, 0xE1, 0x5B, 0x9F, 0x8B, 0x29, 0x34);
Type shellTrayBandSiteService = Type.GetTypeFromCLSID(GUID_TrayBandSiteService, true);
site = Activator.CreateInstance(shellTrayBandS...
I have an F# program that creates an instance of Visual Studio:
let vsTy = Type.GetTypeFromProgID("VisualStudio.DTE.10.0") in
let dte2 = Activator.CreateInstance(vsTy,true) :?> EnvDTE80.DTE2 in
...
That works well; I can probe all kinds of info about the running instance
of Visual Studio.
But I can't determine how to load a s...
My Application is created in Vc++ and from the exe I try to load a Excel plugin which is created in C# . I communicate with Excel Plugin by using CreateInstance . But after doing 2 or 3 communications . Create Instance crashes on checking the Event Viewer I am getting these entries
1) .NET Runtime version 2.0.50727.4206 - Fatal Execut...