Casting from System.RuntimeType

I’m trying to load SqlConnection dynamically like this:

asm = [Assembly].LoadWithPartialName("System.Data")
con = asm.GetType("System.Data.SqlClient.SqlConnection")

How can I convert con, which is of the type "System.RuntimeType", to SqlConnection

Thanks


Answer this question

Casting from System.RuntimeType

  • Jonas Røineslien

    Aah ok thank you

  • technoTABLET

    You can't cast a Type object to a SqlConnection. If you want to create an instance of the type, check out the Activator.CreateInstance method.



  • Casting from System.RuntimeType