Tharpa Roberts

Tharpa Roberts

  • 1.7k
  • 13
  • 628

Non-nullable field must contain a non-null value when exiting construc

Sep 14 2023 7:23 PM

So there was a class with an existing constructor with two fields.  I do not want to interfere with the existing constructor:

 

//existing
private IAuthDataProvider testAuthDBProvider;
private IPropertyProvider testPropertyProvider;
//I added
private IConnectorResolver testConnectorResolver;
private IAppContainerProvider testAppContainerProvider;
private IBlobStorageClient testBlobStorageClient;

//existing constructor
public TestAuthenticationProvider(IAuthDataProvider authDBProvider, propertyProvider)
{
     testAuthDbProvider = authDbProvider;
     testPropertyProvider = propertyProvider;
}

//I added this constructor
public TestAuthenticationProvider(IAuthDataProvider authDBProvider, propertyProvider, IConnectorResolver connectorResolver, IAppContainerProvider containerProvider, IBlobStorageClient blobStorageclient)
{
      testAuthDbProvider = authDbProvider;
     testPropertyProvider = propertyProvider;
      testConnectorResolver = connectorResolver;
     testAppContainerProvider = containerProvider;

     testBlobStorageClient = blobStorageclient;
}

And it seems to work okay.  However, I now get a warning over the existing constructor:

Non-nullable field must contain a non-null value when exiting constructor.  Consider declaring the field as nullable.

But I can't declare it nullable.  When I try I get an error that it must be non-nullable.

 


Answers (4)