The Assembly provides GetTypes() for retrieving the defined type, is there a
way to add my type dynamically?
Thank you very much! 7 1616
Hi,
Any types (classes, structs enums etc.) you define in the Assembly are
automatically part of that Assembly and accessable through reflection.
Hope this helps
Chris Taylor
"ZhangZQ" <zh*******@hotmail.com> wrote in message
news:e6***************@TK2MSFTNGP10.phx.gbl... The Assembly provides GetTypes() for retrieving the defined type, is there
a way to add my type dynamically?
Thank you very much!
"ZhangZQ" <zh*******@hotmail.com> wrote in
news:e6*************@TK2MSFTNGP10.phx.gbl: The Assembly provides GetTypes() for retrieving the defined type, is there a way to add my type dynamically?
You can create Types dynamically with System.Reflection.Emit
Greets
Peter
--
------ooo---OOO---ooo------
Peter Koen - www.kema.at
MCAD CAI/RS CASE/RS IAT
------ooo---OOO---ooo------
Chris Taylor,
Thank you.
Yes, that is what I have to do. But I want to know if it is possible to add
another assembly into current running assembly? then I can refer that data
type in current running assembly.
Thanks.
"Chris Taylor" <ch*************@hotmail.com> wrote in message
news:Ov**************@TK2MSFTNGP09.phx.gbl... Hi,
You can use an appropriate overload of Activator.CreateInstance() or you could use Assembly.Load() to load the Assembly and then use
GetType/GetTypes and use reflection from there.
Hope this helps
Chris Taylor
"ZhangZQ" <zh*******@hotmail.com> wrote in message news:OH*************@tk2msftngp13.phx.gbl... Peter,
Thanks.
My question is, supposing I defined a type(MyAssembly.MyType) in an assembly call MyAssembly.dll, if I don't refer it in compile time, I want to load it from runtime, how can I do that?
Thanks
"Peter Koen" <koen-newsreply&snusnu.at> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... "ZhangZQ" <zh*******@hotmail.com> wrote in news:e6*************@TK2MSFTNGP10.phx.gbl:
> The Assembly provides GetTypes() for retrieving the defined type, is > there a way to add my type dynamically?
You can create Types dynamically with System.Reflection.Emit
Greets Peter
-- ------ooo---OOO---ooo------
Peter Koen - www.kema.at MCAD CAI/RS CASE/RS IAT
------ooo---OOO---ooo------
Hi,
Please forgive me if I am not understanding you correctly. The current
running Assembly can use a public type in another Assembly by using either
Activator.CreateInstance() of Assembly.Load().
Regards
Chris Taylor
"ZhangZQ" <zh*******@hotmail.com> wrote in message
news:en**************@TK2MSFTNGP09.phx.gbl... Chris Taylor,
Thank you.
Yes, that is what I have to do. But I want to know if it is possible to
add another assembly into current running assembly? then I can refer that data type in current running assembly.
Thanks. "Chris Taylor" <ch*************@hotmail.com> wrote in message news:Ov**************@TK2MSFTNGP09.phx.gbl... Hi,
You can use an appropriate overload of Activator.CreateInstance() or you could use Assembly.Load() to load the Assembly and then use GetType/GetTypes and use reflection from there.
Hope this helps
Chris Taylor
"ZhangZQ" <zh*******@hotmail.com> wrote in message news:OH*************@tk2msftngp13.phx.gbl... Peter,
Thanks.
My question is, supposing I defined a type(MyAssembly.MyType) in an assembly call MyAssembly.dll, if I don't refer it in compile time, I want to
load it from runtime, how can I do that?
Thanks
"Peter Koen" <koen-newsreply&snusnu.at> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... > "ZhangZQ" <zh*******@hotmail.com> wrote in > news:e6*************@TK2MSFTNGP10.phx.gbl: > > > The Assembly provides GetTypes() for retrieving the defined type,
is > > there a way to add my type dynamically? > > > You can create Types dynamically with System.Reflection.Emit > > Greets > Peter > > -- > ------ooo---OOO---ooo------ > > Peter Koen - www.kema.at > MCAD CAI/RS CASE/RS IAT > > ------ooo---OOO---ooo------
Dear Chris Taylor,
I tried this, supposing I used VC++ to create an OCX call MyOCX, and there
is a object in the OCX call MyObject. I used the AxImp.exe to generate the
proxy assembly call MyOCXLib.dll. Now in my code
Assembly myAssembly = Assembly.LoadFrom("MyOCXLib.dll");
Type myObjType = myAssembly.GetType("MyOCXLib.MyObject");
MyOCXLib.MyObject myObj =
(MyOCXLib.MyObject)Activator.CreateInstance(myObjT ype);
// the above line will cause an exception to be thorwn with error message
"specified cast in invalid"
// If I change to the following line
MyOCXLib.MyObject myObj =
(MyOCXLib.MyObject)Activator.CreateInstance(typeof (MyOCXLib.MyObject));
// then it is ok.
that is the problem. do you know why? I think the MyOCXLib.MyObject type
does not exist in the current Assembly. What do you think?
Regards,
ZhangZQ
"Chris Taylor" <ch*************@hotmail.com> wrote in message
news:OK**************@TK2MSFTNGP09.phx.gbl... Hi,
Please forgive me if I am not understanding you correctly. The current running Assembly can use a public type in another Assembly by using either Activator.CreateInstance() of Assembly.Load().
Regards
Chris Taylor "ZhangZQ" <zh*******@hotmail.com> wrote in message news:en**************@TK2MSFTNGP09.phx.gbl... Chris Taylor,
Thank you.
Yes, that is what I have to do. But I want to know if it is possible to add another assembly into current running assembly? then I can refer that
data type in current running assembly.
Thanks. "Chris Taylor" <ch*************@hotmail.com> wrote in message news:Ov**************@TK2MSFTNGP09.phx.gbl... Hi,
You can use an appropriate overload of Activator.CreateInstance() or
you could use Assembly.Load() to load the Assembly and then use GetType/GetTypes and use reflection from there.
Hope this helps
Chris Taylor
"ZhangZQ" <zh*******@hotmail.com> wrote in message news:OH*************@tk2msftngp13.phx.gbl... > Peter, > > Thanks. > > My question is, supposing I defined a type(MyAssembly.MyType) in an assembly > call MyAssembly.dll, if I don't refer it in compile time, I want to load it > from runtime, how can I do that? > > > Thanks > > "Peter Koen" <koen-newsreply&snusnu.at> wrote in message > news:%2****************@TK2MSFTNGP09.phx.gbl... > > "ZhangZQ" <zh*******@hotmail.com> wrote in > > news:e6*************@TK2MSFTNGP10.phx.gbl: > > > > > The Assembly provides GetTypes() for retrieving the defined
type, is > > > there a way to add my type dynamically? > > > > > > You can create Types dynamically with System.Reflection.Emit > > > > Greets > > Peter > > > > -- > > ------ooo---OOO---ooo------ > > > > Peter Koen - www.kema.at > > MCAD CAI/RS CASE/RS IAT > > > > ------ooo---OOO---ooo------ > >
Hi,
You do not need to use Assembly.LoadFrom and Activator.Create..., I gave
both as an alternative.
Try the following.
MyOCXLib.MyObject myObj = (MyOCXLib.MyObject)Activator.CreateInstance(
"MyOCXLib.dll", "MyOCXLib.MyObject" );
I did not test this so excuse any typos.
Hope this helps
Chris Taylor
"ZhangZQ" <zh*******@hotmail.com> wrote in message
news:eg**************@TK2MSFTNGP09.phx.gbl... Dear Chris Taylor,
I tried this, supposing I used VC++ to create an OCX call MyOCX, and there is a object in the OCX call MyObject. I used the AxImp.exe to generate the proxy assembly call MyOCXLib.dll. Now in my code
Assembly myAssembly = Assembly.LoadFrom("MyOCXLib.dll"); Type myObjType = myAssembly.GetType("MyOCXLib.MyObject");
MyOCXLib.MyObject myObj = (MyOCXLib.MyObject)Activator.CreateInstance(myObjT ype); // the above line will cause an exception to be thorwn with error message "specified cast in invalid" // If I change to the following line MyOCXLib.MyObject myObj = (MyOCXLib.MyObject)Activator.CreateInstance(typeof (MyOCXLib.MyObject)); // then it is ok.
that is the problem. do you know why? I think the MyOCXLib.MyObject type does not exist in the current Assembly. What do you think?
Regards,
ZhangZQ "Chris Taylor" <ch*************@hotmail.com> wrote in message news:OK**************@TK2MSFTNGP09.phx.gbl... Hi,
Please forgive me if I am not understanding you correctly. The current running Assembly can use a public type in another Assembly by using
either Activator.CreateInstance() of Assembly.Load().
Regards
Chris Taylor "ZhangZQ" <zh*******@hotmail.com> wrote in message news:en**************@TK2MSFTNGP09.phx.gbl... Chris Taylor,
Thank you.
Yes, that is what I have to do. But I want to know if it is possible
to add another assembly into current running assembly? then I can refer that data type in current running assembly.
Thanks. "Chris Taylor" <ch*************@hotmail.com> wrote in message news:Ov**************@TK2MSFTNGP09.phx.gbl... > Hi, > > You can use an appropriate overload of Activator.CreateInstance() or you > could use Assembly.Load() to load the Assembly and then use GetType/GetTypes > and use reflection from there. > > Hope this helps > > Chris Taylor > > "ZhangZQ" <zh*******@hotmail.com> wrote in message > news:OH*************@tk2msftngp13.phx.gbl... > > Peter, > > > > Thanks. > > > > My question is, supposing I defined a type(MyAssembly.MyType) in
an > assembly > > call MyAssembly.dll, if I don't refer it in compile time, I want
to load > it > > from runtime, how can I do that? > > > > > > Thanks > > > > "Peter Koen" <koen-newsreply&snusnu.at> wrote in message > > news:%2****************@TK2MSFTNGP09.phx.gbl... > > > "ZhangZQ" <zh*******@hotmail.com> wrote in > > > news:e6*************@TK2MSFTNGP10.phx.gbl: > > > > > > > The Assembly provides GetTypes() for retrieving the defined type, is > > > > there a way to add my type dynamically? > > > > > > > > > You can create Types dynamically with System.Reflection.Emit > > > > > > Greets > > > Peter > > > > > > -- > > > ------ooo---OOO---ooo------ > > > > > > Peter Koen - www.kema.at > > > MCAD CAI/RS CASE/RS IAT > > > > > > ------ooo---OOO---ooo------ > > > > > >
Thanks, let me try it.
"Chris Taylor" <ch*************@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... Hi,
You do not need to use Assembly.LoadFrom and Activator.Create..., I gave both as an alternative. Try the following.
MyOCXLib.MyObject myObj = (MyOCXLib.MyObject)Activator.CreateInstance( "MyOCXLib.dll", "MyOCXLib.MyObject" );
I did not test this so excuse any typos.
Hope this helps
Chris Taylor
"ZhangZQ" <zh*******@hotmail.com> wrote in message news:eg**************@TK2MSFTNGP09.phx.gbl... Dear Chris Taylor,
I tried this, supposing I used VC++ to create an OCX call MyOCX, and
there is a object in the OCX call MyObject. I used the AxImp.exe to generate
the proxy assembly call MyOCXLib.dll. Now in my code
Assembly myAssembly = Assembly.LoadFrom("MyOCXLib.dll"); Type myObjType = myAssembly.GetType("MyOCXLib.MyObject");
MyOCXLib.MyObject myObj = (MyOCXLib.MyObject)Activator.CreateInstance(myObjT ype); // the above line will cause an exception to be thorwn with error
message "specified cast in invalid" // If I change to the following line MyOCXLib.MyObject myObj = (MyOCXLib.MyObject)Activator.CreateInstance(typeof (MyOCXLib.MyObject)); // then it is ok.
that is the problem. do you know why? I think the MyOCXLib.MyObject type does not exist in the current Assembly. What do you think?
Regards,
ZhangZQ "Chris Taylor" <ch*************@hotmail.com> wrote in message news:OK**************@TK2MSFTNGP09.phx.gbl... Hi,
Please forgive me if I am not understanding you correctly. The current running Assembly can use a public type in another Assembly by using either Activator.CreateInstance() of Assembly.Load().
Regards
Chris Taylor "ZhangZQ" <zh*******@hotmail.com> wrote in message news:en**************@TK2MSFTNGP09.phx.gbl... > Chris Taylor, > > Thank you. > > Yes, that is what I have to do. But I want to know if it is possible to add > another assembly into current running assembly? then I can refer
that data > type in current running assembly. > > Thanks. > > > > "Chris Taylor" <ch*************@hotmail.com> wrote in message > news:Ov**************@TK2MSFTNGP09.phx.gbl... > > Hi, > > > > You can use an appropriate overload of Activator.CreateInstance()
or you > > could use Assembly.Load() to load the Assembly and then use > GetType/GetTypes > > and use reflection from there. > > > > Hope this helps > > > > Chris Taylor > > > > "ZhangZQ" <zh*******@hotmail.com> wrote in message > > news:OH*************@tk2msftngp13.phx.gbl... > > > Peter, > > > > > > Thanks. > > > > > > My question is, supposing I defined a type(MyAssembly.MyType) in an > > assembly > > > call MyAssembly.dll, if I don't refer it in compile time, I want to load > > it > > > from runtime, how can I do that? > > > > > > > > > Thanks > > > > > > "Peter Koen" <koen-newsreply&snusnu.at> wrote in message > > > news:%2****************@TK2MSFTNGP09.phx.gbl... > > > > "ZhangZQ" <zh*******@hotmail.com> wrote in > > > > news:e6*************@TK2MSFTNGP10.phx.gbl: > > > > > > > > > The Assembly provides GetTypes() for retrieving the defined
type, is > > > > > there a way to add my type dynamically? > > > > > > > > > > > > You can create Types dynamically with System.Reflection.Emit > > > > > > > > Greets > > > > Peter > > > > > > > > -- > > > > ------ooo---OOO---ooo------ > > > > > > > > Peter Koen - www.kema.at > > > > MCAD CAI/RS CASE/RS IAT > > > > > > > > ------ooo---OOO---ooo------ > > > > > > > > > > > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ced |
last post by:
Hi,
i'm not an expert in C but i try to compile BTNG software under linux
kernel 2.4.2-2. I get these errors at the very first stage. Does
someone could have a rapid look on this and tell me...
|
by: Jigar.Patel |
last post by:
I have simple remoting server exposing following simple method. When I try to
add webreference to this server in another project by serveraddresss?wsdl,
it gives me following error:
Custom tool...
|
by: Jigar.Patel |
last post by:
I have simple remoting server exposing following simple method. When I try to
add webreference to this server in another project,
it gives me following error:
Custom tool error: Unable to import...
|
by: Xah Lee |
last post by:
in March, i posted a essay “What is Expressiveness in a Computer
Language”, archived at:
http://xahlee.org/perl-python/what_is_expresiveness.html
I was informed then that there is a academic...
|
by: Michael |
last post by:
Hi,
I could understand the difference between class and object. However, I
could find out a good definiton of type. how to understand the
relaitonship between type, class, and object? Thanks!
...
|
by: budy_ludy |
last post by:
Hi All,
I am new to vb .net,
I have an ArrayList and i store class objects in it,
and later i want to retrieve each ArrayList items and type cast to the
class,
How can it be done ?
I used...
|
by: garyusenet |
last post by:
I'm using an example piece of code: -
namespace Wintellect.Interop.Sound{
using System;
using System.Runtime.InteropServices;
using System.ComponentModel;
sealed class Sound{
public static...
|
by: mps |
last post by:
I want to define a class that has a generic parameter that is itself a
generic class. For example, if I have a generic IQueue<Tinterface, and
class A wants to make use of a generic class that...
|
by: aaragon |
last post by:
Hello, I was wondering if it is possible to forward declare a type
definition. If so, what is the way to do it? I found a couple of
messages where they say it's not possible but there must be a way...
|
by: Atropo |
last post by:
Hi, all.
As you can see I'm just begining on C. with the tutorial "Sams Teach
Yourself C in 24 Hours" as a starter. on aix 5.2 when compiling a
helloWorld the gcc throws some warnings the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
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...
|
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...
|
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...
|
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,...
| |