Hi.
I am trying to get a type object using GetType. For this,
I use:
Type type = Type.GetType("S ystem.Windows.F orms.TextBox");
But after this line, when I check, type is null.
What am I doing wrong ? How to do it right ?
Thank you and God bless.
_____
Marco 6 2189
Marco <a@b.c> wrote: I am trying to get a type object using GetType. For this, I use:
Type type = Type.GetType("S ystem.Windows.F orms.TextBox");
But after this line, when I check, type is null. What am I doing wrong ? How to do it right ?
Type.GetType only looks in the currently executing assembly and
mscorlib.
For the above, you should use
Type type = typeof(System.W indows.Forms.Te xtBox);
If you need to dynamically get another type, you should work out what
assembly it should be part of, and call Assembly.GetTyp e appropriately.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
> Type type = Type.GetType("S ystem.Windows.F orms.TextBox");
try use typeof(TextBox) instead. this should be more reliable.
Jon and Marco,
Jon's statement:
Type.GetType only looks in the currently executing assembly and mscorlib.
Isn't completely true. If the type name that is passed in unqualified
(which is indeed the form that the original caller was using), it will
search only the current assembly and mscorlib (there is an inconsistency in
the documentation that states that it will look in System.dll and in the
current assembly). However, the following will work:
Type.GetType("S ystem.Windows.F orms.TextBox, System.Windows. Forms,
Version=1.0.500 0.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9");
So, as a general rule, when doing dynamic discovery of types, make sure
to store the fully qualified name of the type (which means full namespace,
full assembly name with version, public key, etc, etc if they exist).
However, if you know that the type that you have to get is a TextBox,
then Jon's suggestion of using typeof is the more reliable solution.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com
"Jon Skeet" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@news.microsof t.com... Marco <a@b.c> wrote: I am trying to get a type object using GetType. For this, I use:
Type type = Type.GetType("S ystem.Windows.F orms.TextBox");
But after this line, when I check, type is null. What am I doing wrong ? How to do it right ?
Type.GetType only looks in the currently executing assembly and mscorlib.
For the above, you should use
Type type = typeof(System.W indows.Forms.Te xtBox);
If you need to dynamically get another type, you should work out what assembly it should be part of, and call Assembly.GetTyp e appropriately.
-- Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Jon, typeof did what I needed.
Thank you very much and God bless.
_____
Marco
Jon, typeof did what I needed.
Thank you very much and God bless.
_____
Marco
Nicholas Paldino [.NET/C# MVP] <ni************ **@exisconsulti ng.com>
wrote: Type.GetType only looks in the currently executing assembly and mscorlib.
Isn't completely true. If the type name that is passed in unqualified (which is indeed the form that the original caller was using), it will search only the current assembly and mscorlib (there is an inconsistency in the documentation that states that it will look in System.dll and in the current assembly). However, the following will work:
<snip>
Apologies - yes indeed. Sorry for not being clear :(
Type.GetType("S ystem.Windows.F orms.TextBox, System.Windows. Forms, Version=1.0.500 0.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9");
So, as a general rule, when doing dynamic discovery of types, make sure to store the fully qualified name of the type (which means full namespace, full assembly name with version, public key, etc, etc if they exist).
Or load the assembly separately and use Assembly.GetTyp e.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
by: ron |
last post by:
Hi,
I am currently using the base class GetType() in the
following way and was woundering if there was a different
way of looking at types and doing a comparison for
equality.
Thanks Ron
foreach(System.Web.UI.Control ctl in this.Controls)
{
|
by: Jimi |
last post by:
What am I doing wrong?
I'm trying to get a type object for a type which is not currently
loaded in my project (otherwise I'd use "typeof").
System.Type oType = System.Type.GetType("SomeNamespace.SomeType");
But oType is always "<undefined value>" after this line.
Any help is much appreciated.
|
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
|
by: Nicolas |
last post by:
I want to return the proper Null to the SQL Database if my property is
nothing
Also I thought about creating a function so I don't have to put so many if
statement for each property for each classes etc.
However if I call ReturnValue(myClass.CompanyName) and CompanyName is
Nothing then it crash where it shoud return SqlTypes.SqlString.Null
Private _CompanyName As String
| |
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...
|
by: hardieca |
last post by:
Hi,
I have an .aspx page that needs to instantiate an object whose type in
not known until runtime. The definition of said object resides in
/App_code/CMS.cs
CMS.cs
==================
namespace CMS{
public interface IWindmill{
|
by: Carlos Rodriguez |
last post by:
I have the following function in C#public void Undo(IDesignerHost host)
{
if (!this.componentName.Equals(string.Empty) && (this.member != null))
{
IContainer container1 = (IContainer)
host.GetService(typeof(IContainer));
IComponent component1 =
container1.Components;
PropertyInfo info1 =
component1.GetType().GetProperty(this.member.Name);
|
by: Martin Eckart |
last post by:
Hi folks,
Who can explain me why the following expression does not result in getting
the correct type, but null:
Type t = Type.GetType("System.Xml.XmlReader");
For "System.String" it works as well as for "System.IO.Stream" or
"System.Globalization.CultureInfo". Does that related to the constructor of
XmlReader being not public?
|
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...
|
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...
| |
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |