MicrosoftDocs/mslearn-dotnetmaui-store-local-data

System.NullReferenceException: "Object reference not set to an instance of an object.

Closed this issue · 1 comments

https://learn.microsoft.com/ru-ru/training/modules/store-local-data/4-exercise-store-data-locally-with-sqlite
Hello, I may be wrong, but in your tutorial I found a small problem due to which the entire program does not work.
in your lesson it is written like this:
class PersonRepository
"private void Init()
{
if (conn != null)
return;

conn = new SQLiteConnection(_dbPath);
conn.CreateTable<Person>();

}"

But in visual studio the following error appears: "System.NullReferenceException: "Object reference not set to an instance of an object."

To fix this error you need to write this:
"private void Init()
{
conn = new SQLiteConnection(_dbPath);
if (conn == null)
return;

 conn.CreateTable<Person>();

}"

The logic is correct. The first time you call Init it will be null and will create a new one. I just did the module and working great for me.