472,986 Members | 2,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,986 software developers and data experts.

System.Type & QAN.... Will 'version' break things down the line?

Sky
Yesterday I was told that GetType(string) should not just be with a Type, but
be Type, AssemblyName. Fair enough, get the reason. (Finally!).

As long as it doesn't cause tech support problems down the line...
What happens when my code is run on a station that only has framework 3.0 or
4.0, and this assembly, with version number defined for 2.0.0.0 , isn't
available. ...breaks?

Second question:
Does an assembly's PublicKeyToken change for every release of the framework?
Or is it defined for good? I'm asking this because I've found that some Types
can be gotten with simply the assemblyname, and sometimes nothing works
except for a FullyQualifiedAssemblyName.

Hence my question as to what is the cost down the road to specifying Version
and PublicKeyToken information.

And then there is just the don't get it part, still:
Frankly, I don't understand why some Types it can find with just a partial
AssemblyName, no version or anything...and others, like this Type below,
needs absolutely everything before it comes back non-null. Can I get it to be
a little less strict?

//STUDY:

//Get a real instance and see what its FQAN is:
System.Type to = typeof(System.Configuration.ConfigurationManager);

//This is what I get back:
string AssemblyQualifiedName = type.AssemblyQualifiedName;
//which was:
//"System.Configuration.ConfigurationManager, System.Configuration,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
//Here we try to get the type via reflection with variations of partial
names...
//With terrible results:
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager", false, true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration", false, true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Culture=\"\"", false, true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Culture=neutral", false, true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Culture=\"en\"", false, true));

resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Culture=neutral, StrongName =null", false ,true));

//Error:
//resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Version=null,Culture=neutral", false ,true));
//Error:
//resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Version=\"\",Culture=neutral", false ,true));

resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Version=2", false ,true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Version=2.0.0.0", false ,true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Version=2.0.0.0, Culture=null", false ,true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Version=2.0.0.0, Culture=\"\"", false ,true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Version=2.0.0.0, Culture=neutral", false ,true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Version=2.*", false, true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Culture=neutral, Version=2.0.0.0", false, true));
//Error:
//resultList.Add(System.Type.GetTyp
("System.Configuration.ConfigurationManager,
PublicKeyToken=b03f5f7f11d50a3a", false, true));
//Error:
//resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager,
System.Configuration, Version=null,Culture=neutral, PublicKeyToken=\"\"",
false ,true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, PublicKeyToken=b03f5f7f11d50a3a", false, true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration", false, true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Version=2.0.0.0", false, true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Version=2.0.0.0, Culture=neutral", false, true));

//Only one that works:
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager,
System.Configuration, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a",false ,true));

//If I breakpoint here to check, the only non-null is the last one...
System.Type configurationManagerType = resultList[resultList.Count-1];
Jul 26 '06 #1
1 2089
Sky
Aha!!!
After trying 20 or so variations...only one I hadn't tried was:
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager,
System.Configuration, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a",false ,true));

Guess what? It works.

but this doesn't:
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager,
System.Configuration, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a",false ,true));
Conclusion:
Although at first it looks really scary to use an Assembly name tied to a
version that may not exist in the future (such as binding to 2.0, and later
-- many eons from now -- when the code runs on a new OS that has NET 4.0 on
it, but not 2.0) it will not break!
Why?
a) The name will be the same if in the NET framework
b) The PublicKeyToken will be the same for all versions of it (I think,
atleast it seems reasonable, if it was snk'd before being released the first
time)
c) The culture is generally going to be neutral in most cases
d) The version though, will try to find the exact match if it can -- if it
can't, it will increment till it finds the first and nearest version.

Ok. I can relax now. This finally puts to rest my worrying about using FQN
in config files, when I was trying to do everything to avoid them, and
running into serious trouble loading from GAC with only partial names. No
need to. Bind to a FQN of the version you currently have -- it won't break in
future (except for 'breaking changes' the Framework, but there we are talking
about method signatures, not assembly names).

Night,
Sky


"Sky" wrote:
Yesterday I was told that GetType(string) should not just be with a Type, but
be Type, AssemblyName. Fair enough, get the reason. (Finally!).

As long as it doesn't cause tech support problems down the line...
What happens when my code is run on a station that only has framework 3.0 or
4.0, and this assembly, with version number defined for 2.0.0.0 , isn't
available. ...breaks?

Second question:
Does an assembly's PublicKeyToken change for every release of the framework?
Or is it defined for good? I'm asking this because I've found that some Types
can be gotten with simply the assemblyname, and sometimes nothing works
except for a FullyQualifiedAssemblyName.

Hence my question as to what is the cost down the road to specifying Version
and PublicKeyToken information.

And then there is just the don't get it part, still:
Frankly, I don't understand why some Types it can find with just a partial
AssemblyName, no version or anything...and others, like this Type below,
needs absolutely everything before it comes back non-null. Can I get it to be
a little less strict?

//STUDY:

//Get a real instance and see what its FQAN is:
System.Type to = typeof(System.Configuration.ConfigurationManager);

//This is what I get back:
string AssemblyQualifiedName = type.AssemblyQualifiedName;
//which was:
//"System.Configuration.ConfigurationManager, System.Configuration,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
//Here we try to get the type via reflection with variations of partial
names...
//With terrible results:
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager", false, true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration", false, true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Culture=\"\"", false, true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Culture=neutral", false, true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Culture=\"en\"", false, true));

resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Culture=neutral, StrongName =null", false ,true));

//Error:
//resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Version=null,Culture=neutral", false ,true));
//Error:
//resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Version=\"\",Culture=neutral", false ,true));

resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Version=2", false ,true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Version=2.0.0.0", false ,true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Version=2.0.0.0, Culture=null", false ,true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Version=2.0.0.0, Culture=\"\"", false ,true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Version=2.0.0.0, Culture=neutral", false ,true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Version=2.*", false, true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Culture=neutral, Version=2.0.0.0", false, true));
//Error:
//resultList.Add(System.Type.GetTyp
("System.Configuration.ConfigurationManager,
PublicKeyToken=b03f5f7f11d50a3a", false, true));
//Error:
//resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager,
System.Configuration, Version=null,Culture=neutral, PublicKeyToken=\"\"",
false ,true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, PublicKeyToken=b03f5f7f11d50a3a", false, true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration", false, true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Version=2.0.0.0", false, true));
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager, System.Configuration, Version=2.0.0.0, Culture=neutral", false, true));

//Only one that works:
resultList.Add(System.Type.GetType("System.Configu ration.ConfigurationManager,
System.Configuration, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a",false ,true));

//If I breakpoint here to check, the only non-null is the last one...
System.Type configurationManagerType = resultList[resultList.Count-1];

Jul 30 '06 #2

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

Similar topics

19
by: Philipp Lenssen | last post by:
I don't know the English word, but I'm referring to the double-dash which is used to separate parts of a sentence. I'm using — so far. Now I saw – which is slightly shorter. Some sites use --. ...
39
by: Hareth | last post by:
C# 2005 express & vb 2005 express: 1. During runtime, I can edit my codes in C#..... How come this cannot be done in VB? it says ...."read-only" during runtime...... 2. Why does vb...
1
by: Kevin Bartz | last post by:
-----Original Message----- From: Kevin Bartz Sent: Friday, August 06, 2004 8:41 PM To: 'mike@thegodshalls.com' Subject: RE: Out of swap space & memory Well, all I'm doing right now is using...
11
by: frizzle | last post by:
Hi groupies I'm building a news site, to wich a user can add new items into a mySQL db. It's still in testfase, but it's so extremely slow, i want to figure out what i'm doing wrong, or what to...
8
by: Mike S | last post by:
Hi all, I noticed a very slight logic error in the solution to K&R Exercise 1-22 on the the CLC-Wiki, located at http://www.clc-wiki.net/wiki/KR2_Exercise_1-22 The exercise reads as...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
0
by: balean | last post by:
Hi guys, I need help. I am trying to extract data from XML file. I am using all the fucntions needed to parse the xml data every thing working fine, but what I am looking for is to take the string...
0
by: Adam Salisbury | last post by:
**To members of microsoft.public.dotnet.framework, apologies for the crosspost. I originally posted this message into that group however have since realised this may have been a better...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.