I have had a bug recently that only manifested itself when the library was built as a release build rather than a debug build. The library is a .NET dll with a COM wrapper and I am using CoCreateInstance to create a class from the dll in an unmanaged c++ app. When I finally tracked the bug down it was caused by accessing a singleton object. I had the singleton instance declared like so:
private static readonly MyObjectType s_instance = new MyObjectType;
and then accessed it with:
public static MyObjectType Instance
{
get
{
return s_instance;
}
}
this was failing. Changing it to:
private static MyObjectType s_instance;
public static MyObjectType Instance
{
get
{
if (s_instance==null)
{
s_instance = new MyObjectType();
}
return s_instance;
}
}
fixed the issue. Any ideas why the initial usage didn't work and if there are any downsides to doing it either way?
The release dll seemed to be perfectly usable from another managed app.