473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Activator.CreateInstanceFrom

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.CreateInstanceFrom 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 8389
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.CreateXXXX 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.CreateInstance ("MyAssembly.MyType");

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

You could also use Activator.CreateInstance function and specify the
assembly and type name. For GAC assemblies i dont think
CreateInstanceFrom 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******@community.nospam> wrote in message
news:uT**************@TK2MSFTNGP14.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.CreateInstanceFrom 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********@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.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.CreateXXXX 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.CreateInstance ("MyAssembly.MyType");

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

You could also use Activator.CreateInstance function and specify the
assembly and type name. For GAC assemblies i dont think
CreateInstanceFrom 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
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.