By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,238 Members | 1,771 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,238 IT Pros & Developers. It's quick & easy.

Type.GetType for referenced library returns undefined value

P: n/a
Hi !

I created a sample library project. In my second project I reference
this library
and make the following call, which returns "undefined value":

Type myType = Type.GetType("SampleLib.MyClass");

My guess was that the function fails because my library isn't loaded
yet.
So I wrote the following:

SampleLib.MyClass ptrMyClass = new SampleLib.MyClass();
Type myType = Type.GetType("SampleLib.MyClass");

Unfortunately, this doesn't solve my problem. Type.GetType of any new
type defined in my second project
works just fine.

Any ideas ?

Thanks
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
The MSDN documentation for System.Type.GetType() explains what's going on
here:
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemtypeclassgettypetopic1.asp

The documentation says: "If typeName includes only the name of the Type,
this method searches in the calling object's assembly, then in the
mscorlib.dll assembly. If typeName is fully qualified with the partial or
complete assembly name, this method searches in the specified assembly."

So, as you noted, you are able to look up types in the same assembly, but
not in a referenced assembly. To look up a type in a reference assembly,
add the referenced assembly name to the string. If your SampleLib.MyClass
class exists in a DLL called MyLibrary, then you would write this code to
look it up:

Type myType = Type.GetType("SampleLib.MyClass,MyLibrary");
--
Eric, Visual Studio Enterprise Frameworks and Tools

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
--------------------
| From: je*******@hotmail.com (Jean Stax)
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Subject: Type.GetType for referenced library returns undefined value
| Date: 25 Oct 2003 12:51:24 -0700
| Organization: http://groups.google.com
| Lines: 22
| Message-ID: <df**************************@posting.google.com >
| NNTP-Posting-Host: 212.150.123.82
| Content-Type: text/plain; charset=ISO-8859-1
| Content-Transfer-Encoding: 8bit
| X-Trace: posting.google.com 1067111485 3928 127.0.0.1 (25 Oct 2003
19:51:25 GMT)
| X-Complaints-To: gr**********@google.com
| NNTP-Posting-Date: Sat, 25 Oct 2003 19:51:25 +0000 (UTC)
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!t-onlin
e.de!newsfeed.icl.net!newsfeed.fjserv.net!news.max well.syr.edu!postnews1.goo
gle.com!not-for-mail
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:194051
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hi !
|
| I created a sample library project. In my second project I reference
| this library
| and make the following call, which returns "undefined value":
|
| Type myType = Type.GetType("SampleLib.MyClass");
|
| My guess was that the function fails because my library isn't loaded
| yet.
| So I wrote the following:
|
| SampleLib.MyClass ptrMyClass = new SampleLib.MyClass();
| Type myType = Type.GetType("SampleLib.MyClass");
|
| Unfortunately, this doesn't solve my problem. Type.GetType of any new
| type defined in my second project
| works just fine.
|
| Any ideas ?
|
| Thanks
|

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.