473,698 Members | 2,404 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 8404
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
3263
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
8674
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8895
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7728
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4369
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.