tags:

views:

943

answers:

3

How can I specify that Excel uses the .NET framework version 2.0 when running .NET dlls other than adding an excel.exe.config file to the Office Binary folder?

Our application runs in Excel and uses VBA which makes calls into managed code in .NET assemblies. I believe the textbook way of doing this is to add excel.exe.config to the Office binary directory containing:

<?xml version="1.0"?>
<configuration>
  <startup>
    <supportedRuntime version="v2.0.50727"/>
  </startup>
</configuration>

This option is not acceptable for our clients, firstly because they simply won't allow us to add files to the Office directory and even if they did we could not risk breaking some application using .NET v1.1 which is the default choice of Excel.

The solution which we thought would work was to copy the Excel.exe file to our own applications directory from the client's Office directory, to add the config file there and execute that file. It works well but we are having serious installation problems where the install script cannot find the correct version of Excel. Plus it's a nasty kludge in the first place.

Any ideas would be welcome. I wonder if a layer of unmanaged (non .NET) code in a DLL might work. Some advice on how to do this or some simpler alternative would be appreciated as this is non-trivial.

Related:

.NET app.config question

+2  A: 

Another way to configure the runtime version selected for Excel is to change the following registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\Policy\AppPatch\v2.0.50727.00000\excel.exe

By default, this key forces Excel to use the 1.1 framework; removing it (or renaming it) causes Excel to load the latest version available.

If you're worried about breaking .NET 1.1 inside Excel then you may have to end up running a second renamed copy of excel.exe. The .NET framework can only be loaded once into a given Windows process, so within a single instance of excel.exe, you have to choose between 1.1, 2.0 or higher.

Tim Robinson
Thanks for the response, Tim.Unfortunately our clients would not allow us to / be happy if they found out that we changed the registry.Copying and renaming the Excel binary runs into the same problem we have encountered copying the binary to our own directory in that this creates problems at install time.
mikemay
+1  A: 

Microsoft has released a patch, which should be installed for every user using the add-in. You can obtain the patch here:

http://support.microsoft.com/kb/908002

See

http://stackoverflow.com/questions/436958/-net-app-config-question

0xA3
Thanks, Divo. This is something I can tell the clients to do without breaking their v1.1 applications.
mikemay
+1  A: 

The following article is pretty exhaustive on the issue. http://mcfunley.com/331/a-real-head-scratcher-courtesy-the-clr-and-office-teams . I think .NET 4.0 will be a saviour for those with the option.

mikemay