473,626 Members | 3,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(o bject sender, System.EventArg s e)
{
Type type = Type.GetType("S ystem.Windows.F orms.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 11639
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("S ystem.Windows.F orms.TextBox, " +
"System.Windows .Forms, Version=1.0.500 0.0, " +
"Culture=neutra l, PublicKeyToken= b77a5c561934e08 9" );

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

Type type = typeof(System.W indows.Forms.Te xtBox);

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("S ystem.Windows.F orms.TextBox, " +
"System.Windows .Forms, Version=1.0.500 0.0, " +
"Culture=neutra l, PublicKeyToken= b77a5c561934e08 9" );
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.W indows.Forms.Te xtBox);


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 GetPropertyValu e(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(o bject sender, System.EventArg s e)
{

string sAssemblyInfo = "System.Windows .Forms.TextBox,
System.Windows. Forms, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken= b77a5c561934e08 9";
string sControlName = "textBox1";
string sPropertyName = "Text";

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

MessageBox.Show ((string)type.G etProperty(sPro pertyName).GetV alue(GetControl (
sControlName), null));
}
}
private Control GetControl(stri ng 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
15098
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( "myDLLnamespace.CSDll" ) returns null. I made sure that the fully qualified class defined in the dll is case-sensitive. // CSEXE.exe
2
3494
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, I'm using the System::Type::GetType(String* typeName) to create a Type* needed to construct the XmlSerializer. The typeName argument is taken from the XmlDocument and consists of the
4
12011
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 = System.Type.GetType("DateTime"); t is set to the appropriate Type object but the second call returns null (when I dont specify the namespace name)
1
4000
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 = Type.GetType("SampleLib.MyClass"); My guess was that the function fails because my library isn't loaded yet.
1
3213
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= (IPasswordProvider)Activator.CreateInstance(t); GetConfigValue DOES return the correct value from the config file - "namespace.DBPassword, namespace" It appears that Type.GetType is NOT finding the assembly whose name is the
7
7808
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}" As far as I know yet -- hence this question -- there is no 'one solution fits all', but instead there are several parts that have to be put together to check. What I have so far is, and would like as much feedback as possible to ensure I've...
3
2517
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 string, returns null. Naturally, I suspect that because the this assembly doesn't reference the assembly containing "System.Drawing.Bitmap", the type cannot be found and thus I'm getting null in the GetType.
1
3528
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 assuming since I did not use the full name which is not available. I wrote the below method to return the Type but I have some concerns with it. First is there an eaiser way to do this that I am missing. Second, I am concerned about the...
4
13141
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 Type.GetType(enumTypeName) it returns null or throws an exception. Can anyone enlighten me on how to walk through an unknown enums elements to retrieve their custom attributes?
0
8259
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
8696
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8358
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
8502
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
5571
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4090
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...
1
2621
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1504
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.