none
System.TypeInitializationException was unhandled

    Question

  • I am working on a code that will import data into excel. Once I add the following piece of code I get a

    System.TypeInitializationException was unhandled error. The program stops and breaks in the form where I call my main (which starts the main as soon as the form opens). Does anyone see why this pice of code would cause this error?

    Thanks in advance

     

    #Region " (Import Data) This function will import the PI Tag Names and desired Attributes into an Excel worksheet "
    
        'Declare Varibles for Data Retrevial
        Dim sNameArray() As String                                     'Storage for each tag name
        Dim PITagNames As PISDK.PIPoints = myServer.PIPoints           'Stores the points that are to be checked
        Dim PIValues As PISDK.PIValue
        Dim Name As String
        Dim pPoints(sNameArray.Length - 1) As String
    
        Private Sub GetData()
            Dim i As Integer
            For i = 0 To sNameArray.Length - 1
                Try
                    Name = sNameArray(i)
                    PIValues = PITagNames(Name).Data.Snapshot
                    If PIValues.Value.GetType.IsCOMObject Then
                        pPoints(i) = (CType(PIValues.Value, PISDK.PointAttributes).Name)
                    Else
                        pPoints(i) = PIValues.Value
                    End If
                Catch ex As Exception
                    MsgBox("There was an error getting data from PI")
                    'The point does not exist, so go to the next point (should never happen)
                    (i) = ("Tag Not Found")
                End Try
            Next
            'Call CreateSpreadsheet(pPoints)
        End Sub
    #End Region
    



    Friday, February 19, 2010 8:24 PM

Answers

  • Hi.  It's hard to say for sure what the actual problem is but I believe this will occur when a referenced assembly encounters an exception during instantiation.  What exactly is causing the exception is the big question.  Often I think this happens when Shared/static members cause an exception -- which can occur the very first time the type is referenced.  There could be permission issues at hand where the referenced assembly has limited permissions due to a security policy - but that's just a guess.  If true it may be a line of code that is trying to perform an operation in limited security scope, like accessing a file, a data source or some other assembly that is not loaded on the local machine (like a font for example).
    • Marked as answer by Jeff Shan Friday, February 26, 2010 2:02 AM
    Friday, February 19, 2010 9:32 PM

All replies

  • Hi.  It's hard to say for sure what the actual problem is but I believe this will occur when a referenced assembly encounters an exception during instantiation.  What exactly is causing the exception is the big question.  Often I think this happens when Shared/static members cause an exception -- which can occur the very first time the type is referenced.  There could be permission issues at hand where the referenced assembly has limited permissions due to a security policy - but that's just a guess.  If true it may be a line of code that is trying to perform an operation in limited security scope, like accessing a file, a data source or some other assembly that is not loaded on the local machine (like a font for example).
    • Marked as answer by Jeff Shan Friday, February 26, 2010 2:02 AM
    Friday, February 19, 2010 9:32 PM
  • Thank you for the response. I am trying to import data into excel from servers that are up to 100 miles away. I will have to look into the security issue. Thanks for the idea.
    Friday, February 19, 2010 11:19 PM