0

I have a C# program that references a few things, namely Excel and office references. However, on the target machine, Office isn't installed. Is there a way to include the reference/dlls that the program needs in some sort of installation package so that it will work?

Here is the error code I get when I try to run it on someone's machine with Excel 2003. I installed the 2010 Interop from microsoft, but this still happened:

Thread failed to Initialize. System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Office.Interop.Excel, Version=14.0.0.0, Culture=neutral,PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The locaved assembly's manifest definition does not match the assembly reference. (Exception from HRESULT:0x80131040)

WRN: Assembly binding logging is turned OFF

It references this section when the error comes up, and despite being on another computer, it shows a path on my computer where the project is located.

private void bgwFirstProcessThread_DoWork(object sender, DoWorkEventArgs e)
    {
        try
        {
            BackgroundWorker worker;
            worker = (BackgroundWorker)sender;

            //Get the Class object and call the main method
            XlsxThread WO = (XlsxThread)e.Argument;
            WO.ProcessXlsx(worker, e);
        }
        catch (Exception ex)
        {
            MessageBox.Show("Thread failed to Initialize.\n" + ex.ToString());
        }
    }
user3215251
  • 239
  • 1
  • 16
  • http://stackoverflow.com/questions/15285880/how-to-reference-microsoft-office-interop-excel-dll for example. – Mark C. May 20 '14 at 12:51
  • I did that already. But when it loads up the program, it says it can't fine Excel Interop 14.0.0.0 despite my never having included a reference to that one specifically, only 12.0.0.0. I even brought in the DLLs into my .exe folder and made references to them instead, and that at least loaded up the program, but it got to the point where it tries running it, it fails because it can't find the reference file. – user3215251 May 20 '14 at 12:53
  • I was looking for it, but in my References under.Net, it only goes up to 12.0.0.0. – user3215251 May 20 '14 at 13:13
  • Okay, I seem to have found the COM reference, but I can't seem to get rid of it. – user3215251 May 20 '14 at 13:17
  • What do you mean "get rid of it"? And did you test it? – Mark C. May 20 '14 at 13:21
  • I did some research, and when I include the 12.0.0.0, it automatically includes a COM reference to C:\Programs\Microsoft Office\Office14\EXCEL.exe. This is most likely why it's not working on other computers, but I have no idea how to resolve it. – user3215251 May 20 '14 at 13:27

1 Answers1

1

Checkout Microsoft Office Primary Interop Assemblies Redistributable available here.. http://www.microsoft.com/en-us/download/details.aspx?id=3508

This allows you to package Microsoft.Office.Interop assemblies (within bin folder) and reference in code.

But if the functionality in code requires MS Office on target machine, the office installation is a must for desired result.

= And AFAIK - if you want to keep it compatible for multiple office versions, you must include the Interop Assembly of the lowest version you want to support to keep your code compatible for all versions. So you will need Excel 2003 compatible interop assembly version for your need http://www.microsoft.com/en-gb/download/details.aspx?id=20923 And that will limit you from using newer office functionalists such as ribbon menu.

dhalsumit
  • 143
  • 1
  • 1
  • 10
  • I do not have enough reputation to add comment to your question so I am going ahead here.. ========= [I did some research, and when I include the 12.0.0.0, it automatically includes a COM reference to C:\Programs\Microsoft Office\Office14\EXCEL.exe. This is most likely why it's not working on other computers, but I have no idea how to resolve it.] ===== DID YOU CHECK PROJECT PROPERTIES - REFERENCE TAB WHICH LISTS all references... – dhalsumit May 20 '14 at 14:20