I have inhertied an web application (.Net MVC) to support. I have noticed that the previous developer has created a class library (myApp.Core) and used a settings file (AppSettings.settings) to store application specific settings, I also can see an associated app.config file that has all the settings defined in:
<applicationSettings>
<myApp.Core.AppSettings>
<setting name="DaysToKeep" serializeAs="String">
<value>2</value>
</setting>
...
</myApp.Core.AppSettings>
</applicationSettings>
I undersatnd that using a settings file gives nice strongly typed values and they can be stored agasint a user or application and the values can be accessed in code using the following notation:
AppSettings.Default.DaysToKeep;
However recently a change was required to update one of these setting's values on a production server (to issue a quick fix) however I was unable to locate where the actual app.settings file was located on the server and the exact setting and value to change.
Locally I can see myApp.core.dll.config in myApp.Core bin folder.
So... Where is the app.config file located on the web server? Also reading numberous articles seems to suggest that these values can't be upadted anyway, is this true.
Related
This has been asked before, but I can't find an answer that works for me.
I have a solution that contains 5 projects, one is a Web API (.net 4.5) and one is a Class Library (.net 4.5). The Web API has a reference to the class/DLL. In the class project, the Settings.settings is utilized to enter values in the App.Config. All the values in the settings are Type string, Scope Application, Access Modifier Internal.
These values are created in the App.Config and look something like this:
<applicationSettings>
<xxxxx.Properties.Settings>
<setting name="setting1" serializeAs="String">
<value>1</value>
</setting>
<setting name="setting2" serializeAs="String">
<value>abc123</value>
</setting>....
In the class code, the values are read like so:
Properties.Settings.Default.setting1;
When the package for the Web API is created, it has the .dll, but not the .dll.config file. If I manually copy the .dll.config file, the .dll doesn't read from it. It also doesn't seem to read the ConnectionString fromt he web.config either.
I need the DLL to read either the .dll.config or the Web APIs web.config file. I have tried several solutions posted in stackoverflow, but most seem updated/deprecated and/or throw errors when I tried them.
What is the current and correct approach to this issue, with .net 4.5?
Thanks
I ended up deleting everything from the Settings.settings eliminating the
<applicationSettings>
<xxxxx.Properties.Settings>...
section of the App.Config. Then I just added a regular <appSettings> section and calling the value in code with
ConfigurationManager.AppSettings["xxxxx"];
I read in some posts that this was no longer supported, but it was the method that worked for me.
I am working on a asp.net application that stores important data in app.config. In all Windows versions before Windows 10, the tests correctly load the data I want, but once I upgraded a system to Windows 10, the application no longer is able to pass the same test and fails to grab data. Whenever it read from the app.config file, as seen in the code below, Null is always returned.\
var data = System.Configuration.ConfigurationManager.AppSettings["PathName"];
When run in Windows 8, the value returned is a valid string that I use. When run in Windows 10, null is returned despite the file being present just as before. Once the value is used later on in regards to path3, an Exception is tripped and the error shown below occurs. Path3 comes from a function that the Null value is passed into.
threw exception: System.ArgumentNullException: Value cannot be null. Parameter name: path3
I have tried changing user permissions to files, folder and so on, but nothing seems to change this. I have also changed the User Account Control settings with no luck. I am using Visual Studios 2013 Professional and always run it in under admin mode.
Everything I have looked at online has not helped much and pretty much reiterates most of the steps I have already tried. Any insight is greatly appreciated.
Contents of app.config (Key = "PathName")
<?xml version="1.0"?>
<configuration>
<configSections>
</configSections>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
<appSettings>
<add key="PathName" value="DATA_VALUE_NEEDED" />
</appSettings>
<applicationSettings>
</applicationSettings>
</configuration>
So, after trying a lot of solutions, I finally figured out what was creating the problem. I'm not exactly sure why this occurred, but this is what happened all the same.
On windows 8, the app.config file from test projects loads directly from the main project it is meant for. Meaning, if you create a separate project for your tests, it links to the original that it was created for when loading app.config files.
In Windows 10, this does not seem to be the case for some reason. For some reason, the app.config file being read in was not the one for the project the tests were created for. It was some sort of auto generated default despite no settings or configurations being changed between porting the code between the two OS versions.
I was able to solve the problem by copying the file directly from the main project into the test project for it. Then, with a link between the two, they will stay updated when either one is changed.
I still don't understand why this happened and cannot locate the generated app.config file. After debugging, I simply noticed that the loaded key value pairs available did not exist in any single XML files in the entire project repository. Hopefully this helps others down the road with the same problem since I have seen several other reports online of people running into what seems to be this problem. Thanks everybody for your help!
In an effort to try to get ConfigurationManager.AppSettings[..] working again, I've created one applicationSettings element and one appSettings element in a single-project console application.
<applicationSettings>
<el_testo.Properties.Settings>
<setting name="ApplicationSetting" serializeAs="String">
<value>Application Value</value>
</setting>
</el_testo.Properties.Settings>
</applicationSettings>
<appSettings>
<add key="AppSetting" value="App Value"/>
</appSettings>
Here's my effort to retrieve the two values.
Debug.WriteLine("---> ApplicationSettings Test");
Debug.WriteLine(ConfigurationManager.AppSettings["ApplicationSetting"] + "");
var applicationSettingsTest = ConfigurationManager.AppSettings["ApplicationSetting"];
Debug.WriteLine(applicationSettingsTest);
Debug.WriteLine("---> AppSettings Test");
Debug.WriteLine(ConfigurationManager.AppSettings["AppSetting"]);
Debug.WriteLine("---> Complete");
And here are my results.
---> ApplicationSettings Test
---> AppSettings Test
App Value
---> Complete
I could just "settle" and use the appSettings construct. It would be kind of nice, however, to use the Settings tab on Project properties on this project and future projects. Here's what I've tried this far to make work.
There's only one project in this application. Therefore, I can't be setting the value in one project and trying to read it in another. (Additionally, appSettings works.)
I verified that the project includes the assembly reference System.Configuration and the class includes the proper namespace reference (using System.Configuration;)
I've double-checked spelling and case of the setting name in ConfigurationManager.AppSettings["ApplicationSetting"].
I've tried linking App.config to different XML Schema files, EnterpriseLibrary.Configuration.xsd and an XML Schema file I generated using the XML menu in Visual Studio.
I've wiped the contents of the Debug and Release folders and rebuilt the project.
You are incorrectly trying to read your ApplicationSetting element as a key under appSettings with the following statement:
ConfigurationManager.AppSettings["ApplicationSetting"]
This means your are trying to get the value of this:
<appSettings>
<add key="ApplicationSetting" value="xxxx" />
</appSetting>
Instead; when you add an application setting using the project properties, it creates a settings class extending the ApplicationSettingsBase class, create properties with the name of your settings and will also add necessary configSection and a default config element in your app.config file. Why not just create and use that class which will give you type strict access to your application settings?
Just go to Project/e_testo Properties/Settings and add ApplicationSetting with scope Application
You can then access the ApplicationSetting by
var applicationSettingsTest = Properties.Settings.Default.ApplicationSetting
I'm trying to update a value in my app.config file using the code below (the value is defined in Properties > Settings as Application scoped)
System.Configuration.Configuration configApp = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
MessageBox.Show(configApp.AppSettings.Settings.Count.ToString()); //this shows 0
configApp.AppSettings.Settings["PontajAdminPwd"].Value = "dsfs";
configApp.Save(ConfigurationSaveMode.Full);
but it saying that configApp.AppSettings.Settings is empty...
This is a part of my app.config file
<applicationSettings>
<PontajWPF.Properties.Settings>
<setting name="PontajAdminPwd" serializeAs="String">
<value>696W3oybVP85szuiY2Qpiw==</value>
</setting>
</PontajWPF.Properties.Settings>
</applicationSettings>
What am I doing wrong?
Thank you
EDIT 1: I'm in a hurry so I adopted the solution proposed here (direct file access after changing the app.config file by hand - using appSettings instead of applicationSettings):
http://www.longhorncorner.com/uploadfile/rahul4_saxena/update-app-config-key-value-at-run-time-in-wpf/
configApp.AppSettings.Settings.Count.ToString() this will try to read settings from <appSettings> section, not <applicationSettings>. Also the name of the file should app.config.
In your case you will need to use Properties.Settings static class, to access your settings from applicationSettings. You can try PontajWPF.Properties.Settings.Default.PontajAdminPwd
Application-scope settings are read only, and can only be changed at design time or by altering the .exe.config file in between application sessions.
User-scope settings, however, can be written at run time, just as you would change any property value. The new value persists for the duration of the application session. You can persist changes to user settings between application sessions by calling the Settings.Save method. These settings are saved in the User.config file.
Read more on MSDN
Hope this helps.
I have a .net solution having a reference hierarchy like this
MyWinApp->ServerCore->DataAccess
where the last two are class libraries and myWinApp is a windows app.
Now, each time I want to run this project on different servers I need to rebuild the project since I couldn't manage to separate the configuration file(app.config) of DataAccess project that has connection string related configurations.
How can I separate database configurations from the application code? I tried to build action options but it doesn't work :S What might be the most feasible solution?
Thanks in advance
The configuration should most likely go with the MyWinApp project. The configuration file goes with what is executing. So if you make an installer for your application, it'll have a configuration file called MyWinApp.exe.config that was created from your App.Config.
Basically the app.config with your Datalayer.dll doesn't really do much.
What you might want to do is look at how the configSource property works for configuration files in .net here: http://msdn.microsoft.com/en-us/library/system.configuration.sectioninformation.configsource.aspx and see if this is what you're looking for. This lets you set a configSource for your connection strings that you can change per machine.
All I do is setup a simple xcopy before a deploy and I have the correct configuration settings before deploying an asp.net app. If you have to package an installer, copying the correct files before building the installer should do the trick as well.
For my DAL projects I typically have a DataLayer.dll.config file but I actually add the ConnectionString entries to my Program.exe.config file. I don't know that you need anything special for this. Possibly just reference a static readonly string or something from the DataLayer.dll in the Program.exe?
Or, do you really want to have separate configuration files? If so then you can use the ConfigurationManager class to open a loose configuration file with the OpenMappedMachineConfiguration method. See MSDN ref here: http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.openmappedmachineconfiguration.aspx
I think you can use applicationSettings to include configuration for specific referenced assemblies:
For example:
<configuration>
<applicationSettings>
<ProjectName.Properties.Settings>
<setting name="ConnectionString" serializeAs="String">
<value>YourConnectionStringHere</value>
</setting>
</ProjectName.Properties.Settings>
</applicationSettings>
</configuration>
Where "ProjectName" is the name of the reference you need to configure. Each project can have it's own app.config with the above applicationSettings entry and a value specific to the project itself.