473,385 Members | 1,409 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,385 software developers and data experts.

GetType not working?

I am having some troubles with loading up a type dynamically.

From what i have read

Type myType = Type.GetType("WB.DataAccess.FAQ");

is the exact same as

Type myType = typeof(WB.DataAccess.FAQ);
HOWEVER..... in practise it doesnt quite work..... using typeof always
works.... however using the GetType doesnt it will set
myType to be null or undefined.

What am i doing wrong? i need to load up a type from a string value.

Nov 16 '05 #1
5 1638
Darren

try this.

Type myType = myAssembly.GetType("WB.DataAccess.FAQ");

myType wont be null..
Shak.
"Darren Clark" <dc******@hotmail.com> wrote in message
news:uN**************@TK2MSFTNGP12.phx.gbl...
I am having some troubles with loading up a type dynamically.

From what i have read

Type myType = Type.GetType("WB.DataAccess.FAQ");

is the exact same as

Type myType = typeof(WB.DataAccess.FAQ);
HOWEVER..... in practise it doesnt quite work..... using typeof always
works.... however using the GetType doesnt it will set
myType to be null or undefined.

What am i doing wrong? i need to load up a type from a string value.


Nov 16 '05 #2
hi,

probably GetType() requires the run type expression of a type, can you try
something like

MyType t1 = new MyType();
Type t = t1.GetType();

rgds
Joyjit
"Darren Clark" <dc******@hotmail.com> wrote in message
news:uN**************@TK2MSFTNGP12.phx.gbl...
I am having some troubles with loading up a type dynamically.

From what i have read

Type myType = Type.GetType("WB.DataAccess.FAQ");

is the exact same as

Type myType = typeof(WB.DataAccess.FAQ);
HOWEVER..... in practise it doesnt quite work..... using typeof always
works.... however using the GetType doesnt it will set
myType to be null or undefined.

What am i doing wrong? i need to load up a type from a string value.


Nov 16 '05 #3
Hi Darren,

I think that in your case myType is set to "null".
Probably, the reason is that this type is stored in
assembly that did not load.

Look at: Assembly.Load in .NET docs.

Regards

Marcin
I am having some troubles with loading up a type dynamically.

From what i have read

Type myType = Type.GetType("WB.DataAccess.FAQ");

is the exact same as

Type myType = typeof(WB.DataAccess.FAQ);
HOWEVER..... in practise it doesnt quite work..... using typeof always
works.... however using the GetType doesnt it will set
myType to be null or undefined.

What am i doing wrong? i need to load up a type from a string value.


Nov 16 '05 #4
Darren Clark <dc******@hotmail.com> wrote:
I am having some troubles with loading up a type dynamically.

From what i have read

Type myType = Type.GetType("WB.DataAccess.FAQ");

is the exact same as

Type myType = typeof(WB.DataAccess.FAQ);


No, it's not. Type.GetType(string) will, when given just the type name
and no assembly information, only look in mscorlib and the current
assembly. typeof actually uses completely different (and more
efficient) IL, I believe.

If you need to fetch a type from another assembly, either use
Assembly.GetType or call Type.GetType with the assembly name in the
string as well.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
MyNews <jo**************@thomson.com> wrote:
probably GetType() requires the run type expression of a type, can you try
something like

MyType t1 = new MyType();
Type t = t1.GetType();


No, the method being talked about here is the static method
Type.GetType(string).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6

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

Similar topics

3
by: Kelmen Wong | last post by:
Greeting, I'm working on a class managing resources (satelite). public CResMgr() { Assembly objClient = Assembly.GetCallingAssembly(); _objResMgr = new...
0
by: Sean | last post by:
Hello, I have the following class: Public class INFO <xmlElementAttribute("ALM_INFO",GetType(ALM_INFO), <xmlElementAttribute("COMMENT",GetType(System.string()), Public Items() as object...
2
by: JohnnySparkles | last post by:
Hi everyone, I'm currently writing an application which uses the XmlSerializer class to serialize/deserialize objects to/from xml. Now when deserializing an XmlDocument back into the object,...
7
by: .pd. | last post by:
Hello, I'm trying to setup a named-object list using objects of 3 different types all derived from the same base class. public class namedObjectList :...
1
by: Ekips | last post by:
Currently im using Type.GetType("namespace.myType") to get the type for the classes, but i want to store the types in a class library insted, however when i do this it will nolonger return a type,...
10
by: Bob | last post by:
This has been bugging me for a while now. GetType isn't availble for variables decalred as interface types, I have to DirectCast(somevariable, Object). In example: Sub SomeSub(ByVal...
5
by: Grande | last post by:
Hi all, I'm trying to use GetType to get an Interface, but it's not working? Is there a special way you have to do this, since it's an Interface (rather than a complete class)? Code: Type...
0
by: svwi | last post by:
Hi. I need to dynamically retreive the type name of a COM-object exposed by a C# COM server. This was previously successfully done in .NET framwork 1.X with the method "GetType()", inherited...
2
by: nibin | last post by:
pls help me it urgent i m facing a problem with my vb.net code this is the code equivalent in c# this is the interface...........
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
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...

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.