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

GetType returns null on a loaded assembly

Good day! :O)

I have the following code :

//***
using System;
using System.Windows.Forms;

<snip>

private void button1_Click(object sender, System.EventArgs e)
{
Type type = Type.GetType("System.Windows.Forms.TextBox");
if (type != null)
{
MessageBox.Show(type.FullName);
}
}
//***

I've read in the archives that GetType() returns null if the assembly isn't
loaded... In this case the assembly is loaded but GetType always returns
null. Any ideas on what I'm doing wrong?

Thanks a lot!

--
Best Regards
Yanick Lefebvre

Please posts answers to the group so all can benefit
Nov 15 '05 #1
3 11588
I've read in the archives that GetType() returns null if the assembly isn't
loaded... In this case the assembly is loaded but GetType always returns
null. Any ideas on what I'm doing wrong?


When you don't explicitly provide the assembly name, Type.GetType()
only looks for the type in mscorlib and the calling assembly. Whether
or not you have loaded System.Windows.Forms is irrelevant.

This should work

Type type = Type.GetType("System.Windows.Forms.TextBox, " +
"System.Windows.Forms, Version=1.0.5000.0, " +
"Culture=neutral, PublicKeyToken=b77a5c561934e089" );

But since you obviously have System.Windows.Forms referenced, it's
better to do

Type type = typeof(System.Windows.Forms.TextBox);

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #2
Hi Mattias!

Type type = Type.GetType("System.Windows.Forms.TextBox, " +
"System.Windows.Forms, Version=1.0.5000.0, " +
"Culture=neutral, PublicKeyToken=b77a5c561934e089" );
Thanks! And where do I find this information? (i'm new to the .NET
environment..)

But since you obviously have System.Windows.Forms referenced, it's
better to do

Type type = typeof(System.Windows.Forms.TextBox);


I wish I could. ;O)

Actually I need a function that returns the property value of an object but
the only information I have to do so are of string type.

Something like :
private object GetPropertyValue(string sClassName, string sIntanceName,
string sPropertyName);

is it possible? thanks again!

--
Best Regards
Yanick Lefebvre

Please posts answers to the group so all can benefit
Nov 15 '05 #3
I got it.. i'm just not sure about the GetControl function.. isn't there a
better way?

that did the trick :
//***
private void button1_Click(object sender, System.EventArgs e)
{

string sAssemblyInfo = "System.Windows.Forms.TextBox,
System.Windows.Forms, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089";
string sControlName = "textBox1";
string sPropertyName = "Text";

Type type = Type.GetType(sAssemblyInfo);
if (type != null)
{

MessageBox.Show((string)type.GetProperty(sProperty Name).GetValue(GetControl(
sControlName), null));
}
}
private Control GetControl(string sControlName)
{
Control control = null;
foreach (Control ctl in this.Controls)
{
if (ctl.Name == sControlName)
{
control = ctl;
break;
}
}
return control;
}

Now I only need to know where you got the assembly information of a given
class. :O)
Thanks for your help!

--
Best Regards
Yanick Lefebvre

Please posts answers to the group so all can benefit
Nov 15 '05 #4

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

Similar topics

1
by: Suresh | last post by:
Hi, I have an C# CSEXE.exe (CSexe.cs) and a CSDll.dll (CSdll.cs). exe is compiled with a reference to dll. Calling for the class Type defined in CSDLL.dll using Type.GetType(...
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,...
4
by: audipen | last post by:
I have a problem with System.Type.GetType method. If you try out the following code in C# console app .. System.Type t = System.Type.GetType("System.DateTime"); System.Type t1 =...
1
by: Jean Stax | last post by:
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 =...
1
by: hazz | last post by:
"Value cannot be null.\r\nParameter name: type" is the exception thrown after the CreateInstance method below. Type t = Type.GetType(GetConfigValue("PasswordProvider")); IPasswordProvider ppdr=...
7
by: Sky | last post by:
I have been looking for a more powerful version of GetType(string) that will find the Type no matter what, and will work even if only supplied "{TypeName}", not the full "{TypeName},{AssemblyName}"...
3
by: Ron M. Newman | last post by:
Hi, I have a certain assembly that needs to create instances of objects where the object class is passed as a string (e.g. "System.Drawing.Bitmap"). I have found that calling "GetType" on this...
1
by: Jamey McElveen | last post by:
I have the typename of a form I wish to to load dynamically (example:MyCompany.Client.Win.Security.Detail.SysUserDetailForm). However, when I call Type.GetType(typeName) it return null I am...
4
by: =?Utf-8?B?QXhlbCBEYWhtZW4=?= | last post by:
Hi, I'd like to create a generic algorithm to analyse an enum's elements for custom attributes. All I have at hand is is a type name to create an enum type info from. But if I call...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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:
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...
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: 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.