The blog has moved to a new address. The blog is now located at http://devintelligence.com

Adsense

Friday, August 11, 2006

Why are user scoped settings present in the app.config?


The configuration system is hierarchical and has the following ordering:

Machine à Application à Roaming User à Local User


When you query a configuration section at any level, you get a merged view of the sections declared in that level and those below it (with machine being the lowest level and local user the highest). The section handler defines how the merge happens and for settings, a setting value specified in, say, local user config trumps the one specified in application config.


So for user scoped settings, you can think of the values specified in app.config to be install time defaults. When the settings are saved into user.config, those values will override these defaults. This way admins have the option of changing the defaults. Note that the defaults can also be specified by means of a DefaultSettingValueAttribute. The provider will use this value if no value is specified for a setting in any level of config.






Technorati : ,

How are my strongly typed properties serialized as settings?


There are two primary mechanisms that ApplicationSettingsBase uses to serialize settings:



  1. If a TypeConverter exists that can convert to and from string, it is used.

  2. Otherwise, the XmlSerializer is used.

Are there multiple config files for an application or just one?


The default SettingsProvider for client applications (called the LocalFileSettingsProvider) stores settings in the application configuration files. In .NET v1 and v1.1, there were two levels of config files - machine.config and app.exe.config (where 'app.exe' is the name of the application). In v2.0, we have added two more levels of configuration to store user specific data - one that goes in the roaming user profile path and another in the local user profile path. On XP, the profile directories would be something like 'c:\Documents and Settings\<username>\Application Data' and 'c:\Documents and Settings\<username>\Local Settings\Application Data' respectively. These directories are the recommended location (per Windows Logo requirements) for storing user specific information, and most applications (like Outlook and Visual Studio) put user data somewhere under here.




Technorati : , ,

How do I know when to call Upgrade in a non-Clickonce app?


In non-Clickonce cases, there is no automatic upgrade - you have to call Upgrade yourself. Here is one idea for determining when to call Upgrade:
Have a boolean setting called CallUpgrade with a default value of true. When your app starts up, do the following:


if (Properties.Settings.Value.CallUpgrade)
{
Properties.Settings.Value.Upgrade();
Properties.Settings.Value.CallUpgrade = false;
}
This will ensure that Upgrade( ) is called only the first time the application runs after a new version is deployed.




Technorati : , , ,

How do I know when to call Upgrade in a Clickonce app?


In Clickonce, when you install a new version of your application, ApplicationSettingsBase will detect it and automatically upgrade settings for you at the point settings are loaded.




Technorati : , , ,

If I deploy a new version of my application, will the user lose all the settings saved by the previous version?


It is easy to upgrade settings from a previous version of the application to the latest. Simply call ApplicationSettingsBase.Upgrade() and it will retrieve settings from the previous version that match the current version of the class and store them out in the current version's user.config file. You also have the option of overriding this behavior either in your settings class or in your provider implementation.




Technorati : , ,

Where is the user.config file located if I deployed my application using Clickonce?


The path algorithm mentioned above is not used in the Clickonce case. Instead, the local user.config file goes in the Clickonce Data directory (the <Version> part of the path will still be included). There is no roaming user.config file for Clickonce applications.




Technorati : , ,

Wednesday, July 19, 2006

Why doesn’t the debugger catch exceptions in webBrowser events?


Since the core of the managed WebBrowser is an unmanaged ActiveX control, it captures all exceptions thrown in its methods before they can be passed to the debugger. This can lead to unusual behavior if you are not catching the exceptions before they leave the method. For this reason it is highly recommended that try catch blocks should be placed around the contents of all WebBrowser methods during the development and test phases, with special attention paid to procedures that could potentially throw exceptions.




Technorati : , ,

Does the WebBrowser control work in Partial Trust?


The WebBrowser control does not work in partial trust. This class makes security demands at the class level, therefore a SecurityException is thrown when a derived class or any caller in the call stack does not have full trust permission. For details about security demands, see Link Demands and Inheritance Demands.




Technorati : , , ,

WebBrowser FAQ:How do I get the site of a new window?


To get the Url that the WebBrowser is navigating to in a new window, use DWebBrowserEvents2::NewWindow3. This method is not exposed by IntelliSense. For information on how to use it, see: http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=7228 for an implementation.




Technorati : , ,

How do I navigate to a Url that contains escape characters?


To navigate to an addresses that contains escaped characters (such as %20) be sure to use the webBrowser.Navigate(String) method instead of the webBrowser.Navigate(Uri) method. The Uri method escapes these characters by default, while the String method does not.




Technorati : , ,

How do I block popups?


To block pop-ups, use the following registry key:
HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER)
SOFTWARE
Microsoft
Internet Explorer
Main
FeatureControl
FEATURE_WEBOC_POPUPMANAGEMENT
For more information on this topic, see http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/hosting/wbcustomization.asp




Technorati : , ,

Why won’t the WebBrowser navigate?


Be sure that AllowNavigation is set to true. This property not only prevents users from making the WebBrowser navigate, but also prevents the WebBrowser from programmatically being given a new Url.

WebBrowser FAQ:How can a control in the browser access the DOM of the page that is hosting it?


For an example of this, see http://msdn2.microsoft.com/en-us/library/system.windows.forms.webbrowser.objectforscripting




Technorati : , ,

WebBrowser FAQ:How do I get XP SP2 Security features?


To control XP SP2 security features, you can set various registry keys. For detailed information, see: http://www.microsoft.com/technet/prodtechnol/winxppro/maintain/sp2brows.mspx




Technorati : , ,