Manoj Patel

Manoj Patel

  • NA
  • 26
  • 15.1k

VB.net WPF :Unable to cast object of type 'Ocean.GeneralMast

Apr 24 2013 7:01 AM
Dear Experts,

I'm using wpf with vb.net. When i tried below code then i'm getting an error 

Error--------------
Unable to cast object of type 'Ocean.GeneralMaster' to type 'System.Windows.Forms.Form'.
------------------



 Dim objForm As Form
        Dim sValue As String
        Dim FullTypeName As String
        Dim FormInstanceType As Type
        ' Form class name
        sValue = "GeneralMaster"
        ' Assume that form classes' namespace is the same as ProductName
        FullTypeName = "Ocean" & "." & sValue
        ' Now, get the actual type
        FormInstanceType = Type.GetType(FullTypeName, True, True)
        ' Create an instance of this form type
        objForm = CType(Activator.CreateInstance(FormInstanceType), Form)
        ' Show the form instance
        objForm.Show()