I am currently facing an issue in my program that is created for reading .xls and .csv files and match two files against each other. When using .xls files everything is fine and works as expected. However, if I am using .csv files, I always receive this error:
Fatal error. Internal CLR error. (0x80131506) An unhandled exception of type 'System.ExecutionEngineException' occurred in Unknown Module.
I am reading the files using the "get_Value" and storing the results in an object[,]. The xls and csv files are the same - content wise (same rows and columns). The csv uses as delimiter ",".
When I take a look directly at the object "valueArrayComp" I can see every string correctly even though I did not specificy the delimiter explicitly:
But as soon as I am trying to process the data for example by converting it back to a string or a tuple, I receive the above mentioned error.
What am I missing here? I read some threads here as well where it states that the error might have happened earlier than when the actual exception gets thrown. However, I am still not able to stop the actual error.
My code looks like this:
Workbook wbCol;
Worksheet wsCol;
Application excelComp;
wbCol = wbsCol.Open(compareFile);
excelComp.DisplayAlerts = false;
wsCol = (Worksheet)wbCol.Worksheets[1];
int addC = 2;
int j = 2;
foreach (Worksheet wsC in wbCol.Worksheets)
{
Microsoft.Office.Interop.Excel.Range excelRangeComp = wsC.UsedRange;
Console.WriteLine(wsC.Cells[2,2]); //this is inserted and a test and working
object[,] valueArrayComp = (object[,])excelRangeComp.get_Value(XlRangeValueDataType.xlRangeValueDefault);
string test = Convert.ToString(valueArrayComp[2, 2]); //error is thrown here, as soon as I am trying to access the object
Thanks a lot for any ideas!
User contributions licensed under CC BY-SA 3.0