web.config in ASP.NET 5 MVC 6 - c#

I have a WCF .dll that loads configuration from web.config file.
I'm using that dll in asp.net 5 application, when I try to call a function from dll, I'm getting exception:
Could not find default endpoint element that references contract 'WebService.MyWebService' 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 contract could be found in the client element.
The configuration for dll exists in web.config.
This used to work in asp.net beta 6, but now that I upgraded to rc1 it doesn't work.
How can I make this work?

As stated here:
Support for app.config when running on the full .NET Framework
When running on the full .NET Framework you can now use System.Configuration to access configuration data in app.config from a DNX based console application. Simply put your XML configuration file next to your project.json file.
So I only had to copy contents of web.config to app.config

Related

Can you move system.diagnostics configuration from web.config in appsettings.json for iConfiguration for a .NET Framework 4.6.1 project?

Our team is trying to move our web.config transforms into appsettings.json files which are determined in runtime via an environment variable in the server which we set on deploy (rather than transforming web.config files at compile time). One of our projects has a web.config with system.diagnostics logging configuration which is transformed using xdt transform. We are not moving to ASP.NET Core (yet), but sticking with ASP.NET Framework 4.6.1 (we are forced due to our solution being tied to a particular version of Sitecore which we can't upgrade due to licensing).
Can we move system.diagnostics configuration into an appsettings.json file which is then picked up by iConfiguration? If so, how would we do it? How is the configuration for diagnostics structured in the json file?
Secondary bonus but related question: We have system.web and system.webserver configurations that are also transformed. Can they be similarly moved to an appsettings.json file as well?
Thank you in advance.

Reading .NET Fx app.config in an Azure Function v2 (.NET Core) app

I am developing a new Azure Function using the v2 SDK. So the function app is a .NET Core App. A lot of the logic that the function needs exists in .NET Framework 4.7.2 libraries, which are referenced from the Function project.
The project compiles and runs (locally, thus far). However, even though I have an app.config file in the project, which is set to the copy to the output directory, the libraries can't seem to find the config.
The app.config file gets copied to the \bin\Debug\netcoreapp3.0 folder with the name app.config. That probably wouldn't work, but even when I copy the config file to the bin subfolder (\bin\Debug\netcoreapp3.0\bin) and change it's name to myassembly.dll.config (where myassembly is the compiled function app), the config can't be found.
I've also added the connection string (one of the key configuration pieces) to local.settings.json as such
{
...,
"ConnectionStrings": {
"connstringname": "connectionstring..."
}
}
That also does not make the connection string available to the code in the .NET Framework class libraries.
I've also tried adding the System.Configuration.ConfigurationManager NuGet package (4.6.0) to the Function app project, without a change.
I am not sure if there is any other easy solution. But there is a workaround.
You may add all the configurations to the local.settings.json, and the function will set all those configurations as system environments settings.
Then you can get one by:
System.Environment.GetEnvironmentVariable("{key_name}");

External dll is referencing current project's web.config

I've got two projects, WebAPI project as A and MVC4 project as B.
The dll of A project is referenced in B project.
I found that A's dll is using the config setting in B's web.config.
These projects have different definition for corresponding web.config.
So how can I do A's dll to use its own web.config and not to use B's web.config?
The configuration file is read only from starter project. You can merge configs if they differ in appsettings or connectionstrings. But if they differ in system settings like .net version, authentication and so on, you should launch your projects separately.
You're doing strange things, because MVC4 has initial support for WebApi. You can extract business logic from WebApi into another project. Do you really need to have WebApi controllers in separate project?

Settings from "app.config" is not being gotton in class library project

Problem is that my settings from "app.config" is not being gotten in class library project.
Can "app.config" be used in applications only and not in class libraries?
You should add the config settings to the project that is using the class project. ie If you have a project 'MyProject' that references 'MyClassProject' then the app.config settings should be placed in the 'MyProject' project
Application configuration files contain settings specific to an application. This file contains configuration settings that the common language runtime reads (such as assembly binding policy, remoting objects, and so on), and settings that the application can read. The config file is optional, if it does not exist environments such as ASP.NET will fall back to the machine.config file stored in the .NET system directories to get machine wide defaults.
Think about it like that. If you class library has some custom settings then it should have a config to deal with it.
By design of .NET framework when you access Application configuration with default means - .NET runtime supplies you with data from app.config of entry assembly (an EXE file that references your class library).
Application Configuration of class library can be accessed in following way (code should be placed in project of class library - in order for Assembly.GetCallingAssembly().Location to return proper path):
ExeConfigurationFileMap classLibraryConfigurationMap= new ExeConfigurationFileMap();
classLibraryConfigurationMap.ExeConfigFilename = Assembly.GetCallingAssembly().Location + ".config";
Configuration classLibraryConfiguration = ConfigurationManager.OpenMappedExeConfiguration(classLibraryConfigurationMap, ConfigurationUserLevel.None);

3rd Party .Net Assembly not working in WebService project

So I'm trying to use a .Net Assembly in my web services project. This assembly requires lots of settings in App.config. But my web service doesn't have an App.config, it has a web.config. It seems that it uses sections that an app.config would have that don't even exist for web projects. Is there any way I can make this assembly work? (make it read another config file maybe?)
You should be able to simply use the same configuration sections in the web.config file that exist in the app.config and it would work.
The way the configuration subsystem works means that it does not matter.

Categories