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

How to extract full type name from assembly qualified name

Hi there,

Does anyone know how to extract the full type name ("namespace.type") from
an assembly qualified name. Thanks.
Jun 12 '07 #1
11 15071
On Jun 12, 6:43 pm, "John Brown" <no_spam@_nospam.comwrote:
Hi there,

Does anyone know how to extract the full type name ("namespace.type") from
an assembly qualified name. Thanks.
I think System.Reflection namespace will help you with that problem.

Jun 12 '07 #2
I think System.Reflection namespace will help you with that problem.

That's what I thought but I can't find any relevant class. I thought
"AssemblyName" might help but it throws the following no matter what I pass
it:

"The given assembly name or codebase was invalid. (Exception from HRESULT:
0x80131047)"
Jun 12 '07 #3
Can you show the code you are using to load the assembly?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John Brown" <no_spam@_nospam.comwrote in message
news:ek**************@TK2MSFTNGP02.phx.gbl...
>I think System.Reflection namespace will help you with that problem.

That's what I thought but I can't find any relevant class. I thought
"AssemblyName" might help but it throws the following no matter what I
pass it:

"The given assembly name or codebase was invalid. (Exception from HRESULT:
0x80131047)"

Jun 12 '07 #4
Thanks for the feedback.
Can you show the code you are using to load the assembly?
I'm not explicitly loading the assembly. I'm simply passing the string to
the "AssemblyName" constructor though I've since discovered it's probably
not the correct class. That is, the exception results when I pass it this
for instance:

"System.String, mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089"

The constructor takes a "display name" argument according to the docs which
is the above name *minus* the "System.String, " at the start (based on what
I've read about the format of a fully-qualified asssembly name).
"System.String" is what I'm trying to extract however but I don't know if
it's safe to simply parse the string myself. Can I safely assume it will
always precede the first comma that is and will it matter if I run this on a
thread with a different culture (i.e., is the comma culture-sensitive in
thsi context - I wouldn't think so). Preferably I want to use an official
function if one is available. Thanks.
Jun 12 '07 #5
On Jun 12, 10:11 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
Can you show the code you are using to load the assembly?

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"John Brown" <no_spam@_nospam.comwrote in message

news:ek**************@TK2MSFTNGP02.phx.gbl...
I think System.Reflection namespace will help you with that problem.
That's what I thought but I can't find any relevant class. I thought
"AssemblyName" might help but it throws the following no matter what I
pass it:
"The given assembly name or codebase was invalid. (Exception from HRESULT:
0x80131047)"- Hide quoted text -

- Show quoted text -
Are you using GetType() method? THis method expects a fully quliafied
name i guess.

Try using "Assembly.FullName"

Jun 12 '07 #6
Are you using GetType() method? THis method expects a fully quliafied
name i guess.

Try using "Assembly.FullName"
I'm not working with the assembly. I'm only working with the
assembly-qualified strings themselves. The actual assembly might not even be
present on the host machine (e.g., 3rd-party assemblies).
Jun 12 '07 #7
John,

You absolutely can parse the fully qualified type name yourself. If you
are sure that it is a valid type name, then you can use the following BNF
notation to generate parse rules to get what you are after:

http://msdn2.microsoft.com/en-us/library/yfsftwz6.aspx
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John Brown" <no_spam@_nospam.comwrote in message
news:OI**************@TK2MSFTNGP04.phx.gbl...
Thanks for the feedback.
> Can you show the code you are using to load the assembly?

I'm not explicitly loading the assembly. I'm simply passing the string to
the "AssemblyName" constructor though I've since discovered it's probably
not the correct class. That is, the exception results when I pass it this
for instance:

"System.String, mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089"

The constructor takes a "display name" argument according to the docs
which is the above name *minus* the "System.String, " at the start (based
on what I've read about the format of a fully-qualified asssembly name).
"System.String" is what I'm trying to extract however but I don't know if
it's safe to simply parse the string myself. Can I safely assume it will
always precede the first comma that is and will it matter if I run this on
a thread with a different culture (i.e., is the comma culture-sensitive in
thsi context - I wouldn't think so). Preferably I want to use an official
function if one is available. Thanks.

Jun 12 '07 #8
John,
>
You absolutely can parse the fully qualified type name yourself. If
you are sure that it is a valid type name, then you can use the following
BNF notation to generate parse rules to get what you are after:

http://msdn2.microsoft.com/en-us/library/yfsftwz6.aspx
Thanks for the link. I was hoping a canned routine would already be natively
available but I'll just have to roll it myself assuming I can't find a
reliable implementation on the web. Anyway, thanks again.
Jun 12 '07 #9
Hi,

"John Brown" <no_spam@_nospam.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Hi there,

Does anyone know how to extract the full type name ("namespace.type") from
an assembly qualified name. Thanks.
what about typeof( YourType) ?
Jun 12 '07 #10
>Does anyone know how to extract the full type name ("namespace.type")
>from an assembly qualified name. Thanks.

what about typeof( YourType) ?
Thanks but I don't have the actual type, only the assembly qualified name as
a string. I did find this blurb under "Type.AssemblyQualifiedName" however:

"The assembly-qualified name of a type consists of the type name, including
its namespace, followed by a comma, followed by the display name of the
assembly."

I'm leery about trusting this however since it may be just a passing
comment. I'm now looking through the BNF link that Nicholas provided to
confirm if it's really safe to simply scan for the first comma.
Jun 12 '07 #11
"John Brown" <no_spam@_nospam.comwrote in message
news:#Q**************@TK2MSFTNGP05.phx.gbl...
Hi there,

Does anyone know how to extract the full type name ("namespace.type") from
an assembly qualified name. Thanks.
The following works in v1.1 (And should work in all later versions and
possibly even earlier one too):

string qualType =
@"System.String, mscorlib, Version=2.0.0.0, " +
@"Culture=neutral, PublicKeyToken=b77a5c561934e089";

Type t = Type.GetType(qualType, false);

if (t == null) {
Console.WriteLine("Invalid qualified type string.");
return;
}

Console.WriteLine(t.FullName);
HTH :)

Mythran
Jun 12 '07 #12

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

Similar topics

4
by: pervinder | last post by:
Hi, I get an error on line #3 while compiling the program segment on aix (xlc - va6) While this warning is not seen with gcc "test.cpp" line 200.18: 1540-0152 (W) A template dependent name that...
4
by: Jim Garrison | last post by:
I know how to use the name() function to access the name of the current node. How do I get the 'fully qualified' name, consisting of the path from the root to the current node? I.e. <a> <b>...
0
by: JMD | last post by:
I have a set of schemas for two different XML files that share common structures through the use of "import". Eventually, the main XSD file (which just gathers pieces from the common stuff to...
4
by: Aashish Patil | last post by:
Hello, Is it possible to obtain the fully qualified name of a class in c#. What I am looking for is something analogous to Box.class.getName() that exists in Java. Its possible to get this by...
1
by: Erland | last post by:
Hi all, As per my understanding in order to load an assembly using Assembly.Load() you have to provide fully qualified name of the assembly you are trying to load e.g. Assembly...
2
by: Larry Smith | last post by:
Hi there, How can I convert this: "System.Windows.Forms.Form" to this: "System.Windows.Forms.Form, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
4
by: Wayne Shu | last post by:
Hey, guys. There is a problem. e.g. template <typename T> class foo { public: foo();
0
by: Jim Avera | last post by:
On AIX, a template class containing a nested class which needs to be a friend provokes a warning: (W) A template dependent name that is a type must be qualified with "typename". and method...
5
by: Simon Brooke | last post by:
The documentation for org.w3c.dom.DOMImplementation.createDocumentType says helpfully: public DocumentType createDocumentType(java.lang.String qualifiedName, java.lang.String publicId,...
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
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...
0
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,...
0
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,...

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.