Dynamically creating an object

  • Thread starter Thread starter ThisBytes5
  • Start date Start date
T

ThisBytes5

Type codeDomProviderType =
Type.GetType("Microsoft.CSharp­.CSharpCodeProvider", true);


ObjectHandle objHandle = Activator.CreateInstance(null,
"Microsoft.CSharp.CSharpCodePr­ovider");


Both lines of code throw exceptions when executed, neither one is able
to find the type in question. Am I on the right track? Or should I be
trying to create an instance of the provider a different way.


Example above is hard coded with the CSharpProvider for testing only,
eventually it will be read from a configuration file which one I want
to create.
 
For assemblies in GAC you need to provide fully qualified name:

Type type = Type.GetType("Microsoft.CSharp.CSharpCodeProvider, system,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089,
Custom=null", true);

HTH,
Alexander

Type codeDomProviderType =
Type.GetType("Microsoft.CSharp­.CSharpCodeProvider", true);


ObjectHandle objHandle = Activator.CreateInstance(null,
"Microsoft.CSharp.CSharpCodePr­ovider");


Both lines of code throw exceptions when executed, neither one is able
to find the type in question. Am I on the right track? Or should I be
trying to create an instance of the provider a different way.


Example above is hard coded with the CSharpProvider for testing only,
eventually it will be read from a configuration file which one I want
to create.
 
Now that I look at the below a bit more, I have one more question.

Where does the custom come from? I've looked at the properties for
windows\assembly and have found everything else but the custom.
 
No idea. I simply used "gacutil /l system" to get the full name.

HTH,
Alexander
 
Back
Top