How to fix an app using an old InterOp Assembly that can't be removed
-
Thursday, May 24, 2012 2:33 PM
I have a VB Studio 2005 Express app that uses the Excel part of the Office Primary Interop Assemblies (PIA). We used to have Office 2003 and then some of us moved to Office 2007. Now the entire company moved to Office 2010 and what I've noticed is that as people have gotten new machines and run the app, their machines seem to have a copy of the old InterOp Assemblies. The GAC is referenced, but because the assemblies haven't been "installed" they don't appear in "Add or Remove Programs". I've installed the Office 2010 PIA, but the app continues to reference the old PIAs.
I'm stumped. I don't understand how to fix this. When I look in my own C:\WINDOWS\assembly directory, I see that I have the version that must have gotten installed when the new machines were deployed. The file is: Microsoft.Office.Interop.Excel version 14.0.4756.1000
The exception listing shows that the app is using:
Microsoft.Office.Interop.Excel
Assembly Version: 14.0.0.0
Win32 Version: 14.0.4756.1000
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.Office.Interop.Excel/14.0.0.0__71e9bce111e9429c/Microsoft.Office.Interop.Excel.dllThe version of the Microsoft Office 2010 Primary Interop Assemblies that I have installed is: 14.0.4763.1150
Even though i've installed the new version, My C:\WINDOWS\assemblies still references the 14.0.4756.1000 version.
I believe that this is the cause of the problems that I've been seeing, but don't know how to fix the problem.
I'll attach the exception listing and a section of code. The code works fine on my machine, but I can't get it to work on one of the user's machines.
Here is an exception trace showing the exception and listing the old PIA
See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box. ************** Exception Text ************** System.Runtime.InteropServices.COMException (0x800A03EC): Unable to set the CenterHorizontally property of the PageSetup class at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData) at Microsoft.Office.Interop.Excel.PageSetup.set_CenterHorizontally(Boolean ) at PEPS.mdl_Public_Functions_Subs.QUICK_EXCEL_EXPORT(ListView flstv, String fSheetName) at PEPS.frmPIDPurgeTool.cmdExcel_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) ************** Loaded Assemblies ************** mscorlib Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.3625 (GDR.050727-3600) CodeBase: file:///c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll ---------------------------------------- PEPS Assembly Version: 1.0.0.0 Win32 Version: 1.0.0.0 CodeBase: file:///C:/Documents%20and%20Settings/lz24sh/Local%20Settings/Apps/2.0/W4CW1ZZX.VLR/8HDACT1Z.8M1/peps..tion_f75c785a355c0db6_0001.0000_c727851afc393b4d/PEPS.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.3631 (GDR.050727-3600) 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.3623 (GDR.050727-3600) 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.3636 (GDR.050727-3600) CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.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 ---------------------------------------- System.Deployment Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000) CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Deployment/2.0.0.0__b03f5f7f11d50a3a/System.Deployment.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.DirectoryServices Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000) CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.DirectoryServices/2.0.0.0__b03f5f7f11d50a3a/System.DirectoryServices.dll ---------------------------------------- System.Data Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000) CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll ---------------------------------------- System.Transactions Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000) CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll ---------------------------------------- System.EnterpriseServices Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000) CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll ---------------------------------------- System.Security Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.3613 (GDR.050727-3600) CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Security/2.0.0.0__b03f5f7f11d50a3a/System.Security.dll ---------------------------------------- Microsoft.Office.Interop.Excel Assembly Version: 14.0.0.0 Win32 Version: 14.0.4756.1000 CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.Office.Interop.Excel/14.0.0.0__71e9bce111e9429c/Microsoft.Office.Interop.Excel.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.
Here is a code segment showing the code:
Public Sub QUICK_EXCEL_EXPORT(ByVal flstv As ListView, ByVal fSheetName As String) Dim xlApp As Excel.Application Dim xlWorkBook As Excel.Workbook Dim xlWorkSheet As Excel.Worksheet Dim sh As Excel.Worksheet Dim xlRange As Excel.Range Dim LR As Integer Dim x, i, y As Integer Dim LC As String 'Create New Excel File xlApp = New Excel.Application xlWorkBook = xlApp.Workbooks.Add xlWorkSheet = xlWorkBook.Worksheets(1) xlWorkSheet.Name = fSheetName 'Sets Page Margins & Paper Orientation With xlWorkSheet.PageSetup .CenterHorizontally = True '' code croaks here .BottomMargin = 46.8 .FooterMargin = 0 .HeaderMargin = 0 .FitToPagesWide = 1 .FitToPagesTall = 35 .Zoom = False .PrintTitleRows = "$1:$1" .Orientation = Excel.XlPageOrientation.xlLandscape .CenterHeader = "Generic Excel Report" .LeftHeader = "&G" .LeftHeaderPicture.Filename = glb_DelphiLogo .LeftFooter = "&D" .RightFooter = "Page &P of &N" End With
Any help would be gratefully appreciated.
By the Way: There is a line defining Excel as:
Imports Excel = Microsoft.Office.Interop.Excel
Thanks!
Alan Edwards
- Edited by Alan Edwards KAE Thursday, May 24, 2012 2:41 PM added the Excel Definition at the bottom
All Replies
-
Friday, May 25, 2012 7:05 AMModerator
Hi Alan,
Welcome to the MSDN Forum.
Based on your description, it seems that you want to reference the new version Excel, but your application keeps the 2.0 version one.
Am I right?
If so, please try the following steps:
1. Go to the property page of this project, and click on the reference tab.
2. Remove all Excel references.
3. Click the Add Button on the same page.
4. Choose the proper Excel reference on the ".Net" tab.
5. Rebuild your solution.
I hope this will be helpful.
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Marked As Answer by Alan Edwards KAE Tuesday, May 29, 2012 1:57 PM
-
Friday, May 25, 2012 1:34 PM
Hi Mike,
Thanks for your response. Yes, I believe you're right. I'm following the steps above.
I was able to remove the Excel reference from the References list in the Project, but I'm having trouble finding the right one to add back. I looked for an InterOp or an Excel library in the ".Net" tab, but I wasn't able to find it. There are some Component Names there called VsWebSite.Interop, VsWebSite.Interop100 and VsWebSite.Interop90, but I don't think that's the Excel or Office interop PIAs. Under COM, I have:
Microsoft Excel 14.0 Object Library (1.7) in C:\Program Files\Microsoft Office\Office14\EXCEL.EXE
Microsoft Office 14 Authorization Control 1.0 Type Library (1.0) in C:\PROGRA~1\MICROS~2\Office14\AUTHZX.DLL
Microsoft Office 14.0 Access Database engine Object Library(12.0) in C:\Program Files\Common Files\Microsoft Shared\OFFICE14\ACEDAE.DLL
Microsoft Office 14.0 Object Library (2.5) in C:\Program Files\Common Files\Microsoft Shared\OFFICE14\MSO.DLLUnder Imported namespaces, I have the option to check or uncheck namespaces, but I don't see anything there that says Office or Excel.
Is there a "Reference Path" that I should add so that I can see the ".Net" Office 2010 Primary Interop Assemblies?
If I go to the "Browse" tab, I can go to C:\WINDOWS\assembly and see what I believe I was referencing before:
Microsfot.Office.Interop.Excel (version: 14.0.0.0) (culture is blank) (Public Key Token: 71e9bce111e9429c) (Processor Architecture: MSIL)
There is an older version there too: Microsoft.Office.Tools.Excel.v9.0 (9.0.0.0)(b03F57F11d50a3a)(MSIL)
I'm not sure what to do from here. I don't have any reference to the interop libraries right now. Does this information tell you enough that will help you tell me what I need to do next?
Thanks for your help!
Alan Edwards
-
Friday, May 25, 2012 7:35 PM
Here are the Primary Interop Assembly versions that I have loaded. The first picture is what I get when I press the "Click here for support information" link on the "Add or Remove Program" entry for the "Microsoft Office 2010 Primary Interop Assemblies".
The second picture is what my C:\WINDOWS\assembly shows for the PIAs:Alan Edwards
-
Tuesday, May 29, 2012 6:04 AMModerator
Hi Alan,
Since the Excel reference is already on your computer, please try to use the "Browser" table to find the reference in the path "C:\Windows\assembly" and then add it into your project.
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Marked As Answer by Alan Edwards KAE Tuesday, May 29, 2012 1:57 PM
-
Tuesday, May 29, 2012 1:32 PM
Hi Mike,
Thanks for your reply. After I add the Excel reference library from the C:\Windows\assembly, should I go to the Publish side tab and in Application Files, should I choose "Include" and (Required) so that the library comes together with the deployment?
I noticed in "Application Files" there are several options (Include Auto, Include, Prerequisit, Exclude). What's the difference between Include (Auto) and Include?
The Application Files setting that I have is Include, (Required). Here is a snapshot of my Application Files without Show all files and with Show all Files checked:
Here it is with "Show all Files" checked:
Alan Edwards
-
Tuesday, May 29, 2012 1:59 PM
Hi Mike,
I was able to add the reference to the Excel PIAs from the Browse tab and publish the application. The new published app fixes the problem.
Thank you for your help!
Alan Edwards

