Link to home
Start Free TrialLog in
Avatar of mattegol
mattegolFlag for Sweden

asked on

Get 32bit asp.net to work with 64bit

I have an application that reads excel files, and after an upgrade from 32bit to 64bit I get these errors when trying to get the excel file.

Diagnostic Data Retrieving the COM class factory for component with CLSID {0002E559-0000-0000-C000-000000000046} failed due to the following error: 80040154.

And

The "SendUsing" configuration value is invalid
Private Sub btnFull_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFull.Click
            Dim sFormat As String
            Try
                sFormat = rblReportType.SelectedValue() 'check to see whether its CSV or Excel. If Empty we default to excel
                If sFormat = "" Then
                    sFormat = "Excel"
                End If

                PopReport("Full", sFormat)
                trDownload.Visible = True   'make download row visible
                trSep1.Visible = True
                '        btnFull.Enabled = False 'do not allow creation of another report until the one generated is downloaded.
            Catch excException As Exception

                If Not TypeOf excException.GetBaseException Is System.Threading.ThreadAbortException Then

                    Me.cvGeneral.ErrorMessage = Session("GenErrorText") ' Errors.UserFriendlyMessage(excException, "EN")
                    Errors.EmailDiagnostics(excException, "RegisterforEvent Admin Preview IntroPage")

                    Me.cvGeneral.IsValid = False
                End If

            End Try
        End Sub


Private Sub PopReport(ByVal sType As String, Optional ByVal sFormat As String = "")
            'I get all the data for the current event
            'I format it into XML so I can deal easier with records
            'i create and xmlreader which holds the xml
            'the xml reader is then used to populate a dataset making the data easier to deal with.
            'if summary is choosen the dataset is
            'used  as datasource for a datagrid
            'if excel or csv is choosen the ds is passed to relevant function which processes it into the desired format.

            'sType determines if we want all data or only summary
            'I check the strXML if it has data each time
            'and proceed only if there is data

            Dim strXML As String 'holds the XML markup returned from function
            Dim xmlrder As XmlTextReader
            Dim ds As New DataSet
            '      Dim dt As New DataTable
            Try
                Select Case sType.ToUpper
                    Case "FULL"

                        Select Case sFormat.ToUpper
                            Case "EXCEL"
                                'get the event data in XML format
                                strXML = GetFullReport(Session("RegEventID"))
                                If strXML.Length > 0 Then
                                    xmlrder = New XmlTextReader(strXML, System.Xml.XmlNodeType.Document, Nothing)
                                    xmlrder.ReadOuterXml() 'xml in to xmlreader

                                    ds.ReadXml(xmlrder) 'put data in dataset

                                    CreateExcel(ds)


                                End If
                                'Case "EXCELCC"
                                'get the event data in XML format with CreditCard
                                'strXML = GetFullReportCC(Session("RegEventID"))
                                'If strXML.Length > 0 Then
                                'xmlrder = New XmlTextReader(strXML, System.Xml.XmlNodeType.Document, Nothing)
                                'xmlrder.ReadOuterXml() 'xml in to xmlreader

                                'ds.ReadXml(xmlrder) 'put data in dataset

                                'CreateExcel(ds)


                                'End If
                            Case "CSV"
                                strXML = GetFullReportCC(Session("RegEventID"))
                                If strXML.Length > 0 Then
                                    xmlrder = New XmlTextReader(strXML, System.Xml.XmlNodeType.Document, Nothing)
                                    xmlrder.ReadOuterXml()

                                    ds.ReadXml(xmlrder)  'put data in dataset
                                    CreateCSVFile(ds)
                                    ' TextBox1.Text = strXML 'testing only
                                End If
                        End Select
                        'no longer in use but i leave it here in case
                    Case "SUMMARY"
                        Select Case sFormat.ToUpper
                            Case "EXCEL"
                                strXML = GetSummaryReport(Session("RegEventID"))
                                If strXML.Length > 0 Then
                                    xmlrder = New XmlTextReader(strXML, System.Xml.XmlNodeType.Document, Nothing)
                                    xmlrder.ReadOuterXml()

                                    ds.ReadXml(xmlrder)  'put data in dataset
                                    CreateExcel(ds)
                                End If
                                'Case "EXCELCC"
                                'strXML = GetSummaryReport(Session("RegEventID"))
                                'If strXML.Length > 0 Then
                                'xmlrder = New XmlTextReader(strXML, System.Xml.XmlNodeType.Document, Nothing)
                                'xmlrder.ReadOuterXml()

                                'ds.ReadXml(xmlrder)  'put data in dataset
                                'CreateExcel(ds)
                                'End If
                            Case "CSV"
                                strXML = GetSummaryReport(Session("RegEventID"))
                                If strXML.Length > 0 Then
                                    xmlrder = New XmlTextReader(strXML, System.Xml.XmlNodeType.Document, Nothing)
                                    xmlrder.ReadOuterXml()

                                    ds.ReadXml(xmlrder)  'put data in dataset
                                    CreateCSVFile(ds)
                                End If
                        End Select

                End Select

                '    ds.Clear()
                '    ds.Dispose()
                'ds = Nothing
            Catch excException As Exception
                If Not TypeOf excException.GetBaseException Is System.Threading.ThreadAbortException Then

                    Me.cvGeneral.ErrorMessage = Errors.UserFriendlyMessage(excException, "EN") 'Session("GenErrorText") ' 
                    Errors.EmailDiagnostics(excException, "RegisterforEvent Admin Preview IntroPage")

                    Me.cvGeneral.IsValid = False
                End If

            Finally
                xmlrder.Close()
                ds.Clear()
                ds.Dispose()
                ds = Nothing
            End Try


        End Sub



Public Sub CreateExcel(ByVal ds As DataSet)

            Dim xlsExport As OWC11.SpreadsheetClass = New OWC11.SpreadsheetClass

            Dim numbercols As Integer
            Dim myRow As DataRow
            Dim myCol As DataColumn
            Dim intRowCounter As Integer = 1
            Dim intColCounter As Integer
            Dim strOtherPath As String
            Dim strFilename As String
            Dim strDateTime As String
            Dim sEventPath As String

            Try



                strDateTime = Format(Date.Now, "yyyyMMMddhhmm") 'used in excel file name

                sEventPath = "Ev" & Session("RegEventid")
                strOtherPath = Request.ServerVariables.Item("APPL_PHYSICAL_PATH")
                strOtherPath = strOtherPath & "EventImages\" & sEventPath & "\"


                'handle of the directory to save report file in
                'if don't exist I need to create it.

                Dim di As DirectoryInfo
                di = New DirectoryInfo(strOtherPath)
                If Not di.Exists Then
                    di.Create()
                End If

                Dim dtExcel As DataTable = ds.Tables(0)

                Dim currRows() As DataRow = dtExcel.Select(Nothing, Nothing, DataViewRowState.CurrentRows)

                If (currRows.Length < 1) Then
                    'No Current Rows Found
                Else
                    'rows found
                    'write the column names to the spreadsheet
                    intColCounter = 1
                    intRowCounter = 1


                    For Each myCol In dtExcel.Columns
                        xlsExport.ActiveSheet.Cells(intRowCounter, intColCounter) = myCol.ColumnName.ToString
                        intColCounter = intColCounter + 1
                    Next

                    intRowCounter = intRowCounter + 1 'go to second row for writing data
                    Dim s As String
                    'iterate through the columns in each row and write the contents to a table cell
                    For Each myRow In dtExcel.Rows
                        intColCounter = 1
                        For Each myCol In dtExcel.Columns
                            s = myRow(myCol).ToString()
                            xlsExport.ActiveSheet.Cells(intRowCounter, intColCounter) = "'" & s.Replace(vbCrLf, " ")
                            intColCounter = intColCounter + 1
                        Next
                        intRowCounter = intRowCounter + 1
                    Next
                End If


                strFilename = Session("RegeventName")
                strFilename = strFilename & strDateTime.ToUpper & ".xls"
                lblFileName.Text = strFilename

                'Export the spreadsheet
                ' xlsExport.ActiveSheet.Application.Export(strOtherPath & strFilename, OWC11.SheetExportActionEnum.ssExportActionNone)
                xlsExport.ActiveSheet.Application.Export(strOtherPath & strFilename, OWC11.SheetExportActionEnum.ssExportActionNone, OWC11.SheetExportFormat.ssExportXMLSpreadsheet)

            Catch excException As Exception
                If Not TypeOf excException.GetBaseException Is System.Threading.ThreadAbortException Then


                    Me.cvGeneral.ErrorMessage = Session("GenErrorText") ' Errors.UserFriendlyMessage(excException, "EN")
                    Errors.EmailDiagnostics(excException, "RegisterforEvent Admin Preview IntroPage")

                    Me.cvGeneral.IsValid = False
                End If

            Finally
                myRow = Nothing
                myCol = Nothing

            End Try
        End Sub

Open in new window

Avatar of Jarrod
Jarrod
Flag of South Africa image

This is because the com object you are using is 32 bit.
 
So whats happening is: You have compiled to "Any CPU " or to x64 - this compiles ok, because VS does not know that the com object is 32 bit. When your app runs on a 64bit box it runs in 64 bit mode. Then when you try and call your com object the com trys to run at 32 bit - the architecture does not allow this.
 
You have a few options:
1. Get a 64 bit or "Any CPU" version of your com object (in my case this was not possible as the developers have not yet released one)
2. Right click your project file in vs - > properties and in the build tab change the config to x86 ( This will not affect running on a 64 bit box - it will still run - unless your app uses more than 4gb of ram)
 
What you need to do is right click on your po
Have you Enabled the "Enable 32 Bit Application " in your Application Pool ?
BTW:
if you are running this on IIS7 - you will need to select : enable 32-bit application in the application pool.
Avatar of mattegol

ASKER

Am I at the right place for option 2?
untitled.bmp
Go to iis7 above websites is a application pool node. Select deafault app pool and right click for advanced properties. Then locate the setting : enable 32-bit applications
Open the IIS Manager by executing 'inetmgr' command in run window
Expand the Node (Computer Name )
you will get "Application Pool" where you can get the information about all the pools

Locate your Application from the WebSites list there you can find the "Application Pool" for your Application select it and enable the Property as given in this link
http://blog.davidyack.com/journal/2008/5/19/iis7-and-32bit-applications.html
That one is already fixed, I meant for option 2

2. Right click your project file in vs - > properties and in the build tab change the config to x86 ( This will not affect running on a 64 bit box - it will still run - unless your app uses more than 4gb of ram)

Have you enabled the 32 bit Applicaion ?
ASKER CERTIFIED SOLUTION
Avatar of princeatapi
princeatapi
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial