Manage Nuget Packages give Object Reference not set to an instance of an object on Scaffolding

Bar Mashiach 6 Reputation points
2022-11-17T10:57:47.63+00:00

Getting the Object Reference not set to an instance of an object when trying to do scaffolding on a asp.net core mvc project i am working on.
I already did the scaffolding when i started the project and now i have updated the database and and i need to do the scaffolding again but i am getting the error.

![261463-image.png]1

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
752 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,622 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,029 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Shivanka de Silva 1 Reputation point
    2022-12-31T04:13:51.557+00:00

    I too had the same issue, for me it was due to a table without a primary key. once I add the primary key to the table it worked. use this script to find the table/s without primary key

    select schema_name(tab.schema_id) as [schema_name],
    tab.[name] as table_name
    from sys.tables tab
    left outer join sys.indexes pk
    on tab.object_id = pk.object_id
    and pk.is_primary_key = 1
    where pk.object_id is null
    order by schema_name(tab.schema_id),
    tab.[name]

    I found my solution from this thread https://github.com/dotnet/efcore/issues/29516

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.