App.Config file - Which project I must put it?

Hello!

I have a question.

Which project I must put an App Config file, when I have a Solution with 3 projects (Visual Studio)?

For example:

I have 3 Class Library Projects on Visual Studio:

HydraProjectApp - It`s the main project, responsible for API integration
HydraPlugin (Visual Plugin) - It’s the main entry of the app.
HydraUI - Visual Plugin UI for HydraProjectApp

The problem is:

When I`m running the application from Delphi (through DLL), if I put the appConfig file on the HydraPlugin, I got an error of missing configuration from app.config, when calling it in HydraProjectApp.

But, when I`m running Visual Studio, using a Form as main entry, to call the Library HydraUI and HydraProjectApp, they work wonderfully.

I`m missing something to this work correctly.

May you help with this?

At.

Into the one that generates the main .exe, I believe.

Hello

I’d strongly suggest you to use other approach like custom .json files to store configuration options.

Accessing App.config for a .dll file (f.e. for a Hydra plugin) will require some additional code.

In this case you will need to load the config file manually:

string configPath = this.GetType().Assembly.Location;
var config = ConfigurationManager.OpenExeConfiguration(configPath);
var element = config.AppSettings.Settings["KeyName"];

var configValue = element.Value;

Regards

Ive tried, but my project its a Class Library (3 files *.dll). I must access them inside Delphi Project. (I did a little test, put it in the *.exe application directory (Delphi). But it didnt work.

An extra information, the HydraProjectApp uses a group of dll files to comunicate with an API, and this one uses the config from the App.Config.

Running the Project in Visual Studio worked fine, because I have a Main *.exe application that call the HydraProjectApp and Ive put the App.config inside this project, but It didnt work on Delphi.

I`ve tried do this

string configPath = this.GetType().Assembly.Location;
var config = ConfigurationManager.OpenExeConfiguration(configPath);

But I`ve got invalid exe path.

PS: The 3 Dll files are inside *.exe path (Delphi) and they are accessed normally.

Thank you!

This solution was tested and confirmed to be working on a Hydra Delphi host and .NET Hydra plugin:

Please double-check that your .config file has correct name, that is it properly copied next to the plugin assembly etc

Please provide additional information:
What is the exact exception you got?
What is the full name of the .config file?
What is the name of the assembly where you try to execute the code that loads the configuration file?

What is the exact exception you got?
Delphi Project -

System.InvalidOperationException: Could not find endpoint element with name BasicHttpBinding_IService and contract IService 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’

What is the full name of the .config file?
App.config

What is the name of the assembly where you try to execute the code that loads the configuration file?
I`ve tried to load directly on HydraPlugin, but unsucessfully.

I’m suspecting that I’m using the wrong approach!
The 3 projects in Visual Studion Solution are defined as Class Library

Thank you!

About this snippet

string configPath = this.GetType().Assembly.Location;
var config = ConfigurationManager.OpenExeConfiguration(configPath);
var element = config.AppSettings.Settings["KeyName"];

var configValue = element.Value;

I managed to read some information from the configuration file, but a kind of “Brute Force” was made.
According to my research, it is not highly recommended.

Thank you!

As a workaround you might try to set your .config file name to match the host .exe file name. For example if your host name is DelphiHostApplication.exe then you config file name should be DelphiHostApplication.exe.config and this config file should be placed in the same folder as the .exe file.

This is a temporary workaround. A similar issue is already logged: bugs://85336

Hi,

Yes, I did this. But only worked for a specified field that I got by Brute Force.

In my project I have 3rd Party *.dlls that connect to an external service, it needs App.Config informations too.

When instantiating a connection with the service, i got this error, when called by Delphi Project

System.InvalidOperationException: Could not find endpoint element with name BasicHttpBinding_IService and contract IService 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’

Thank You.

Could you create a simplified testcase and send it to support@ ?
Thanks in advance

Also please send your account name to support@ so we’ll be able to provide you a fix download once it is available.

Hi,

I sent an e-mail about this, with a sample.

Regards.