Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am building a few programs for work and require them to import excel files for internal processing. I have no issue doing such.

I have now built and tested the programs. Apon moving the programs to the 2003 server. I am now receiving errors when using the excel interop operations.

I have copied the interop file to the program location (Interop.IWshRuntimeLibrary.dll), this had no success.

I installed .Net 3.5 on the server, which has also not helped.

After pulling my hair out for 30 minutes, I have come to the understanding that I may require office to be installed on the server for the IWSH runtime library to operate.

Whats puzzling me, I do not have office installed on my XP machine at home, yet all these operations work without error.

At home I have Visual Studio 2008 installed, I presume that it contains the libraries required for the IWSH library, therefor allows the code to run at home without error.

Can anyone shed any light for me?

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

************** Exception Text **************
System.IO.FileNotFoundException: Could not load file or assembly 'System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
   at Contact_Manager_Server.UserControls.ExcelFilesourceSelecter.tbFilesource_TextChanged(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnTextChanged(EventArgs e)
   at System.Windows.Forms.TextBoxBase.OnTextChanged(EventArgs e)
   at System.Windows.Forms.Control.set_Text(String value)
   at System.Windows.Forms.TextBoxBase.set_Text(String value)
   at System.Windows.Forms.TextBox.set_Text(String value)
   at Contact_Manager_Server.UserControls.ExcelFilesourceSelecter.btnBrowseFilesource_Click(Object sender, EventArgs e)
   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)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
</pre>
Posted
Comments
Corayzon 6-Aug-10 3:04am    
I have tested some older programs for processing excel data health checks. It uses the same OLE code from the same libraries I wrote about a year ago.

They work fine on the server.

I am stumped.
Corayzon 6-Aug-10 3:14am    
I now added a basic example at the start of the project to get the workbook names from a filename entered via a self made input box.

It processes and gets workbooks in excel file with no issues.

Must be something else underlying causing my problem.

Thanks for your help Christian

If you don't have Excel installed, what do you hope to interop with ? You must have it installed, or it plain would not work. The code you write simply controls Excel via COM, it is not Office, or Excel.
 
Share this answer
 
Update.

I am using OLE connection to retrieve data.

C#
Results.QueryData = new DataTable();
            using (OleDbConnection OleConnection = new OleDbConnection(QueryConfiguration.OleConnectionString))
            {
                OleConnection.Open();
                using (OleDbDataAdapter OleAdapter = new OleDbDataAdapter(QueryConfiguration.SqlStatement, OleConnection))
                    OleAdapter.Fill(Results.QueryData);
                OleConnection.Close();
            }
 
Share this answer
 
I feel like a drongo now.

After more and more repeated testing I have found the cause of my problem.

Old code causing error:

C#
private void tbFilesource_TextChanged(object sender, EventArgs e)
{
    if (tbFilesource.Text == "")
    {
        cbWorkbook.Enabled = false;
    }
    else
    {
        cbWorkbook.Enabled = true;
        cbWorkbook.Items.Clear();
        cbWorkbook.Items.AddRange(
            Excelerater.ExcelQueryConiguration.GetWorkbookSpreadsheets(tbFilesource.Text).ToArray());
    }
}


This appears to generate the error simply because GetWorkbookSpreadsheets method returns a string[] object which is being converted ToArray() as it is passed to the AddRange method of the combobox.


Updated working code:

C#
private void tbFilesource_TextChanged(object sender, EventArgs e)
{
    if (tbFilesource.Text == "")
    {
        cbWorkbook.Enabled = false;
    }
    else
    {
        cbWorkbook.Enabled = true;
        cbWorkbook.Items.Clear();
        cbWorkbook.Items.AddRange(
            Excelerater.ExcelQueryConiguration.GetWorkbookSpreadsheets(tbFilesource.Text));
    }
}



As you can see the GetWorkbookSpreadsheets() method is now not being converted ToArray and now does not cause the error.

I figure this is a problem between .net framework versions.

Even though they report the same versions from the static Environment class.
 
Share this answer
 
Comments
Dalek Dave 6-Aug-10 4:05am    
Always nice when you solve something like that!

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