I have created a WCF web service which has references to some class library (BO.dll,BLL.dll,DAL.dll) ,and invoke their methods . one of the libraries(DAL.dll) need a config file to read some settings like connection string . then the config file is located near to the dll files .
but when I use the service, it has error which the "could not find file C:\windows\microsoft.NET\FrameWork\v4.0.30319\Temporary ASP.NET Files\SampleService(some temp folder)\myConfigFile.config"
I should say that, dll code read the config file as a simple xml file. and extract the settings.
why it looks for in this address ?
where should I put the config file to be accessible by the dll ?
It is because for DLL you need to use your webservice's configuration file for DLL if you are reading connection string using
System.Configuration.ConfigurationManger.AppConfig class.
Otherwise you can reading manually.
This link might help you
Reading dll.config (not app.config!) from a plugin module
Related
I am using electron-edge-js to call a C# DLL.
Within the DLL, the App.config file is called out for server connection information.
return (ServiceDetailConfiguration)ConfigurationManager.GetSection(ServiceDetailConfiguration.ServiceDetailConfigurationConst);
In my js file calling the dll, I can successfully call out to the dll, and process information. That is, until I hit the above line, I get a null exception thrown as it can't find the app.config.
I've tried the below:
Load WCF app.config bindings in edge.js app
working with electron-edge-js for existing dll with app.config
Without much luck.
In my package.json file, the name is "firstelectronapp".
When i build the file, I output it as "test.exe"
So i've attempted these files in the same root folder as the test.exe file with no luck:
first.exe.config
firstelectronapp.exe.config
test.exe.config
node.exe.config
Is there something I'm missing? I wrote a quick C# app with an app.config that calls the dll, and when stepping through it I can tell that's what the issue is.
The config file should be renamed electron.exe.config and placed in the same directory as electron.exe - i.e. node_modules\electron\dist.
I just ran into this when needing to add a bindingRedirect. Putting it in the above file solved it.
Also, if you're using electron-builder for packaging the app, you can easily include the config file in the packaged application by adding it to the extraFiles collection in the build configuration, for instance:
"extraFiles": [
{
"from": "app.config",
"to": "my-electron-app-name.exe.config"
}
]
I gone through lot of threads about this topic but did not get any solution.
First I created a windows application. In that I used app.config file to store some variables it worked properly. Then the application converted to class library. While extracting the varibles it gives only null values.
Any other option to get or set variables in config file in the class library
Thanks.
If you converted you code to some class library you have to remember that it will reuse web.config/app.config of an application, which references it. So I would suggest to add settings from "old" app.config to the configuration file of an application, which uses your library.
We can not use app.config or web.config in class library. Add app.config for Console/Windows application or web.config file for your web application which calls your class library then application will automatically takes and uses that configuration file.
I have a Windows application called TechReader. Its configuration file is TechReader.exe.config. Some parts of the configuration are kept in other configuration files. So I refer to that config file from the config section created in the exe.config.
<TechReader.ProviderConfiguration file="localProvider.config"/>
Now I want to load the whole configuration of my application using reflection. I use code like this.
Assembly techReaderAssembly = Assembly.GetAssembly(typeof(TechReaderStarter));
ConfigurationManager.OpenExeConfiguration(techReaderAssembly .Location);
TechReaderStarter class is defined in the project whose output is windows application and not the library.
When I use above code, I get TargetInvocationException and ConfigurationErrorsException
Is the approach correct?
Will OpenExeConfiguration load the final configuration generated by merging the exe.config and other referenced config file?
How can I achieve the things?
Note: I want to use this Windows application to install as a Windows Service. I am trying to read the configuration in the ServiceInstaller class (a class which inherits ServiceInstaller) so that the details like service name mentioned in the configuration of the Service will be available to the installutil. For this I have to use reflection to get the exact configuration of the service.
Is there any way to inherit settings in the .config file from a subassembly?
Example:
Imagine I have an assembly .NET that does something like connect to a database, or a remote WCF service. This assembly is called "Connect.dll", and its config file is "Connect.dll.config".
This sub assembly is called from the main program, "main.exe", its config file is "main.exe.config".
Is there some way to import the settings from "connect.dll.config" into "main.config", without having to copy the appropriate .xml lines in in by hand?
Unfortunately, no. There is however possible to load configuration from the "Connect.dll.config" manually using the ConfigurationManager API.
I have a config file in my C# class library called MyLibrary.config, in vs 2008.
I created another project, say a simple console app, add reference by "Browsing" the MyLibrary.dll in the bin directory of the class library project, and when I compile, the MyLibrary.config is not including in the bin directory of the output in the console app.
How can I set it so I can include it when I reference the dll?
Cheers
You can't. Your console application is expecting to find a config file with prefix the same as the name as the console application (MyConsoleApplication.exe -> MyConsoleApplication.exe.config.).
In some situations you can share a config file by using the file attribute on the appSettings element:
<appSettings
file="path">
</appSettings>
Note that path is relative to the executing assembly.
As a side note, DLLs do not even use the config file that you've defined in the project. Again, configuration information is read from the a config file with prefix the same as the executing assembly. Thus, even when MyLibrary.dll tries to yank configuration information out of a config file, it will be reading the config file for the executing assembly, not MyLibrary.dll.config.
For more on how config files work, see MSDN.
The standard way to use a config file is to have it the same as the executable, adding a reference to a dll will not include its config file and as far as I know dll's don't load config files on their own, rather they rely on the executable that reference them.
Beyond not being able to do this, I would also advise against this approach.
Rather than trying to tighly couple your settings to the DLL library, consider more of a "Dependency Injection" type approach - i.e. where you pass in the value dependencies (i.e. settings) to the code you are calling (i.e. the library).
The advantage in this is you are not tied to a single method of storing settings. You can then use a database, different config file formats... even hard-coding. It also makes unit testing easier by removing the external file dependency.
There are different ways to implement this, however one example is to pass the configuration settings into the constructor of the class(s) that uses them.