Its been a long time since I wrote some technical blog. All this while I have been writing blogs once in a while on my personal blog at MSN spaces. While going through one of the advanced topics I came across an article which explained the internals of configuring a .NET application. So in this blog I would like to share some of my experiences with configuring the applications.

One of the greatest advantage .NET offered over earlier windows deployment model was that you no longer had to rely on Registry settings to install/deploy the application. .NET works with configuration files which are primarily XML files. These XML files define the tags which replace the need for registry keys. This also helps in XCopy deployment of the applications.

Whoever has worked with .NET must be aware of what assemblies are. If you have any doubt regarding assemblies I would suggest reading following article, as it is outside of the scope of this blog to explain about assemblies. Basically there are two types of assemblies private and public or shared assemblies. Private assemblies reside within the application or in any of its su folders. Assemblies which can be used across applications can be installed in a special folder called Global Assembly Cache (GAC). Microsoft also provides a framework tool for managing shared assemblies.

The runtime searches for assemblies in a specific order. This process of locating the assemblies is called Probing. Probing is applicable only for private assemblies as they are stored within the application directories.

Shared assemblies are located using different mechanism. Each application can have a configuration file of its own. In case of windows applications, it is same as the name of the exe with .config appended to it. For. eg. if your exe name is SapleApplication.exe the config file name will be SapleApplication.exe.config. If there are many directories within the root directory and the private assemblies are deployed in one or two directories, you can configure the settings to direct the runtime to probe for an assembly only in specific folders. Following code snippet is used to demonstrate the same

assemblyBindings tag of runtime element is used to specify the probing path, using the private path attribute. As a result of above settings, runtime will probe for private assemblies within the path1 and path2 subdirectories of the bin directory.

Shared assemblies are identified by the name, public key token and the culture of the assembly. .NET framework allows side-by-side execution of assemblies, which means that two versions of same assembly can be loaded by the runtime without affecting the programs which use individual versions. In case the older version of the shared assembly had some bugs which were fixed in the next version, the publisher of the assembly can create a file called publisher policy file or policy file. This file contains the configuration setting for redirecting the runtime to use newer version of the assembly wherever the older version is referenced. Policy files are also installed in the GAC. The bindingRedirect tag is used to change the dependency among assemblies. This is depicted using following code

culture="neutral" />

dependentAssembly tag is used to link the two versions of the assembly. The assemblyIdentity tag is used specify which assembly along with its public key token. The bindingRedirect tag specifies the older version of the assembly and the newer version of the same assembly which is to be used.

Once the publisher policy file is created it has to be linked to an assembly using the assmebly linker (al) tool. Refer to this article for how to use al tool. A publisher policy file is used to describe the compatibility of the assembly which is issued by the publisher. The old version attribute can be set to a range of values as well. Eg. you can say 1.1.*.*-2.0.*.*

Sometimes due to some reasons it becomes neccessary for the client applications to use the older version of the assembly even if the newer version is installed in GAC and publisher policy is supplied by the publisher. In that case the client application can override the publisher policy settings in its own apllication config file. To know more about applying publisher policies refer to msdn article.

I had encountered similar situation in one of the projects which I had worked on. We were using Sybase as backend database. To connect to the DB we were using ASE client for .NET. But due to some reason the version of Sybase was different on the development machines and the production machines. The code which was working perfectly fine on development boxes was throwing exception in the production environment. After investigating we realised the difference in versions and the publisher policy which was installed in GAC. We had to configure the application not to apply publisher policy and work with the older version of Sybase.

Hope this is of some help. Happy Programming :)

Encoding / decoding URL's

I was caught up in the web created by HTML /Javascript/ ASP.NET due to a very common problem related to URL encoding. For my current project I had to call a popup from an aspx page using client side code written in Javascript. Everything worked fine untill a day came where there was a special character to be passed in the query string.
The special character which was to be passed was '&' and that also happens to be a a special character for query string to seperate different values. My initial thinking was that javascript's good old escape function would do the job for me. But escape does encoding only for spaces and +. The '&' is left as it is because it's a valid character for escape sequence.
After doing few rounds of google I came across two functions which did the job for me. One of them is encodeURI and the one which I used was encoreURIComponent.
Please refer following article for further reading article.

Once the values were encoded correctly on client side it was only a matter of using the capabilities of Server side coding and decoding it back to its original value. Server.HtmlDecode does the job without any fuss.

Hope this is of some help. Happy programming :)

The reference library

I don't know how many people like to read the e-books like I prefer to do. One of the advantages with the books is that you don't require the physical space (other than some MBs on your hard drive). You can carry them anywhere on your laptop or a pen drive. And the contents remain the same. There is no wear and tear.
From various sources, I have a good collection of e-books on various subjects ranging from technical to self-help books. Today I came across a site which offers free downloads for some of the most recently released books on Microsoft technologies. Get you copy now before somebody goes and disables these links