开发者

Project asking for a config setting that's there already

Here is the code that I am calling:

try
{
    using (var client = new WCFServiceChannelFactory<IFxCurveService>())
    {
        guid = client.Call(svc => svc.ReserveSnapshot(fxCurveKey));
        DiscountFactorNew[] dfs = client.Call(svc => svc.GetDiscountFactors(guid, dates, from));
        return (double)dfs[0].Value;
    }
}
catch
{
    throw new Exception();
}

Now it can't instantiate the WCFServiceFactory because it can't find one of the .config keys that we require, however, it's there in the app.config.

<appSettings>
    <add key="ConfigurationServiceAddress" value="http://ksintapp:91/configurationservice.svc/mex" />
</appSettings>

This fil开发者_运维知识库e and the file that are calling it are within the same directory. They are the only two files in the project, which is the only project in the solution.

This is the error:

Failed to initialize configuration repository because an application setting with the key 'ConfigurationServiceAddress' could not be found in the local configuration file.

Any ideas?


If this is an executable application (Console, WinForms, WPF) make sure that the config file is called AppName.exe.config and is located in the same directory as AppName.exe where AppName is the name of the project. If it is a web application make sure that this setting is present in the web.config.

When you add an App.config file to a project of type executable in Visual Studio everytime you build it copies to the output directory (bin/Debug or bin/Release) this config file by renaming it to AppName.exe.config so that at runtime the application is able to resolve it.


Figured this out by changing the service creation to this:

using (var client = new WCFServiceChannelFactory<IFxCurveService>(new Uri("http://ksqcoreapp64int:5025/")))

But now I'm having different issues, but at least I got around not needing a config file.


A config file has to be loaded by the application that is hosting the code. In your comments you state that this is an assembly that is loaded by excel. You won't be able to create an excel.exe.config file that has any meaning.

So, you're left with explicitly stating what config file to load OR changing to using the registry. I'd probably go with the latter while having that key defined in an install program.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜