473,564 Members | 2,730 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Activator.Creat eInstanceFrom

If I wanted to create an instance of a System.Windows. Forms.Button how would
I go about doing this? I know if I specify the path to the DLL as the first
param, and the qualified name as the second all works well, but the DLL is
in the gac, is there any way to get Activator.Creat eInstanceFrom to use the
GAC to find the DLL? and if so how do you specify the version? (or is that
why you wouldn't be able to use the gac?)

--
Thanks
Wayne Sepega
Jacksonville, Fl
"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein
Nov 16 '05 #1
3 8393
First of, if you wanted to create a System.Windows. Forms.Button
instance you just new it up like:

System.Windows. Forms.Button btn = new System.Windows. Forms.Button();

Soecondly, Activator.Creat eXXXX is used for late binding calls. One way
you can create instances from GAC assemblies is to first load the
assemly and then call create instance. For ex:

Assembly assm = Assembly.Load ("MyAssembly , Version=1.0.0.0 ,
Culture=neutral , PublicKeyToken=[something]");
MyType type = (MyType) assm.CreateInst ance ("MyAssembly.My Type");

That will automatically probe the GAC to check for the MyAssembly
assembly.

You could also use Activator.Creat eInstance function and specify the
assembly and type name. For GAC assemblies i dont think
CreateInstanceF rom will work.

NuTcAsE

Nov 16 '05 #2
Hi,

Just add
using System.Windows. Form;

you should have it already , but just in case.

you only use Activator to load a type at runtime, usually when you do not
know the real type at compile time, so you wait until runtime to decide
which exact typoe you want ot use.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Wayne" <Me******@commu nity.nospam> wrote in message
news:uT******** ******@TK2MSFTN GP14.phx.gbl...
If I wanted to create an instance of a System.Windows. Forms.Button how
would
I go about doing this? I know if I specify the path to the DLL as the
first
param, and the qualified name as the second all works well, but the DLL is
in the gac, is there any way to get Activator.Creat eInstanceFrom to use
the
GAC to find the DLL? and if so how do you specify the version? (or is that
why you wouldn't be able to use the gac?)

--
Thanks
Wayne Sepega
Jacksonville, Fl
"When a man sits with a pretty girl for an hour, it seems like a minute.
But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein

Nov 16 '05 #3
Thank you, that worked perfectly (once I figured out where to get the public
token).

BTW, the System.Windows. Forms.Button was just an example, I plan on using
this with my own assemblies. Also since it was already in the gac I figured
it simpler to test with instead of having to first create the assembly
strong name it and then put it in the GAC.
"NuTcAsE" <ra********@gma il.com> wrote in message
news:11******** **************@ c13g2000cwb.goo glegroups.com.. .
First of, if you wanted to create a System.Windows. Forms.Button
instance you just new it up like:

System.Windows. Forms.Button btn = new System.Windows. Forms.Button();

Soecondly, Activator.Creat eXXXX is used for late binding calls. One way
you can create instances from GAC assemblies is to first load the
assemly and then call create instance. For ex:

Assembly assm = Assembly.Load ("MyAssembly , Version=1.0.0.0 ,
Culture=neutral , PublicKeyToken=[something]");
MyType type = (MyType) assm.CreateInst ance ("MyAssembly.My Type");

That will automatically probe the GAC to check for the MyAssembly
assembly.

You could also use Activator.Creat eInstance function and specify the
assembly and type name. For GAC assemblies i dont think
CreateInstanceF rom will work.

NuTcAsE

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3241
by: CKR Rajesh | last post by:
Hi, I have 2 dlls on which i have the same class MyClass defined. Say A.dll and B.dll The classes have a function (but different functionality) void f(); I use .Net late binding using Activator.CreateInstanceFrom method to dynamically call the method f() in either dll.
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7644
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2083
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.