Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))

when run my project get this error please help me solve the problem

What I have tried:

  1  Private Function GetXlUsedRange(ByVal filePath As String) As Object(,)
  2          Dim xlApp As Excel.Application
  3          Dim xlWorkbooks As Excel.Workbooks
  4          Dim xlWorkbook As Excel.Workbook
  5          Dim xlSheets As Excel.Sheets
  6          Dim xlWorkSheet As Excel.Worksheet
  7          Dim xlRange As Excel.Range
  8  
  9  
 10          xlApp = New Excel.Application
 11          xlWorkbooks = xlApp.Workbooks
 12          xlWorkbook = xlWorkbooks.Open(filePath)
 13          xlSheets = xlWorkbook.Worksheets
 14          xlWorkSheet = CType(xlSheets("Data"), Excel.Worksheet)
 15          xlRange = xlWorkSheet.UsedRange
 16  
 17          Dim rangeValues(,) As Object
 18          rangeValues = CType(xlRange.Value, Object(,))
 19  
 20  
 21          xlWorkbook.Close()
 22          xlWorkbooks.Close()
 23          xlApp.Quit()
 24  
 25          releaseObject(xlRange)
 26          releaseObject(xlWorkSheet)
 27          releaseObject(xlSheets)
 28          releaseObject(xlWorkbook)
 29          releaseObject(xlWorkbooks)
 30          releaseObject(xlApp)
 31  
 32          Return rangeValues
 33      End Function
 34  
 35      Private Sub releaseObject(ByVal obj As Object)
 36          Try
 37              System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
 38              obj = Nothing
 39          Catch ex As Exception
 40              obj = Nothing
 41          End Try
 42      End Sub
 43  
 44      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 45          Dim usedRange(,) As Object = GetXlUsedRange("C:\Users\Jayanta Modak\Desktop\import.xls")
 46  
 47          Dim fromRow As Integer = 7
 48          PopulateListView(usedRange, fromRow)
 49      End Sub
Posted
Updated 23-Dec-23 5:05am
v2
Comments
Richard MacCutchan 23-Dec-23 10:54am    
Which line in the above code causes the error?
Jayanta Modak 23-Dec-23 14:14pm    
xlWorkbook = xlWorkbooks.Open(filePath)
Richard MacCutchan 24-Dec-23 3:24am    
Maybe the filepath is wrong.
Jayanta Modak 24-Dec-23 8:25am    
Sir file path is right
Richard MacCutchan 24-Dec-23 9:06am    
Have you checked the suggestion in Solution 2 below?

To be honest, we can't help you with that little info, and probably can't give you a "full solution" at all - simply because we have no way to access your spreadsheet on your system while you code is running, and you need that to begin diagnosing the problem.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

When you know which line causes the exception, you can look at the data you passed to it, and what it is doing (you will probably need to re-run your app with a breakpoint set on the failing line). The data should give you clues as to the problem.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
Comments
Jayanta Modak 23-Dec-23 14:15pm    
https://ibb.co/frjdGq3
OriginalGriff 24-Dec-23 1:28am    
I don't follow random link shorteners to unknown content, and neither will most of the people here.
What did the debugger show you was going on?
The issue may caused by third-party Excel COM plug-in, refer to the provided link, and it is anticipated that your issue will be resolved.
https://superuser.com/questions/1124945/excel-interop-remote-procedure-call-failed-or-rpc-e-serverfault[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900