Question 'Object variable or With block variable not set' Error

Bonekrusher

Active member
Joined
Jul 4, 2007
Messages
38
Programming Experience
1-3
Hi,

I am receiving the following error when I deploy my application, but not when I run through Visual Basic 2008 Express:

VB.NET:
'Object variable or With block variable not set'


Here is my code:

VB.NET:
Public Function doTransform(ByVal xml As String, ByVal xslt As String, ByVal out As String, ByVal pubname As String, _
                                ByVal pubNum As String, ByVal maintlvl As String, ByVal imlvl As String, ByVal niin As String, _
                                ByVal pubtype As String)
        ' Create a serializer
        Dim serializer As Serializer = New Serializer()
        Dim fs As FileStream = New FileStream(out, FileMode.Create, FileAccess.Write)
        Dim processor As Processor = New Processor()
        Dim input As XdmNode
        Dim compiler
        Dim transformer As XsltTransformer
        Try
            processor.Implementation.setCollectionURIResolver(New net.sf.saxon.functions.StandardCollectionURIResolver())

            ' Load the source document
            input = processor.NewDocumentBuilder().Build(New Uri(xml))
            compiler = processor.NewXsltCompiler()
            compiler.ErrorList = New ArrayList()
            ' Create a transformer for the stylesheet.
            transformer = compiler.Compile(New Uri(xslt)).Load()

            ' Parameters
            transformer.SetParameter(New QName("", "", "pub-name"), New XdmAtomicValue(pubname))
            transformer.SetParameter(New QName("", "", "pub-number"), New XdmAtomicValue(pubNum))
            transformer.SetParameter(New QName("", "", "gui-maintlvls"), New XdmAtomicValue(maintlvl))
            transformer.SetParameter(New QName("", "", "gui-imlvls"), New XdmAtomicValue(imlvl))
            transformer.SetParameter(New QName("", "", "niin"), New XdmAtomicValue(niin))
            transformer.SetParameter(New QName("", "", "pub-type"), New XdmAtomicValue(pubtype))
            ' Set the root node of the source document to be the initial context node
            transformer.InitialContextNode = input
            serializer.SetOutputStream(fs)
            ' Transform the source XML to System.out.
            transformer.Run(serializer)

        Catch ex As Exception
            mainForm.txtConsole.Text += "There were " + compiler.ErrorList.Count.ToString + " Errors"
            Dim myerror As StaticError
            For Each myerror In compiler.ErrorList
                mainForm.txtConsole.Text += "At line " + myerror.LineNumber.ToString + ": " + myerror.Message.ToString
            Next
        Finally
            serializer.Close()
            fs.Close()
        End Try




        Return 0

Thanks for the help.
Bones
 
Never mind. I figured it out.

I should have read the warnings:

VB.NET:
Variable 'compiler' is used before it has been assigned a value. A null reference exception could result at runtime.
 
I also see that you're not declaring 'compiler' as anything when you dimension it:
Dim compiler

what's with that?
 
Back
Top