I’ve following piece of code which implements the singleton class (Double-Check Locking)
public sealed class Plugin
{
#region Private Fields
private static volatile Plugin _instance;
private static object syncRoot = new Object();
private Dictionary<int, string> myMap;
#endregion
private Plugin()
{
myMap = MapInit(GetMainModuleName());
}
static Plugin()
{ }
public static Plugin Instance
{
get
{
if (_instance == null)
{
lock (syncRoot)
{
if (_instance == null)
_instance = new Plugin();
}
}
return _instance;
}
}
}
The singleton instance is constructed properly in the debug mode, and everything seems to be working fine. But in the release mode, the instance is returned before it is constructed properly i.e., the myMap is not initialized.
Also it is to be noted that following code takes around 10 -15 secs to be executed completely in debug mode
myMap = MapInit(GetMainModuleName());
Is this the problem with some compiler optimization? Please help
Ok, here’s the actual problem which may sound naive. The dll with the above code was loaded into the main application which had a exe.config which was invalid. And since my dll had seperate dll.config(which is valid) the application was working fine when run through the debugger, but when run in deployment enviroment(without debugger attached), it was encountering the invalid config file exception.
I’ve made the main exe.config as valid config file and it works now.
So basically , the solution is as naive as checking if there is exception in the construction process.