0

I am new to EF Core 2.0.

I have a Model, that should be translated to MSSQL via Migration files. Unfortunatelly this file is not created. This is my Model:

public class SudokuData
{
    public int SudokuDataId { get; set; } // autogenerated via SQLServer FE
    public SudokuBoard defaultSetting { get; set; } // Setting set by user. Starting Configuration.
    public ICollection<SudokuBoard> solutions { get; set; } // every found Solution
    […]
}

public class SudokuBoard
{
    public int SudokuBoardId { get; set; } // autogenerated via SQLServer FE
    public ICollection<Cluster> clusters { get; set; } // For jigsaw etc. different set Clusters.
    public int[,] boardValues { get; set; }
    public int xDimension { get; set; }
    public int yDimension { get; set; }
    […]
}

public class Cluster // diferent cluster for jigsaw sudoku
{
    public int ClusterId { get; set; } // autogenerated via SQLServer FE
    public List<Point> list { get; set; }
    [...]
}

After executing “add-migration xyz” in Package Manager console I got following error:

Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.

Translated it means something like:

The reference is not set to an instance of an object.

EDIT: To beesure I am in the correct project I entered:

PM> dir


Directory: C:\projects\SudokuSolver\SudokuSolverServer\SudokuSolverServer


Mode                LastWriteTime         Length Name                                                                                                                                                                         
----                -------------         ------ ----                                                                                                                                                                         
d-----       22.10.2018     12:21                App_Data                                                                                                                                                                     
d-----       23.10.2018     10:02                App_Start                                                                                                                                                                    
d-----       23.10.2018     10:02                Areas                                                                                                                                                                        
d-----       23.10.2018     10:32                bin                                                                                                                                                                          
d-----       23.10.2018     10:02                Content                                                                                                                                                                      
d-----       25.10.2018     11:57                Controllers                                                                                                                                                                  
d-----       24.10.2018     11:40                Core                                                                                                                                                                         
d-----       23.10.2018     10:02                fonts                                                                                                                                                                        
d-----       23.10.2018     11:52                Migrations                                                                                                                                                                   
d-----       25.10.2018     12:14                Models                                                                                                                                                                       
d-----       23.10.2018     10:02                obj                                                                                                                                                                          
d-----       23.10.2018     10:02                Properties                                                                                                                                                                   
d-----       25.10.2018     12:14                Repositories                                                                                                                                                                 
d-----       23.10.2018     10:02                Scripts                                                                                                                                                                      
d-----       23.10.2018     10:02                Views                                                                                                                                                                        
-a----       22.10.2018     12:21           7305 ApplicationInsights.config                                                                                                                                                   
-a----       22.10.2018     12:21          32038 favicon.ico                                                                                                                                                                  
-a----       22.10.2018     12:21            113 Global.asax                                                                                                                                                                  
-a----       22.10.2018     12:21            694 Global.asax.cs                                                                                                                                                               
-a----       23.10.2018     10:19           5220 packages.config                                                                                                                                                              
-a----       24.10.2018     10:14          28825 SudokuSolverServer.csproj                                                                                                                                                    
-a----       24.10.2018     10:14           1457 SudokuSolverServer.csproj.user                                                                                                                                               
-a----       23.10.2018     10:19           4797 Web.config                                                                                                                                                                   
-a----       22.10.2018     12:21           1272 Web.Debug.config                                                                                                                                                             
-a----       22.10.2018     12:21           1333 Web.Release.config 

But there is not hint which reference or which object… and how do i solve this error?

Tagamoga
  • 332
  • 4
  • 18
  • Have you seen this? https://stackoverflow.com/questions/33241443/enable-migrations-object-reference-not-set-to-an-instance-of-an-object – Viggo Lundén Oct 26 '18 at 08:05
  • well, in the first step I had a different model without Collections. These Migration files were created correctly... so I think, that migrations are already enabled... – Tagamoga Oct 26 '18 at 08:23
  • 1
    Possible duplicate of [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – dymanoid Oct 26 '18 at 08:34
  • I used the model already in serveral constelations and added a little bit unittesting. Using it beside MSSQL does not throw a NullReferenceException. Everything seems to be correctly instanced. – Tagamoga Oct 26 '18 at 08:37
  • Double check the settings on the PowerShell pane you are firing this command it. Make sure you are on the correct project. Also check the project that is configured to start debugging with: these can override the settings and thus change the project PS will run on. – Rob Bos Oct 26 '18 at 08:44
  • @dymanoid, please read the question before marking it as a duplicate. OP clearly knows what a null reference exception is, but is having a hard time tracing the error back to the throwing source. – Viggo Lundén Oct 26 '18 at 08:45
  • I have added my search for the right project. It seems to be correct... – Tagamoga Oct 26 '18 at 10:00
  • Have you tried executing it with --verbose? Might give a bit more insight into where it actually fails. – MX D Oct 26 '18 at 10:01
  • @ViggoLundén I'm not going to close this question as a duplicate (just yet) but the purpose of the duplicate is not *only* to tell you what that exception is, but also teach/show the troubleshooting steps required to find the reason for why it is happening. This is still valuable. To start this troubleshooting, **what is the stack trace of that exception**? – Lasse V. Karlsen Oct 26 '18 at 10:08

0 Answers0