dotnet / ef6

This is the codebase for Entity Framework 6 (previously maintained at https://entityframework.codeplex.com). Entity Framework Core is maintained at https://github.com/dotnet/efcore.
https://docs.microsoft.com/ef/ef6
MIT License
1.43k stars 544 forks source link

EF EDMX From Database "Object reference not set..." #1701

Closed Ya-Wang closed 2 years ago

Ya-Wang commented 4 years ago

Using Add > ADO.NET Entity Data Model

Microsoft Visual Studio Enterprise 2019 Version 16.6.2 VisualStudio.16.Release/16.6.2+30204.135 Microsoft .NET Framework Version 4.8.03752

Please see included screen shot.

Capture

Any ideas?

Works fully in VS2017. And is fully fuctional (can update) after creation using VS2017.

ErikEJ commented 4 years ago

When in the process do you get this error - in other words, more detailed repro steps, please.

Ya-Wang commented 4 years ago

Reproduce by,

  1. Right clicking on project image

  2. Add ADO.NET Entity Data Model image

  3. EF Designer from Database image

  4. Just pick a sql server and next image

  5. Pick any table.

  6. Error, emdx files empty but created.

SSDiver2112 commented 4 years ago

I have been working on this and searching for an answer the past couple of days. I have deleted and recreated the edmx files many times rebuilding and restarting etc. trying to find a magic combination. The files below are created, but not the .tt files.

image

Double clicking the edmx file returns one of these two messages.

image or image

The .tt files can be made, but only from the designer, which won't open. I did this last week and everything was working Friday. Monday I needed to make some changes and now the edmx is incomplete and nothing will work anymore.


Microsoft Visual Studio Community 2019 Preview Version 16.7.0 Preview 3.1 VisualStudio.16.Preview/16.7.0-pre.3.1+30223.230 Microsoft .NET Framework Version 4.8.03752

Installed Version: Community

ADL Tools Service Provider 1.0 This package contains services used by Data Lake tools

ASA Service Provider 1.0

ASP.NET and Web Tools 2019 16.7.392.237 ASP.NET and Web Tools 2019

ASP.NET Core Razor Language Services 16.1.0.2030908+50b4350fabebe02aa08844cd3c1fa2a490107f5f Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2019 16.7.392.237 For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0 16.7.392.237 Azure App Service Tools v3.0.0

Azure Data Lake Node 1.0 This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio 2.4.6000.1 Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools 16.7.392.237 Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio 2.4.6000.1 Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools 3.7.0-3.20312.3+ec4841263590f5456e32728d98097e97c1605e22 C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Code alignment 14.1.107.0 Code alignment helps you present your code beautifully, enhancing clarity and readability.

CodeRush for Roslyn 20.1.4.0 DevExpress CodeRush for Roslyn package.

CodeRush for Roslyn Tool Windows 20.1.4.0 DevExpress CodeRush for Roslyn Tool Windows package.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Entity Framework 6 Power Tools 0.9.2 Preview of useful design-time DbContext features, added to the Visual Studio Solution Explorer context menu.

When right-clicking on a file containing a derived DbContext class, the following context menu functions are supported: 1) View Entity Data Model (Read-only) - Displays a read-only view of the Code First model in the Entity Model Designer. 2) View Entity Data Model XML - Displays the EDMX XML representing the underlying Code First model. 3) View Entity Data Model DDL SQL - Displays the DDL SQL corresponding to the SSDL in the underlying EDM Model. 4) Generate Views - Generates pre-compiled views used by the EF runtime to improve start-up performance. Adds the generated views file to the containing project.

When right-clicking on an Entity Data Model (*.edmx) file, the following context menu function is supported: Generate Views - Generates pre-compiled views used by the EF runtime to improve start-up performance. Adds the generated views file to the containing project.

Microsoft Visual Studio Community 2019 Preview Version 16.7.0 Preview 3.1

Fabric.DiagnosticEvents 1.0 Fabric Diagnostic Events

IntelliCode Extension 1.0 IntelliCode Visual Studio Extension Detailed Info

KnownMonikers Explorer 1.1.28 A tool window for Visual Studio extension authors to explore the KnownMonikers image collection

Microsoft Azure HDInsight Azure Node 2.4.6000.1 HDInsight Node under Azure Node

Microsoft Azure Hive Query Language Service 2.4.6000.1 Language service for Hive query

Microsoft Azure Service Fabric Tools for Visual Studio 16.0 Microsoft Azure Service Fabric Tools for Visual Studio

Microsoft Azure Stream Analytics Language Service 2.4.6000.1 Language service for Azure Stream Analytics

Microsoft Azure Stream Analytics Node 1.0 Azure Stream Analytics Node under Azure Node

Microsoft Azure Tools 2.9 Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.30415.2

Microsoft Continuous Delivery Tools for Visual Studio 0.4 Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager 2.1.79+ge3567815aa.RR Install client-side libraries easily to any web project

Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual Studio Tools for Containers 1.1 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

NuGet Package Manager 5.7.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info

SQL Server Data Tools 16.0.62006.04220 Microsoft SQL Server Data Tools

Swap Selection 1.2 Using Multi-Selection to select two pieces of text and then swap them.

ToolWindowHostedEditor 1.0 Hosting json editor into a tool window

TypeScript Tools 16.0.20610.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 3.7.0-3.20312.3+ec4841263590f5456e32728d98097e97c1605e22 Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.10.0.0 for F# 4.7 16.7.0-beta.20304.1+7673d5e78eca5bccb77a7e4561c9d9429bdc5f35 Microsoft Visual F# Tools 10.10.0.0 for F# 4.7

Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Container Tools Extensions (Preview) 1.0 View, manage, and diagnose containers within Visual Studio.

Visual Studio Tools for Containers 1.0 Visual Studio Tools for Containers

SSDiver2112 commented 4 years ago

Hoped for some response this morning. This is occurring on my work and home computer. To eliminate any conflict with my working solution I started a brand new empty Solution added EF6, added new ADO.NET Entity Data Model, and same result. Please help as soon as possible.

ErikEJ commented 4 years ago

@SSDiver2112 Have you tried a non preview VS version?

SSDiver2112 commented 4 years ago

Erik, OK good call. I un-installed Preview and Installed Production and works fine now. Didn't want to have to rebuild my comfy IDE environment, but now it works so thank you for the suggestion. Off to the extensions and options windows...

ErikEJ commented 4 years ago

@lajones FYI

lajones commented 4 years ago

We have a developer community report on "The extender provider failed to return an extender" - see this link (for my reference this maps to internal ticket 1146365). We are trying but unfortunately we're having difficulty finding an owner for the code that throws that exception.

I've also heard that 16.7.0 Preview 3.1 is a bit flaky and they are issuing a new preview.

All of that said, I can't repro the above at the moment. @Ya-Wang can we try to narrow it down a bit? Could you try to download a simple database such as Northwind see directions here and see if creating an EDMX from a well-known database works. If that works then we've narrowed it down to something specific to that database.

lajones commented 4 years ago

Also @SSDiver2112 - can you post the contents of the .edmx file? Or at least say whether it's empty or almost empty, compared to a normal .edmx file which will have lots of XML about your entities and tables etc.

SSDiver2112 commented 4 years ago

Doing a comparison of the .edmx files, the only difference is the DateTime types have Precision values in the correct working file and One extra DesignerProperty present in the Good file. otherwise they are identical.

image

image

lajones commented 4 years ago

@SSDiver2112 Thanks. Could you tell me what version of EntityFramework were you using in the 2 cases?

SSDiver2112 commented 4 years ago

both 6.4.4

Ya-Wang commented 4 years ago

I took AdventureWorks2014.bak and restored it to my 12.0.6108.1 sql server.

Created a new consoleApp project using .net framework 4.7.2 and followed the steps I initially posted and it work.

Below is the packages in the web api project that is throwing the error. The project is currently 4.6.1 net framework.

EDIT: checked on net framework 4.6.1 consoleapp from scratch and it works, apparently its just that web api project. Is there any troubleshooting steps I can take to fix this? Note, it works fine in vs2017 just not the latest vs2019

`<?xml version="1.0" encoding="utf-8"?>

`
lajones commented 4 years ago

@Ya-Wang If you do a new web api .net 4.6.1 project and try to create an EDMX in there does that work?

Ya-Wang commented 4 years ago

It seems to be a project issue.

Can you point me to any debugging tips for an issue like this?

joeruder commented 2 years ago

This is still happening today, in both 2019 and 2022. It happens on a 100% fresh VM created from a Azure image and a brand new project. New database server setup, single table. To clarify:

  1. create a new VM image with VS 2019 already installed (latest)
  2. create a new Azure SQL database server
  3. create a new database, with only 1 table with 3 test fields (Id, testField1 (varchar) testField2(int)
  4. connect to it, create the EDMX file
  5. get the error and resist throwing the computer out the window.

I also tried with VS 2022. I downloaded 2017 on the same machine and that works.

what is going on?

heerhaan commented 2 years ago

I encountered this exact problem, where it comes from seems pretty clear. Which is the code generator generating an incredibly outdated template which isn't supported anymore, mostly by using references to deprecated assemblies. As said by Joeruder this happens on both VS 2019 and 2022

Gods know why this happens though.

ajcvickers commented 2 years ago

This issue has been closed because EF6 is no longer being actively developed. We are instead focusing on stability of the codebase, which means we will only make changes to address security issues. See the repo README for more information.

Telavian commented 2 weeks ago

To anyone still having this issue. I just tried to add an edmx file to a legacy code base and had this problem in a new project. Using the newer style of csproj failed for me, however the older csproj style worked. I have no idea why.