Tag Archives: .NET

System.Configuration Namespace and Obsolete Functions

‘What Really Grinds My Gears’ (WRGMG) topic of the month:

Have you ever wondered why after adding System.Configuration namespace reference you see a link to System.configuration assembly (note a small ‘c’ instead of the capital one)?

And why calling obsolete functions in order to access your AppSettings through System.Configuration.ConfigurationSettings.AppSettings["myKey"] doesn’t require you adding any additional references, but using System.Configuration.ConfigurationManager.AppSettings["myKey"] requires you going to the project’s Add Reference dialog and adding System.Configuration explicitly?

The reason for that is unfortunately somewhat poor framework design, in particular backward compatibility implementation. In .NET versions starting from 2.0, class System.Configuration.ConfigurationSettings is actually stored in System.dll, and is basically a stub pointing to System.Configuration.ConfigurationManager, which exists in System.configuration.dll (note again small ‘c’).

Here is a good explanation in one of the older blog posts System.configuration.

However, as always the ultimate reference is good ole’ Reflector, which allows you to find exactly where each class is stored, and to peek inside implementation details. Such as delegated calls from deprecated stub class ConfigurationSettings (System.dll) to the new ConfigurationManager (System.configuration.dll).

Web Site Performance and JPEG Compression

As a consultant, throughout stabilizing and deployment phases, I get frequently asked to investigate performance of specific web pages or whole sites, in order to improve page rendering speed, lately more and more related to SharePoint environment.

And what I often see in breakdown of page rendering that it is not that server execution time, which lags behind and causes visual delays, but the size and amount of creative content, which was put on the web site – images and flash files. The easiest way to quickly look at the page load timing breakdown is probably by using FireBug’s Net tab, as it’s shown on this illustration.

There are many ways to optimize and enhance performance of specific web pages and web sites in general. One of the great examples of the process and approach to optimization, is documented in the blog of Microsoft SharePoint team, which has done amazing job speeding up SharePoint.Microsoft.com.

However, in this post, rather than talking about optimization in general, I want to draw your attention to one highly overlooked issue – the size of creative media content used on production web sites, specifically size of JPEG images and Flash pieces relying heavily on imagery.

Back in the days, when I was working in video encoding industry, I used to spend large chunk of my time working with different JPEG settings and libraries for motion JPEG video compression. JPEG has many different implementations, and all image editing software programs, such as PhotoShop, Picasa, Paint, etc. use their own libraries with proprietary JPEG-compression, which differs in compression speed, parallelism, and quality.

However, they all have one thing in common – a configurable characteristic of compression quality, often expressed in per centage, or 0-100. You can read more on JPEG compression quality on wikipedia, with lots of great examples and comparisons.

But I would like to compare samples, which are closer to real life situation, such a simple web site banner, and show what programs you can use to optimize image file compression.

Here’s a sample image saved with different image quality:

Original Image – PNG, Image size: 43KB
apticonlogo

JPEG Image – Quality: 100% (PhotoShop compression quality: Maximum), Size = 24KB
apticonlogo99

JPEG Image – Quality: 80% (PhotoShop compression quality: Very High), Image Size: 14KB
apticonlogo80

JPEG Image – Quality 60% (PhotoShop compression quality: High), Image size: 12KB
apticonlogo60

JPEG Image – Quality 30% (PhotoShop compression quality: Medium), Image size: 6KB
apticonlogo30

JPEG Image – Quality 10% (PhotoShop compression quality: Low), Image size: 4KB
apticonlogo10

As you can see the size differs drastically on the compression quality, and in many situations, when the images do not contain a lot of text or are related to professional photography, the quality can be lowered to reduce the size of the images. How low you should go is absolutely up to you and your attention to details. It is just important to remember to review image sizes before putting them online, and make an intelligent decision about how large do you want your image to be, and how fast you want your page to render on the screen of internet users.

The best way to review image sizes and quality if you are using PhotoShop CS editions is to choose to “Save for Web“. PhotoShop shows you image preview and quality comparison right in the save dialog:

apticonlogophotoshop

As far as free alternatives to PhotoShop go:

– if you are using Picasa, one of the ways to do that if you choose to ‘Export to Folder’, and specify ‘Image Quality’ in the dialog, opting for ‘Normal’, ‘Minimum’, or ‘Custom’ where you can specify the exact compression quality

– or you can use MS Paint, which by default already saves with relatively lossy compression settings, and which you can also override through the registry

How to Locate Assembly in GAC

Here is a simple step by step process of how to locate an assembly in GAC if you want to take a copy of it, or maybe add an additional debug information .pdb-file for remote debugging purposes.

  • open command prompt
  • change the current folder to c:\windows\assembly (%SystemRoot%\assembly)
  • navigate to GAC_MSIL folder – that is where most of the time you will find the assembly
    (the list of all other folders in Assembly, with explanation for some of them, is below)
  • find the folder name with your assembly name without extension and navigate to it
  • additionally navigate down one more folder with the version information, and your assembly should be in that folder

Structure of Assembly folder

Here are examples of what you might see in Assembly folder on different computers:

 Windows XP 32-bit workstation:
– GAC
– GAC_32
– GAC_MSIL
– NativeImages1_v1.1.4322
– NativeImages_v2.0.50727_32
– temp
– tmp

Windows Server 2008 64-bit server:
– GAC
– GAC_32
– GAC_64
– GAC_MSIL
– NativeImages_v2.0.50727_32
– NativeImages_v2.0.50727_64
– temp
– tmp

  • NativeImages… – folders used for native images, which are typically compiled by ngen.exe.
  • tmp folder used for installation assemblies to GAC
  • temp folder is for uninstallation from GAC

Here are some ‘under the hood’ details on GAC Temp and Tmp folders and Install and Uninstall of assemblies.

Opening GAC assemblies with .NET Reflector 

If you are using .NET Reflector there are two things you can do to look what’s inside that assembly from GAC:

  1. make a copy of your assembly from GAC folder to a local folder (the steps explained above) and open the assembly from that local folder
  2. edit your reflector settings file: reflector.cfg, and add the following GAC paths there, then you should be able to open assembly right from open menu:
    [AssemblyCache]

    “%SystemRoot%\Assembly”
    “%SystemRoot%\Assembly\GAC”
    “%SystemRoot%\Assembly\GAC_MSIL”
    “%SystemRoot%\Assembly\GAC_32”
    “%SystemRoot%\Assembly\GAC_64”