LoaderLock was detected
eyekron
Posts: 13
Hello,
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?
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?
Comments
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()
DataCompare()
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())
Else
Console.WriteLine("{0}:{1} == {2}", field.Field(False).Name, value1.ToString(), value2.ToString())
End If
Else
'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
Next
End If
Next
difference.Dispose()
Next
'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:")
'Console.WriteLine(block.GetString())
'Dim executor As BlockExecutor = New BlockExecutor
'executor.ExecuteBlock(block, "CHIDEV02", "WM")
session.Dispose()
'block.Dispose()
db1.Dispose()
db2.Dispose()
End Sub
End Module
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.
Project Manager
Red Gate Software Ltd
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.
Project Manager
Red Gate Software Ltd
Project Manager
Red Gate Software Ltd
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.
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?
I'm on XP as well
Yes -- the LoaderLock appears only in Visual Studio .NET 2005. We are (still) trying to identify and fix the cause of this.
Hope this helps
Project Manager
Red Gate Software Ltd
I am still getting the exception with the latest version...
Blog:http://blog.rthand.com
Righthand .net consulting and software development
http://www.rthand.com
Thanks for noticing. The updated licensing components didn't make it into the latest SQL Bundle release. They will ship in version 6.
Project Manager
Red Gate Software Ltd