Posts

Showing posts from March, 2013

How dangerous can be “public const” while upgrading or fixing a component.

Image
During my investigation I have noticed a source of potential problem for product upgrade where dev team should fix a bug or upgrade a component and distribute it. So what will happen when during fix/upgrade process (I will call it upgrade) a value which was declared as public const was changed. For clear understanding we should see how build process is done. Actually during build process all variables which consume const will be hardcoded. It is not a problem when it is references from the same project, component will be rebuilt anyway. But what if it is referenced from another dll? The value will remain hardcoded and will contain old value. Tools.dll MyConstants.cs
public const int DEFAULT_PORT = 80;
Service.dll Host.cs
StartService(DEFAULT_PORT);
So after upgrade of Tools.dll and change of the DEFAULT_PORT to 8080, Service.dll still will try to start service on 80 port! That is easy to test, just build a solution, copy components to another folder, change const value, rebuild and co…