Old format or invalid type library

Add-in Express™ Support Service
That's what is more important than anything else

Old format or invalid type library
 
Michael Bendtsen




Posts: 58
Joined: 2007-06-27
I get the following error when ever I try to access some data in Excel.

I have read that the solution is to change the culture, but isn't there a better solution to this?

[2764] 10-01-2008 16:22:29: [officeclient]AddinExpress.MSO.ADXExternalException: An error has occured in the code of the add-in. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x80028018): Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))
[2764] --- End of inner exception stack trace ---
[2764] at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
[2764] at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
[2764] at AddinExpress.MSO.ADXAddinModule.ExcelApplicationEvents_SinkHelper.DoWindowActivate(Object workbook, Object window)
[2764] at AddinExpress.MSO.ADXAddinModule.Extensibility.IDTExtensibility2.OnStartupComplete(Array& custom)
[2764] at Excel._Workbook.get_FullName()
Posted 10 Jan, 2008 11:14:42 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Michael.

Another solution is to use the late binding and set the culture directly in the add-in code.

E.g.
hostVersion = Convert.ToString(applicationObject.GetType().InvokeMember(
"Version", BindingFlags.GetProperty, null, applicationObject, null, CultureInfo.CurrentUICulture));
Posted 11 Jan, 2008 09:56:47 Top
marwa hussein




Posts: 1
Joined: 2008-02-21
Dear all
I build a new application using c#.net2005 to read excel file I write the following code but it gives me a run time error
((Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))

can any one help me

using System;
using System.Reflection; // For Missing.Value and BindingFlags
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Resources;
using Microsoft.Office.Core;
using System.IO;
using System.Configuration;
using System.Data.SqlClient;
using Excel;

namespace ReadExcelFiletest
{
public partial class Form1 : Form
{
private Excel.Application ExcelObj = null;
private string strConn = "";
private string[,] myArray = new string[5000, 2];
private int myarrayindex;
public Form1()
{
InitializeComponent();
}

private void btnBrowse_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
this.txtLocation.Text = openFileDialog1.FileName;
}

private void btnUpdate_Click(object sender, EventArgs e)
{
// string Path = @"c:\test.xls";
string MyPath = this.txtLocation.Text.Trim().ToString();

// initialize the Excel Application class
Excel.ApplicationClass app = new ApplicationClass();
// create the workbook object by opening the excel file.
Excel.Workbook workBook = app.Workbooks.OpenMyPath , 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
// get the active worksheet using sheet name or active sheet
Excel.Worksheet workSheet = (Excel.Worksheet)workBook.ActiveSheet;
int index = 0;
// This row,column index should be changed as per your need.
// i.e. which cell in the excel you are interesting to read.
object rowIndex = 1;
object colIndex1 = 1;
object colIndex2 = 2;
object colIndex3 = 3;
myarrayindex = 0;

try
{
while (((Excel.Range)workSheet.Cells[rowIndex, colIndex1]).Value2 != null)
{

rowIndex = index + 1;
string PartNO = ((Excel.Range)workSheet.Cells[rowIndex, colIndex1]).Value2.ToString();
string Price = ((Excel.Range)workSheet.Cells[rowIndex, colIndex2]).Value2.ToString();

myArray[myarrayindex, 0] = PartNO;
myArray[myarrayindex, 1] = Price;
ListViewItem lvi = new ListViewItem();
lvi.Text = Convert.ToString(index + 1);
lvi.SubItems.Add(PartNO);
lvi.SubItems.Add(Price);
this.listView1.Items.Add(lvi);


myarrayindex++;
index++;

}
}
catch (Exception ex)
{
app.quit();

}
}
}
}
Posted 21 Feb, 2008 04:57:48 Top
Michael Bendtsen




Posts: 58
Joined: 2007-06-27
I uses this class to switch from "en-US" to my original language.

You can use the class by calling:

using(new ExcelUILanguageHelper())
{
    // calling excel specific code i.e. app.Workbooks.Open(...);
}




Here is the class:


    class ExcelUILanguageHelper : IDisposable
    {
        private CultureInfo m_CurrentCulture;

        public ExcelUILanguageHelper()
        {
            // save current culture and set culture to en-US
            m_CurrentCulture = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
        }

        #region IDisposable Members

        public void Dispose()
        {
            // return to normal culture
            Thread.CurrentThread.CurrentCulture = m_CurrentCulture;
        }

        #endregion
    }
Posted 21 Feb, 2008 05:11:39 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Marwa.

Please try to use the InvokeMember method with the CultureInfo.CurrentUICulture parameter.
Posted 21 Feb, 2008 08:53:01 Top