LoaderLock was detected

eyekroneyekron Posts: 13

My test project is a win forms application and I'm running both a data compare and structure compare. Every once in awhile for what appears to be no reason at all I get this error:

LoaderLock was detected:

DLL 'C:\Temp\TestDataComp\bin\Debug\RedGate.Licensing.Helper.dll' is 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.

This error doesn't ever occur in any code that is actually related to the RedGate functions, but does seem to happen any time I call a custom DevExpress xrDesignPanel form.

Has anyone else seen this error and do you know how to avoid getting it?


  • Brian DonahueBrian Donahue Posts: 6,590 New member

    This could be getting thrown out as a result of the licensing component when compiling Toolkit projects on Visual Studio 2005. The reason for this is not clear -- we're looking at the licensing components to try to find the problem.

    This isn't harmful aside from being mildly annoying. The LoaderLock message can be dismissed by closing it (or clicking continue, depending on the particular style of messagebox studio decides to show). This shouldn't have any effect on your project or on the compiled code once it's deployed to your customers.
  • :(
    When I click to continue an empty command prompt window opens and does nothing. If it makes any difference, I am using the trial version to evaluate the Toolkit (I am a licensed user of the SQL Bundle). This is my code:

    Imports RedGate.SQL.Shared
    Imports RedGate.SQLCompare.Engine
    Imports RedGate.SQLDataCompare.Engine
    Imports RedGate.SQLDataCompare.Engine.ResultsStore
    Imports RedGate.SQLDataCompare.Engine.TableMapping

    Module Module1

    Sub Main()
    End Sub

    Sub DataCompare()

    Dim provider As New RedGate.SQLDataCompare.Engine.SqlProvider

    Dim db1 As New RedGate.SQLCompare.Engine.Database
    Dim db2 As New RedGate.SQLCompare.Engine.Database

    db1.RegisterForDataCompare(New ConnectionProperties("STLSQL01", "ACG", "appuser", "resuppa"))
    db2.RegisterForDataCompare(New ConnectionProperties("CHIDEV02", "WM", "appuser", "resuppa"))

    Dim mappings As New TableMappings
    mappings.CreateMappings(db1.Tables, db2.Tables)

    Dim session As New ComparisonSession()
    session.CompareDatabases(db1, db2, mappings)

    Dim Mapping As TableMapping

    For Each Mapping In mappings
    Dim table As ViewTableSuperClass = Mapping.Obj1
    Dim difference As TableDifference = session.TableDifferences(Table.FullyQualifiedName)
    Dim row As Row
    For Each row In difference.ResultsStore 'loop through all the rows
    If (row.Type <> row.RowType.Same) Then 'go through the non same records
    Dim field As FieldPair
    Dim i As Int32 = 0
    Console.WriteLine("{0} Row {1} type {2}", table.FullyQualifiedName, row.Index, row.Type.ToString())
    For Each field In difference.ResultsStore.Fields
    'work out where about in the results the field data is stored
    'if we were comparing identical records, or records present in one
    'database but not the other then we would not need to
    'use the OrdinalInResults1 and OrdinalInResults2 properties
    'but just OrdinalInResults
    Dim field1 As Int32 = Field.OrdinalInResults1
    Dim field2 As Int32 = Field.OrdinalInResults2

    If (field1 <> field2) Then
    'get the values
    Dim value1 As Object = Row.Values(field1)
    Dim value2 As Object = Row.Values(field2)
    If (value1 Is Nothing) Then
    value1 = "NULL"
    End If
    If (value2 Is Nothing) Then
    value2 = "NULL"
    End If
    If row.FieldDifferent(i) Then
    Console.WriteLine("{0}:{1} <> {2}", field.Field(False).Name, value1.ToString(), value2.ToString())
    Console.WriteLine("{0}:{1} == {2}", field.Field(False).Name, value1.ToString(), value2.ToString())
    End If
    'this is part of the unique index we are comparing on
    Dim value As Object = Row.Values(field1)
    Console.WriteLine("*{0}:{1}", field.Field(False).Name, value.ToString())
    End If
    i += 1
    End If

    'we want to run the SQL on WM so pass in true as the second parameter
    'Dim block As ExecutionBlock = provider.GetMigrationSQL(session, True)
    'Console.WriteLine("Migration SQL:")

    'Dim executor As BlockExecutor = New BlockExecutor
    'executor.ExecuteBlock(block, "CHIDEV02", "WM")

    End Sub

    End Module
  • Just a thought - what OS and architecture are you attempting to do this on. If you're on Vista or 64 bit I've honestly no idea how it will behave.

    Like Brian says normally you can just continue through the loader lock without a problem.

    Also are you running as an administrator as the system has to write some information to special file locations and registry locations when you activate for the first time.
    Richard Mitchell
    Project Manager
    Red Gate Software Ltd
  • OS = Windows XP Pro

    I tried using Visual Studio 2005 and then, when that failed, Visual Studio 2003. Neither worked. What happens is I get a message saying it's a trial version and to click "Skip" to continue. Then a second message appears telling me that it's an unlicensed version and I should see the web site for activation details. It's an endless loop and that's where I get stuck. I included the license.licx file, as suggested in the sample.
  • Are you still within your 14 day trial or is it possible that this has expired?
    Richard Mitchell
    Project Manager
    Red Gate Software Ltd
  • Expires 12/18/2006
  • Have you tried compiling the sample toolkit applications that are in the Red Gate directory in program files to make sure it isn't some strange setup with your project?
    Richard Mitchell
    Project Manager
    Red Gate Software Ltd
  • Yes. I can get it to run, but it bombs on this line:

    For Each row In difference.ResultsStore

    I think it is due to the fact that a table that exists on DB1 does not exist on DB2 and so the difference object is empty. I tried unsuccessfully to code around it.
  • Brian DonahueBrian Donahue Posts: 6,590 New member

    You normally wouldn't get a loader lock from the Toolkit component here; the one you should get would be at Database db=new Database(). That would invoke the licensing dll of ours which seems to contain some unsafe code (it still hasn't been revealed to me for sure exactly what causes it).

    Maybe there is something in your own code; unsafe blocks or PInvokes or something like that?
  • Just to supply additional information. Today I upgraded to VS 2005 from 2003 and now I receive the Loader lock message. I was able to continue through the message without any problem.

    I'm on XP as well
  • Brian DonahueBrian Donahue Posts: 6,590 New member

    Yes -- the LoaderLock appears only in Visual Studio .NET 2005. We are (still) trying to identify and fix the cause of this.
  • :idea: to disable the LoaderLock exepcion just click debug, and exeptions menu, and then deactivate the LoaderLock check box, LoaderLock is a dma exeption, then you do this, your dll works in vs 2005 :idea:
  • Just to let you all know, we've got a fix for this in the next releases of the products. It's all to do with attempting to load a dll whilst another dll is being loaded. The fix is being put through thorough testing and should be with you before too long.

    Hope this helps :)
    Richard Mitchell
    Project Manager
    Red Gate Software Ltd
  • mihiesmihies Posts: 71 Bronze 4
    richardjm wrote:
    Just to let you all know, we've got a fix for this in the next releases of the products. It's all to do with attempting to load a dll whilst another dll is being loaded. The fix is being put through thorough testing and should be with you before too long.

    Hope this helps :)

    I am still getting the exception with the latest version...
    Miha Markic [MVP C#, INETA Country Leader for Slovenia]
    Righthand .net consulting and software development
  • Brian DonahueBrian Donahue Posts: 6,590 New member
    Hi Miha,

    Thanks for noticing. The updated licensing components didn't make it into the latest SQL Bundle release. They will ship in version 6.
  • Which version are you using? You can find this out by going to the help menu and then about in the UI of SQL Compare or SQL Data Compare. Alternatively you can tell me the version number that Visual studio is reporting for the referenced Red Gate dlls.
    Richard Mitchell
    Project Manager
    Red Gate Software Ltd
Sign In or Register to comment.