1

I've written an app with a service reference to make web services calls to a specific URL and it works great. I want to move this code into an Excel Add-In, but I run into this problem:

Unhandled Exception Message: Could not find endpoint element with name 'ConnectivityHttpsSoap12Endpoint' and contract 'Connectivity.ConnectivityPortType' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.

The problem is that my app.config (w/the service reference info) isn't being loaded because Excel is calling my class library, and the app.config of the calling application would need to have the service reference added to it. But can that be done with Excel? Better yet, is there a way to just load my app.config from code?

hexboy
  • 79
  • 1
  • 5
  • I fixed this myself. The issue was that Excel-DNA needs the config file to be .xll.config and I had used the default .dll.config created by Visual Studio. The problem was that I did a Google search on the above error instead of going right to the Excel-DNA site and checking the forums. Anyway, all good now. – hexboy Nov 06 '12 at 13:58

3 Answers3

2

You would need to open it using the ConfigurationManager. You can find your app.config file in the calling assembly path (usually), so you could write a method like this:

public static Configuration LoadLocalConfigurationFile(string fileName)
{
    // fileName is the configuration file you want to open
    var configMap = new ExeConfigurationFileMap 
    { 
        ExeConfigFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName)
    };

    return ConfigurationManager.OpenMappedExeConfiguration(
        configMap, ConfigurationUserLevel.None);
}
David Yaw
  • 27,383
  • 4
  • 60
  • 93
code4life
  • 15,655
  • 7
  • 50
  • 82
1

I have had the same problem recently myself and found that the best solution was contained in:

Change default app.config at runtime

pointing your config file at:

AppDomain.CurrentDomain.BaseDirectory + "AssemblyName.dll.config"

where AssemblyName is the name of your addin assembly

Community
  • 1
  • 1
SeeMoreGain
  • 1,263
  • 16
  • 36
0

As @hexboy noted in his comment, the answer is that ExcelDNA requires the config file to be the same name as the "xll" file but with a ".config" extension. Then ExcelDNA will load the configuration automatically and no further code is required.

Note also that ExcelDNA produces various different files on build. E.g. addin.xll, addin-packed.xll, addin64.xll, addin64-packed.xll where the project assembly is named addin.

In order for a config file to be picked up, it needs to match the file name that is used for the add-in. E.g. addin-packed.xll.config if using addin-packed.xll as the registered Excel add-in.

Josh Gallagher
  • 5,211
  • 2
  • 33
  • 60