none
System.runtime.interopservices.comexception (0x80010105) RRS feed

  • Question

  • Hello everyone, i've run into a problem when i'm trying to open an Excel file, this is my error log output:
    I've read all related subjects on this forum and google, none fit to my problem, except that if i replace in my code:

    xlWorkBook = xlApp.Workbooks.Open(textBox1.Text, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0) with

                xlWorkBook = xlApp.Workbooks.Open(textBox1.Text, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, Microsoft.Office.Interop.Excel.XlCorruptLoad.xlExtractData)

    It let me to open it and get data, but destroy the format of cells... Below is the error log :

    See the end of this message for details on invoking
    just-in-time (JIT) debugging instead of this dialog box.

    ************** Exception Text **************
    System.Runtime.InteropServices.COMException (0x80010105): The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))
       at Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)
       at testCompareExcel.Form1.button2_Click(Object sender, EventArgs e) in d:\Serban A\pentru facultate\testCompareExcel\testCompareExcel\Form1.cs:line 34
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


    ************** Loaded Assemblies **************
    mscorlib
        Assembly Version: 4.0.0.0
        Win32 Version: 4.6.1076.0 built by: NETFXREL3STAGE
        CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
    ----------------------------------------
    testCompareExcel
        Assembly Version: 1.0.0.0
        Win32 Version: 1.0.0.0
        CodeBase: file:///D:/Serban%20A/pentru%20facultate/testCompareExcel/testCompareExcel/bin/Debug/testCompareExcel.exe
    ----------------------------------------
    System.Windows.Forms
        Assembly Version: 4.0.0.0
        Win32 Version: 4.6.1055.0 built by: NETFXREL2
        CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
    ----------------------------------------
    System
        Assembly Version: 4.0.0.0
        Win32 Version: 4.6.1075.0 built by: NETFXREL3STAGE
        CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
    ----------------------------------------
    System.Drawing
        Assembly Version: 4.0.0.0
        Win32 Version: 4.6.1068.2 built by: NETFXREL3STAGE
        CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
    ----------------------------------------
    System.Configuration
        Assembly Version: 4.0.0.0
        Win32 Version: 4.6.1055.0 built by: NETFXREL2
        CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
    ----------------------------------------
    System.Core
        Assembly Version: 4.0.0.0
        Win32 Version: 4.6.1055.0 built by: NETFXREL2
        CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
    ----------------------------------------
    System.Xml
        Assembly Version: 4.0.0.0
        Win32 Version: 4.6.1067.0 built by: NETFXREL3STAGE
        CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
    ----------------------------------------
    Microsoft.CSharp
        Assembly Version: 4.0.0.0
        Win32 Version: 4.6.1055.0
        CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.CSharp/v4.0_4.0.0.0__b03f5f7f11d50a3a/Microsoft.CSharp.dll
    ----------------------------------------
    Microsoft.Office.Interop.Excel
        Assembly Version: 12.0.0.0
        Win32 Version: 12.0.6600.1000
        CodeBase: file:///C:/Windows/assembly/GAC/Microsoft.Office.Interop.Excel/12.0.0.0__71e9bce111e9429c/Microsoft.Office.Interop.Excel.dll
    ----------------------------------------
    office
        Assembly Version: 12.0.0.0
        Win32 Version: 12.0.6425.1000
        CodeBase: file:///C:/Windows/assembly/GAC/office/12.0.0.0__71e9bce111e9429c/office.dll
    ----------------------------------------

    ************** JIT Debugging **************
    To enable just-in-time (JIT) debugging, the .config file for this
    application or computer (machine.config) must have the
    jitDebugging value set in the system.windows.forms section.
    The application must also be compiled with debugging
    enabled.

    For example:

    <configuration>
        <system.windows.forms jitDebugging="true" />
    </configuration>

    When JIT debugging is enabled, any unhandled exception
    will be sent to the JIT debugger registered on the computer
    rather than be handled by this dialog box.


    Any suggestions ?

    I mention that my excel file has over 4k cells with different format style, interior colored and different string dimensions in cells, maybe some of them over 100 chars.

    Thank you.

    Tuesday, December 6, 2016 4:54 PM

All replies

  • You might look at the following way to access sheet information

    https://1drv.ms/u/s!AtGAgKKpqdWjiA2buRRh_LsKsqqF

    In this project (link above) I show how to properly open, get to the point of working with sheets, release all objects in a simple console app which makes use of a class project that does all the Excel work.

    Note: Don't run the executable in the solution, instead do a build on the project then run it. If there are errors on build that most likely means your version of Excel is different than mine so you will need to change the Excel reference under project references to match your version of Excel.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Tuesday, December 6, 2016 5:23 PM
  • Hi serbanov,

    Thank you for posting here.

    Since your problem is more related to Excel, I will move it to Excel for Developers Forum for support.

    The Visual C# Forum discuss and ask the question about the C# programming language, IDE, libraries, samples and tools.

    If you have some grammar or code errors, please feel free to contact us. We will try our best to give you a solution.

    Thanks for your understanding and cooperation.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 7, 2016 2:41 AM
  • Hello Karen, thank you for your reply, the thing is that it sees as a corrupt file and tries to repair it when i open it, that's the cause why it won't work with the code i've used above, any idea why it sees it as a corupt file ??
    Wednesday, December 7, 2016 7:04 AM
  • Hello Karen, thank you for your reply, the thing is that it sees as a corrupt file and tries to repair it when i open it, that's the cause why it won't work with the code i've used above, any idea why it sees it as a corupt file ??

    I don't know why your methods are not working. You could try using the methods I have suggested in the link, see if the same happens.

    Also, in regards to the highlights, have not seen this before and I have done a great deal with Excel automation. Not saying it's a problem but curious about using a tab escape. 


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, December 7, 2016 10:17 AM
  • Those highlighted parts i've taken from c-sharp corner website ... and i saw many of them using them and didn't complain about it, i don't know actually what should i do, from what i've seen in your code, it gives me a lil headache, i'm not such a good programmer since i'm at the beginning.

    Wednesday, December 7, 2016 11:55 AM
  • Working with Excel has it's challenges and with that one needs to understand when taking code from the web what it does rather than simply using it which is why at this point you are having issues understanding my code or attempting to understand code taken from the web page.

    Perhaps you should fully explain what you are trying to do with being as detailed as possible, that way myself and others can better assist you.

    Let's say all you want is to read data from a sheet, an easier way would be to use OleDb managed data provider while if you need to read data and formulas is not possible with OleDb.

    Writing to Excel can be done with both automation and OleDb but depending on exactly what you need can prove challenging too.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, December 7, 2016 1:52 PM
  • Well Karen, what i'm trying to do is creating an Excel file with informations gathered from a project ( i'm working into a multinational company ) and i need to format cells in a specific way, for example coloring them different depending of the information type. From what i've found on internet the problem i'm encountering it's due to the high number of cells formatted with different style. The algorithm i've written to get informations brings me a lot of data that i need to put in Excel, over 4000 cells.. and the way i try to write and read data in Excel is using Excel Interop.

    The idea is that I've read your code and understood almost all lines of them, it's not that i don't understand your code, the thing is that i can't use your code since my excel file that i use to read is treated like a corrupt file and the only way to open it and see data is using  Microsoft.Office.Interop.Excel.XlCorruptLoad.xlExtractData) as a parameter to function Open().

    I need to build a tool that generates an Excel file ( first generation ) and use this file for a following generation, like :

    Sheet1=All generations - sheet used for comparing versions of generations,
    Sheet2 = First generation with the associated data,
    Sheet3 = Second generation etc  ...

    What i need to do after first generation is to modify first sheet and compare data from Sheet2 with Sheet3, for a 3rd generation, compare data from Sheet3 with Sheet4, for a N generation, compare data from SheetN-1 with SheetN.

    Sorry if i'm lacking the manner to express it as it should be, i'm trying to improve my english as much as i can.
    Thursday, December 8, 2016 7:37 AM
  • Hi,

    It seems that your file is generated from other project. I would suggest you open the file manually and open other files using the code to check what causes the issue.

    If the file is corrupt even you open it manually, I think you need to check the project which created this file.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, December 8, 2016 8:23 AM
    Moderator
  • Celeste, if i open it manually ( simple double click on it ) it's no problem , it opens it, the code i've posted is from a subprogram that i will implement later in the big project, that's the way i've learned to programm in oop, before going to the big project, try it in a smaller program.

    The problem is when i try to open the file from C# WinForm using the line i've posted because it sees it as a corrupt file and i've given you the informations i've got till now from surfing on internet and trying to solve this issue ... i don't have the link anymore, but someone said that if the cells has a string with over 255 chars or it has too many cells with different formatting style it will make the file corrupt and can't open it .

    If i try to open the file using, Microsoft.Office.Interop.Excel.XlCorruptLoad.xlExtractData it let me get my data information but, it's a big BUT, i've got a pop-up box with the following content:

    Repairs to 'name_of_excel_file.xls' :

    Excel was able to open the file by repairing or removing the unreadable content.

    Excel recovered your formulas and cell values, but some data may have been lost.

    .....
    Thursday, December 8, 2016 9:36 AM
  • Hi,

    Do you run the project in the server-side?

    Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment. For more information, please visit Considerations for server-side Automation of Office

    I notice the extension of your Excel file is .XLS. Is it an Excel97-2003 Workbook? I would suggest you convert it into the new file format xlsx. Then you could use Open XML library to retrieve the value and format.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 12, 2016 7:09 AM
    Moderator
  • Hello, i've used ".xls" because i didn't know about something like Open XML or ClosedXML, and i do not think it's a servers side automation of Office, i'm trying to build a tool in WinForm C# ... maybe i am doing something wrong and i do not know what... i will try to use ClosedXML and see what i can do.
    Tuesday, December 13, 2016 12:24 PM
  • Hi,

    If you use Workbook.Open(filename) to open the workbook, what exception would you get?

    If possible, I suggest you share us a sample file to test.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, December 15, 2016 1:51 AM
    Moderator