I use this code as a Workarround, maybe you should use it or improve by using an open source XML/Excel validator :
public bool TryParse(string s)
{
try
{
//RegistryKey key = Registry.ClassesRoot;
//RegistryKey excelKey = key.OpenSubKey("Excel.Application");
//bool excelInstalled = excelKey == null ? false : true;
if (xlApp == null)
xlApp = new Microsoft.Office.Interop.Excel.Application();
System.Object UpdateLinks,
ReadOnly = false,
Format,
Password,
WriteResPassword,
IgnoreReadOnlyRecommended,
Origin,
Delimiter,
Editable,
Notify,
Converter,
AddToMru,
Local,
CorruptLoad = XlCorruptLoad.xlRepairFile;
object misval = System.Reflection.Missing.Value;
if (xlApp == null)
{
MessageBox.Show(System.Reflection.MethodBase.GetCurrentMethod().Name + " EXCEL could not be started. Check that your office installation and project references are correct.");
return true;
}
//xlApp.ShowStartupDialog = false;
xlApp.Visible = false;
//xlApp.ShowWindowsInTaskbar = true;
if (btest) MessageBox.Show(System.Reflection.MethodBase.GetCurrentMethod().Name + " xlApp.Workbooks.Open->");
wb = xlApp.Workbooks.Open(s, misval, ReadOnly,
misval, misval, misval, misval, misval, misval, misval, misval, misval, misval, misval, CorruptLoad);
if (btest) MessageBox.Show(System.Reflection.MethodBase.GetCurrentMethod().Name + " xlApp.Workbooks.Open<-");
if (wb == null)
{
MessageBox.Show("XCL file is invalid.");
if (btest) MessageBox.Show(System.Reflection.MethodBase.GetCurrentMethod().Name + " wb == null");
xlApp.Quit();
return false;
}
wb.Close(false, null, null);
xlApp.Quit();
wb = null;
/*XmlDocument result = new XmlDocument();
result.Validate(validationEventHandler);*/
return true;
}
catch (System.AccessViolationException ex)
{
if (btest) MessageBox.Show(System.Reflection.MethodBase.GetCurrentMethod().Name + " FileNotFoundException : " + ex.ToString());
MessageBox.Show("Check file : EXCEL could not be started. Check that your office installation and project references are correct.");
}
catch (COMException ex)
{
MessageBox.Show(System.Reflection.MethodBase.GetCurrentMethod().Name + " XML file misformatted : try to repair...");
return false;
}
catch (FileNotFoundException ex)
{
MessageBox.Show(System.Reflection.MethodBase.GetCurrentMethod().Name + " FileNotFoundException : " + ex.ToString());
}
catch (XmlException ex)
{
MessageBox.Show(System.Reflection.MethodBase.GetCurrentMethod().Name + " XML file misformatted : " + ex.ToString());
}
catch (System.ApplicationException aex)
{
MessageBox.Show(System.Reflection.MethodBase.GetCurrentMethod().Name + " XML file misformatted : " + aex.ToString());
}
finally
{
if(xlApp != null) xlApp.Quit();
if (btest) MessageBox.Show(System.Reflection.MethodBase.GetCurrentMethod().Name + " finally");
}
return true;
}