Why always null annotation

 So I've used resharper to add the "ambientLightSensor" parameter to the "ConnectSensor" method. And it does it with a null annotaion:

private void TryConnectLastUsedSensor()
if (_settings.LastUsedSensor == null) return;

var sensors = _sensor.GetSensors();
var lastUsedSensor = sensors.FirstOrDefault(s => s.FriendlyName == _settings.LastUsedSensor.FriendlyName);
if (lastUsedSensor == null) return;


private void ConnectSensor(AmbientLightSensor? ambientLightSensor)
IsSensorConnected = _sensorService.ConnectToSensor(SelectedSensor.FriendlyName);
if (IsSensorConnected) _settings.LastUsedSensor = SelectedSensor;

I don't understand why though. For one I check the object in the calling method if it's null and on the other hand Visual Studio tells me that "The annotation for nullable reference types should only be used in code within a '#nullable' annotations context." Is there a setting to turn this off?

Please sign in to leave a comment.