G
Guest
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.Configuration.ConfigurationManager", false, true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration", false, true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Culture=\"\"", false, true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Culture=neutral", false, true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Culture=\"en\"", false, true));
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Culture=neutral, StrongName =null", false ,true));
//Error:
//resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Version=null,Culture=neutral", false ,true));
//Error:
//resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Version=\"\",Culture=neutral", false ,true));
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Version=2", false ,true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Version=2.0.0.0", false ,true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Version=2.0.0.0, Culture=null", false ,true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Version=2.0.0.0, Culture=\"\"", false ,true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Version=2.0.0.0, Culture=neutral", false ,true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Version=2.*", false, true))
resultList.Add(System.Type.GetType("System.Configuration.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.Configuration.ConfigurationManager,
System.Configuration, Version=null,Culture=neutral, PublicKeyToken=\"\"",
false ,true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, PublicKeyToken=b03f5f7f11d50a3a", false, true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration", false, true));
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Version=2.0.0.0", false, true));
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Version=2.0.0.0, Culture=neutral", false, true));
//Only one that works:
resultList.Add(System.Type.GetType("System.Configuration.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];
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.Configuration.ConfigurationManager", false, true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration", false, true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Culture=\"\"", false, true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Culture=neutral", false, true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Culture=\"en\"", false, true));
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Culture=neutral, StrongName =null", false ,true));
//Error:
//resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Version=null,Culture=neutral", false ,true));
//Error:
//resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Version=\"\",Culture=neutral", false ,true));
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Version=2", false ,true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Version=2.0.0.0", false ,true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Version=2.0.0.0, Culture=null", false ,true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Version=2.0.0.0, Culture=\"\"", false ,true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Version=2.0.0.0, Culture=neutral", false ,true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Version=2.*", false, true))
resultList.Add(System.Type.GetType("System.Configuration.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.Configuration.ConfigurationManager,
System.Configuration, Version=null,Culture=neutral, PublicKeyToken=\"\"",
false ,true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, PublicKeyToken=b03f5f7f11d50a3a", false, true))
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration", false, true));
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Version=2.0.0.0", false, true));
resultList.Add(System.Type.GetType("System.Configuration.ConfigurationManager, System.Configuration, Version=2.0.0.0, Culture=neutral", false, true));
//Only one that works:
resultList.Add(System.Type.GetType("System.Configuration.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];