Way to Override Policy & Use 2003 Vice 2007 Excel Interface (VB.NET)?

A

Alan

I am using the Visual Basic 2008 Express IDE to develop VB.NET code
that manipulates Excel files. I am developing on a PC that has both
Excel 2003 and 2007 installed. However, I need the code to run on a
PC with only Excel 2003 installed.

In the IDE I selected the Excel 2003 and Office 2003 COM interfaces as
References for my project. There are no references selected to the
Excel 2007 or Office 2007 COM interfaces. The code works find on my
PC, but I get an error when I try to run it on a PC with only Excel
2003 installed:

"Unhandled exception has occurred in your application. If you click
Continue, the application will ignore this error and attempt to
continue. If you click Quit, the application will close immediately.

Could not load file or assembly 'Microsoft.Office.Interop.Excel,
Version=12.0.0.0, . . . or one of its dependencies. The system cannot
find the file specified."

This indicates that the VB.NET code is looking for Excel 2007 (v. 12),
not Excel 2003 (v. 11).

Is there a way to override this to use 2003 only in my VB.NET project,
by modifying some policy?

Additional information from the error may be found below.

Also, I found an article at http://blogs.msdn.com/excel/archive/2006/06/19/636534.aspx
that says:

"In conjunction with the OM compatibility work we have done, we are
also shipping publisher policy files for the Office PIA’s. These will
automatically redirect code that is compiled against the 2003 PIA to
the new 2007 PIA so that existing code compiled against a 2003 PIA
will automatically be redirected to the corresponding 2007 PIA. As
with any publisher policy, in cases where you may not want to redirect
code to call the new PIA, you can override the policy by using the
following tag in an application configuration file shipped with your
managed assembly.

<publisherPolicy apply="no"/>
"
However, I was not clear as to where or how to make that change, and
the link for more information is broken.

Thanks, Alan

************** Exception Text **************
System.IO.FileNotFoundException: Could not load file or assembly
'Microsoft.Office.Interop.Excel, Version=12.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=12.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c'
at HTMLcreator.MainForm.StartButton_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.1873 (QFEN-1.050727-1800)
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
HTMLcreator
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///D:/Documents%20and%20Settings/james.a.THOMAS/My%20Documents/VBA/HTMLcreator/HTMLcreator.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0..0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
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.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
 
A

Alan

Now I see the problem, but I could not fix it. . . .

The References say 11.0 object libraries, but their paths are set to
the 12.0 libraries, e.g.: C:\Windows\assembly\GAC\Office
\12.0.0.0__71e9bce111e9429c\Office.dll.

I tried browsing to the specific directory for Excel 2003 and
selecting Excel, but the path is still wrong.

Any idea how I can correct this?

Thanks, Alan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top