Results 1 to 15 of 15

Thread: Could not load file or assembly 'Microsoft.Office.Interop.Excel'

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    58

    Could not load file or assembly 'Microsoft.Office.Interop.Excel'

    I have a program that reads data from excel.

    I use:
    Imports Microsoft.Office.Interop
    as well as a Reference from the "COM" tab called "Microsoft Excel 11.0 Object Library"

    I built my program then copied the .exe from the \bin\Debug folder to a location on my company's server. I then double clicked the .exe and it ran as I expected it would.

    My boss then tried (from another computer) and he gets this error:
    Code:
    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 'Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.
    File name: 'Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
       at timesheetGUI.Form1.PopulateCheckBoxArea()
       at timesheetGUI.Form1.bttnScanWorksheets_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].
    
    
    
    ************** Loaded Assemblies **************
    mscorlib
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.3603 (GDR.050727-3600)
        CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
    ----------------------------------------
    timesheetGUI
        Assembly Version: 1.0.0.0
        Win32 Version: 1.0.0.0
        CodeBase: file:///C:/Documents%20and%20Settings/rwood/Desktop/Temp/Timesheet/timesheetGUI.exe
    ----------------------------------------
    Microsoft.VisualBasic
        Assembly Version: 8.0.0.0
        Win32 Version: 8.0.50727.3053 (netfxsp.050727-3000)
        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
    ----------------------------------------
    System
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
    ----------------------------------------
    System.Windows.Forms
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
    ----------------------------------------
    System.Drawing
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
    ----------------------------------------
    System.Configuration
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
    ----------------------------------------
    System.Xml
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.3082 (QFE.050727-3000)
        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
    ----------------------------------------
    System.Runtime.Remoting
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
    ----------------------------------------
    
    ************** JIT Debugging **************
    To enable just-in-time (JIT) debugging, the .config file for this
    application or computer (machine.config) must have the
    jitDebugging value set in the system.windows.forms section.
    The application must also be compiled with debugging
    enabled.
    
    For example:
    
    <configuration>
        <system.windows.forms jitDebugging="true" />
    </configuration>
    
    When JIT debugging is enabled, any unhandled exception
    will be sent to the JIT debugger registered on the computer
    rather than be handled by this dialog box.

    Could someone explain why it works for me and not him? I am new to references but I feel that the problem is there.

  2. #2
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Could not load file or assembly 'Microsoft.Office.Interop.Excel'

    Just ship the office dll with the exe...

    *EDIT* - The dll should be in the Debug\Release folder

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Could not load file or assembly 'Microsoft.Office.Interop.Excel'

    No... the problem was your deployment process... you have the MS Office Interop files installed. Your boss doesn't. Look back in the bin folder.... look for other DLLs see if they are in there.

    I think what you need are the PIAs... as described in this trhead:
    http://www.vbforums.com/showthread.p...&highlight=PIA
    Or better yet - we have an entry in the FAQ : http://www.vbforums.com/showthread.p...&highlight=PIA

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    58

    Re: Could not load file or assembly 'Microsoft.Office.Interop.Excel'

    Quote Originally Posted by mickey_pt View Post
    Just ship the office dll with the exe...

    *EDIT* - The dll should be in the Debug\Release folder
    There is no dll files there.
    edit: this is not a webserver, just a file server.

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Could not load file or assembly 'Microsoft.Office.Interop.Excel'

    doesn't matter... you still need the PIAs on the computer that is running the app... in the threads I linked to (well the first one), they were doing some stuff on the server side, which is why they need to be installed on the webserver.

    In your case, the users are going to need Office installed, then the PIAs installed (since it wasn't in the bin directory, it's possible the PIA files were installed into the GAC).

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Could not load file or assembly 'Microsoft.Office.Interop.Excel'

    @techgnome
    Maybe yes and maybe not
    I have the same problem with an application, just shipped the wrong version of the assembly and i had an error similar to this one...

    And i'm assuming that the computer all have the ms office installed.

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  7. #7

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    58

    Re: Could not load file or assembly 'Microsoft.Office.Interop.Excel'

    Quote Originally Posted by techgnome View Post
    doesn't matter... you still need the PIAs on the computer that is running the app... in the threads I linked to (well the first one), they were doing some stuff on the server side, which is why they need to be installed on the webserver.

    In your case, the users are going to need Office installed, then the PIAs installed (since it wasn't in the bin directory, it's possible the PIA files were installed into the GAC).

    -tg
    I don't know if it will be possible to install the PIA's on every computer running the app. I will need to include it with the app.


    If I look under my references, and choose properties for the excel one I get the path as this:
    C:\WINDOWS\assembly\GAC\Microsoft.Office.Interop.Excel\11.0.0.0__71e9bce111e9429c\Microsoft.Office.I nterop.Excel.dll

    It would be nice if I could edit that so it is just:
    Microsoft.Office.Interop.Excel.dll
    and then I throw that dll in the folder with my app.

    The problem is the path seems to be read only, and in explorer there is no GAC folder.



    Quote Originally Posted by mickey_pt View Post
    And i'm assuming that the computer all have the ms office installed.
    Yes, you can assume that.

  8. #8
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Could not load file or assembly 'Microsoft.Office.Interop.Excel'

    Are you using the installer, or xcopy?
    You can try to copy directly that dll to the application folder.

    Why do you added the COM version?

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  9. #9

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    58

    Re: Could not load file or assembly 'Microsoft.Office.Interop.Excel'

    Quote Originally Posted by mickey_pt View Post
    Are you using the installer, or xcopy?
    You can try to copy directly that dll to the application folder.

    Why do you added the COM version?
    I use the COM version cause thats what I read I needed and there is no .NET version.

    Not sure what you mean by installer or xcopy.

  10. #10
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Could not load file or assembly 'Microsoft.Office.Interop.Excel'

    Imports Microsoft.Office.Interop
    as well as a Reference from the "COM" tab called "Microsoft Excel 11.0 Object Library"
    Remove the COM reference and add the same reference but this time in the NET references, then compile your application, and then you should see a new dll file in the debug/release folder.

    Installer it's a Setup Project (MSI File)
    XCopy, just copy the files directly without any kind of setup.

    BTW, what VS version are you using?
    In 2008 version you can found the references here, default installation directory C:\Program Files\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office11
    Last edited by mickey_pt; Apr 16th, 2010 at 11:05 AM. Reason: Info

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  11. #11

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    58

    Re: Could not load file or assembly 'Microsoft.Office.Interop.Excel'

    Quote Originally Posted by mickey_pt View Post
    Remove the COM reference and add the same reference but this time in the NET references, then compile your application, and then you should see a new dll file in the debug/release folder.

    Installer it's a Setup Project (MSI File)
    XCopy, just copy the files directly without any kind of setup.

    BTW, what VS version are you using?
    In 2008 version you can found the references here, default installation directory C:\Program Files\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office11
    When I go projects-> add reference there is no "Microsoft Excel 11.0 Object Library" under the ".NET" tab.

  12. #12
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Could not load file or assembly 'Microsoft.Office.Interop.Excel'

    what version of vs are you using? Express edition?

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  13. #13

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    58

    Re: Could not load file or assembly 'Microsoft.Office.Interop.Excel'

    Quote Originally Posted by mickey_pt View Post
    what version of vs are you using? Express edition?
    2008 express.

  14. #14
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Could not load file or assembly 'Microsoft.Office.Interop.Excel'

    That's why you don't have the .NET version...
    So then your application run in your computer and in the server, so the problem must be in your boss pc, the version isn't the same or he/she doesn't have any office...

    Download and install the PIA for Office

    Additional info:
    MSDN
    GAC

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  15. #15

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    58

    Re: Could not load file or assembly 'Microsoft.Office.Interop.Excel'

    Quote Originally Posted by mickey_pt View Post
    That's why you don't have the .NET version...
    So then your application run in your computer and in the server, so the problem must be in your boss pc, the version isn't the same or he/she doesn't have any office...

    Download and install the PIA for Office

    Additional info:
    MSDN
    GAC
    Thanks, that seemed to work. My boss has the same Office products installed as me, so is there any other reason why it didn't work for him?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width