IfYouSaySo
Well-known member
OK...So I'm trying to dynamically instantiate a VBCodeProvider, using the Reflection namespace, and I want to use the 2.0 version, specifically not the 1.1 version, because I want to dynamically compile a bit of code that is using new .NET framework 2.0 features. It's not working for me. It seems as if the Version= part is ignored, because I can put in there whatever I want, and it doesn't complain:
Now, the code above is compiled into a .NET 1.1 executable, but the .config file is provides settings that are explicitly calling out "System, version=2.0.0.0, culture=neutral,PublicKeyToken=b77a5c561934e089",
(which is what is in my GAC).
So now I'm wondering if dynamically instantiating a 2.0 object from a 1.1 executable is even possible, or if the version is ignored (informational only), or what...
VB.NET:
Public Function GetProvider(ByVal lang As String) As CodeDomProvider
Dim cfg As NameValueCollection = CType(ConfigurationSettings.GetConfig(lang.ToLower()), NameValueCollection)
If cfg Is Nothing Then
Throw New UnsupportedLanguageException(lang.ToLower())
End If
' Load config settings
Dim strAssembly As String = CType(cfg("Assembly"),[String])
Dim strProvider As String = CType(cfg("Provider"),[String])
Dim strVersion As String = CType(cfg("Version"),[String])
Dim strPublicKeyToken As String = CType(cfg("PublicKeyToken"),[String])
Dim strCulture As String = CType(cfg("Culture"),[String])
If strCulture Is Nothing Then
strCulture = "neutral"
End If
Dim str As String = strAssembly & ", Version=" & strVersion & ", Culture=" & strCulture & ", PublicKeyToken=" & strPublicKeyToken
If strAssembly Is Nothing Or strProvider Is Nothing Or _
strVersion Is Nothing Or strPublicKeyToken Is Nothing Then
Throw New UnsupportedLanguageException(lang.ToLower())
End If
Dim asm As [Assembly] = [Assembly].Load(str)
If asm Is Nothing Then
Throw New InvalidAssemblyException(asm.ToString())
End If
Dim p As CodeDomProvider = CType(asm.CreateInstance(strProvider,True), CodeDomProvider)
If p Is Nothing Then
Throw New InvalidCodeProviderException(strProvider)
End If
Return p
End Function
Now, the code above is compiled into a .NET 1.1 executable, but the .config file is provides settings that are explicitly calling out "System, version=2.0.0.0, culture=neutral,PublicKeyToken=b77a5c561934e089",
(which is what is in my GAC).
So now I'm wondering if dynamically instantiating a 2.0 object from a 1.1 executable is even possible, or if the version is ignored (informational only), or what...