Why is this an issue?
A thread acquiring a lock on an object that can be accessed across application domain boundaries runs the risk of being blocked by another thread
in a different application domain. Objects that can be accessed across application domain boundaries are said to have weak identity. Types with weak
identity are:
-
MarshalByRefObject
-
ExecutionEngineException
-
OutOfMemoryException
-
StackOverflowException
-
String
-
MemberInfo
-
ParameterInfo
-
Thread
Noncompliant code example
Public Class Sample
Private myString As String = "foo"
Public Sub Go()
SyncLock myString ' Noncompliant
End SyncLock
End Sub
End Class
Compliant solution
Public Class Sample
Private Shared ReadOnly fLock As New Object
Public Sub Go()
SyncLock fLock
End SyncLock
End Sub
End Class