Go to Google Groups Home    microsoft.public.dotnet.framework
RE: VS 2005 LoaderLock problem

Dan <d...@discussions.microsoft.com>

Hi,
I'm using Microsoft Sql Management Objects (SMO) -  the sql 2005 version of
SQL_DMO) to obtain information about a table's schema.

I have this code:
List<SMOColumn> GetTableSchema( string tableName, bool onlyPKs )
{
     Database db = sqlSrv.Databases[ dbName ];
...

}

When I execute the code from VS 2005, at this line, I get this exception:
"LoaderLock was detected
Message: Attempting managed execution inside OS Loader lock. Do not attempt
to run managed code inside a DllMain or image initialization function since
doing so can cause the application to hang."
and the application hangs.

However, when I run the unit tests (with Nunit) that go into the same code,
the damn thing works flawlessly.

Why this exception appears and how can I get rid of it?

Many thanks,
Dan