Fadeproof
Fadeproof

Reputation: 3058

Why are .net configuration settings compiled into assemblies?

I have been trying to read up on how to do configuration properly in .net and have run into something that I find a bit odd and that is that configuration settings are compiled into assemblies through the Settings class. Removing the app.config and running the application does not result in configuration errors as I was expecting but rather now I have no way of replacing the configuration values.

In my application I have a configuration setting for a webservice url that I need to be able to pick up and set programmatically. Should I be creating custom sections in the configuration for my application that I will read through the ConfigurationManager.GetSection(..) to trigger reading of the config file or is there another way around this problem as I absolutely don't want the webservice url used to generate the ws proxy as an url that could potentially leak into production.

Please help.

Upvotes: 3

Views: 2972

Answers (7)

Nicolas Dorier
Nicolas Dorier

Reputation: 7465

look Where are user-mode .NET settings stored?

.NET settings are not in the assembly

Upvotes: 1

Tundey
Tundey

Reputation: 2965

I think I understand what you're saying, Jojoe. Say you add a webservice from www.productionurl.com, the proxy class generated keeps the production url in the source code. At runtime, it uses this default value if it can't find a value for the url in the configuration file (provided you've set the service to Dynamic).

If you don't like this behavior, you have 2 choices:

  • change the Reference.cs file (you'll have to keep doing this whenever you refresh the service proxy)
  • Create a partial class for the proxy and override the URL setting

Or you can check to see if the webservice has a development site. If it does, create the web reference from that site instead of the production site.

Upvotes: 0

Romias
Romias

Reputation: 14133

As far as I know the webservice reference logic states that if there is a certain key in the app.config (or web.config) it will pick that... if not... it will use the URL reference used to create the webservice reference. That in Framework 1.1 and may be 2.0.

The Settings.settings file... in framework 3.0 at least is used as the default values. If you don't provide a key in the web.config that overrides the ones in Settings.settings it uses the default values... and that is why you don't see a configuration error. In the case of webservice references, is in that file where is stored the value you provide to create the reference.

As I can see... the Settings.settings allows you to update the keys programatically in order to save preferences and some how get persisted.

More info:

Upvotes: 0

RC1140
RC1140

Reputation: 8663

As far as i remember ( i stand to be corrected) , .Net creates a config file that is stored in your windows app data folder , this is especially true if you are deploying the app.

Search in the app data (C:\Documents and settings\yourusername\Local Setting\Application Data\your app name) and see if you can find the app config in there.If so you should be able to change it there.

Also i am not sure what type of web service you are creating , but should you not be using a web.config (its what i use) to store settings ?

Upvotes: 0

Andrew Hare
Andrew Hare

Reputation: 351516

Try adding an application configuration file to your project rather than a settings file. An application configuration file does not get compiled into the assembly.

Upvotes: 1

Tundey
Tundey

Reputation: 2965

When you add a reference to the webservice, you can set the property to make the webservice url dynamic (i.e. read from the configuration file).

Click on the "Web References". Click on your webservice and set the property "URL Behavior" from "Static" to "Dynamic".

Once you make the change, all you have to do to point the webservice to the right URL is to change the configuration file before your app runs.

Upvotes: 0

Spence
Spence

Reputation: 29332

If you click out the plus on the properties, and then on teh settings, you will find a file called settings.designer.cs

This file contains the default value you created when defining your application setting, and it is why your app works without a config file.

However you can always override this value.

Your only way to test this is to create a default value which is safe for public consumption, and change it during test.

Upvotes: 0

Related Questions