Examples of errors detected by the V3090 diagnostic

V3090. Unsafe locking on an object.


Old NASA World Wind (C#)

V3090 Unsafe locking on an object of type 'String'. GPSTrackerPlugin.APRS.cs 256


private int APRSParse(....)
{
  int iRet=-1;
  try
  {
    lock("ExternDllAccess")
    {
      //Call the APRS DLL
      iRet=APRSParseLinePosStat(sString,
                                ref aprsPosition,
                                ref aprsStatus);
    }
  }
  catch(Exception)
  {
    iRet=-1;
  }
  return iRet;
}

Identical errors can be found in some other places:

  • V3090 Unsafe locking on an object of type 'String'. GPSTrackerPlugin.File.cs 226
  • V3090 Unsafe locking on an object of type 'String'. GPSTrackerPlugin.File.cs 244
  • V3090 Unsafe locking on an object of type 'String'. GPSTrackerPlugin.File.cs 370
  • And 12 additional diagnostic messages.

Mono

V3090 Unsafe locking on a type. All instances of a type will have the same 'Type' object. corlib-net_4_x UnixRegistryApi.cs 245


public RegistryKey Ensure (....)
{
  lock (typeof (KeyHandler)){
    ....
  }
}

Identical errors can be found in some other places:

  • V3090 Unsafe locking on a type. All instances of a type will have the same 'Type' object. corlib-net_4_x UnixRegistryApi.cs 245
  • V3090 Unsafe locking on a type. All instances of a type will have the same 'Type' object. corlib-net_4_x UnixRegistryApi.cs 261
  • V3090 Unsafe locking on a type. All instances of a type will have the same 'Type' object. corlib-net_4_x UnixRegistryApi.cs 383
  • And 9 additional diagnostic messages.

Mono

V3090 Unsafe locking on a type. All instances of a type will have the same 'Type' object. System.Runtime.Remoting-net_4_x HttpRemotingHandlerFactory.cs 61


void ConfigureHttpChannel (HttpContext context)
{
  lock (GetType())
  {
    ....
  }
}

Mono

V3090 Unsafe locking on an object of type 'String'. System.Web-net_4_x ProfileBase.cs 95


const string Profiles_SettingsPropertyCollection =
               "Profiles.SettingsPropertyCollection";
....
static void InitProperties ()
{
  ....
  lock (Profiles_SettingsPropertyCollection) {
  if (_properties == null)
    _properties = properties;
  }
}


Do you make errors in the code?

Check your code
with PVS-Studio

Static code analysis
for C, C++ and C#

goto PVS-Studio;