dotnet / ef6tools

This is the codebase for the Entity Framework 6 and LINQ-To-SQL designers.
MIT License
35 stars 14 forks source link

Designer failing on EF 6.5.1 #65

Open robertmclaws opened 4 months ago

robertmclaws commented 4 months ago

So I know that getting the EDMX designer working with Microsoft.Data.SqlClient in EF 6.5.1 has not been a priority. However, the other day I was able to get the error message I usually get when attempting it to spit out a stack trace.

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Data.Entity.Design.VersioningFacade.LegacyProviderWrapper.LegacyDbProviderServicesWrapper.GetDbProviderManifest(String manifestToken)
   at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifest(String manifestToken)
   at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Loader.InitializeProviderManifest(Action`3 addError)
   at System.Data.Entity.Core.SchemaObjectModel.Schema.HandleAttribute(XmlReader reader)
   at System.Data.Entity.Core.SchemaObjectModel.SchemaElement.ParseAttribute(XmlReader reader)
   at System.Data.Entity.Core.SchemaObjectModel.SchemaElement.Parse(XmlReader reader)
   at System.Data.Entity.Core.SchemaObjectModel.Schema.HandleTopLevelSchemaElement(XmlReader reader)
   at System.Data.Entity.Core.SchemaObjectModel.Schema.InternalParse(XmlReader sourceReader, String sourceLocation)
   at System.Data.Entity.Core.SchemaObjectModel.Schema.Parse(XmlReader sourceReader, String sourceLocation)
   at System.Data.Entity.Core.SchemaObjectModel.SchemaManager.ParseAndValidate(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, AttributeValueNotification providerNotification, AttributeValueNotification providerManifestTokenNotification, ProviderManifestNeeded providerManifestNeeded, IList`1& schemaCollection)
   at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Loader.LoadItems(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths)
   at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Init(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths, Boolean throwOnError, IDbDependencyResolver resolver, DbProviderManifest& providerManifest, DbProviderFactory& providerFactory, String& providerInvariantName, String& providerManifestToken, Memoizer`2& cachedCTypeFunction)
   at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection..ctor(IEnumerable`1 xmlReaders, ReadOnlyCollection`1 filePaths, IDbDependencyResolver resolver, IList`1& errors)
   at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Create(IEnumerable`1 xmlReaders, ReadOnlyCollection`1 filePaths, IDbDependencyResolver resolver, IList`1& errors)
   at Microsoft.Data.Entity.Design.Model.Validation.RuntimeMetadataValidator.ValidateStoreModel(EntityDesignArtifact designArtifact)
   at Microsoft.Data.Entity.Design.Model.Validation.RuntimeMetadataValidator.ValidateArtifactSet(EFArtifactSet artifactSet, Boolean forceValidation, Boolean validateMsl, Boolean runViewGen)
   at Microsoft.Data.Entity.Design.Model.EntityDesignArtifact.DetermineIfArtifactIsStructurallySafe()
   at Microsoft.Data.Entity.Design.Model.EntityDesignArtifact.DetermineIfArtifactIsDesignerSafe()
   at Microsoft.Data.Entity.Design.VisualStudio.Model.VSArtifact.DetermineIfArtifactIsDesignerSafe()
   at Microsoft.Data.Entity.Design.Model.EFArtifact.get_IsDesignerSafe()
   at Microsoft.Data.Entity.Design.EntityDesigner.CustomSerializer.EntityModelToDslModelTranslatorStrategy.TranslateModelToDslModel(EFObject modelElement, Partition partition)
   at Microsoft.Data.Entity.Design.EntityDesigner.MicrosoftDataEntityDesignSerializationHelper.LoadModel(SerializationResult serializationResult, Partition partition, String fileName, ISchemaResolver schemaResolver, ValidationController validationController, ISerializerLocator serializerLocator)
   at Microsoft.Data.Entity.Design.EntityDesigner.MicrosoftDataEntityDesignSerializationHelper.LoadModelAndDiagram(SerializationResult serializationResult, Partition modelPartition, String modelFileName, Partition diagramPartition, String diagramFileName, ISchemaResolver schemaResolver, ValidationController validationController, ISerializerLocator serializerLocator)
   at Microsoft.Data.Entity.Design.Package.MicrosoftDataEntityDesignDocDataBase.Load(String fileName, Boolean isReload)
   at Microsoft.VisualStudio.Modeling.Shell.ModelingDocData.LoadDocData(String fileName, Boolean isReload)
   at Microsoft.Data.Entity.Design.Package.MicrosoftDataEntityDesignDocData.LoadDocData(String fileName, Boolean isReload)
   at Microsoft.VisualStudio.Modeling.Shell.DocData.ReloadDocDataWorker(UInt32 flags)
   at Microsoft.VisualStudio.Modeling.Shell.DocData.OnFileChangeTimerTick(Object sender, EventArgs e)
   at System.Windows.Forms.Timer.OnTick(EventArgs e)
   at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

I thought maybe it would help track the issue down. I'd love to help... are there any instructions for how to build & install a custom version of the designer in VS?

I can repro this NRE consistently, so I'm happy to help any way I can. Thanks!

ErikEJ commented 4 months ago

Can you share a repro or simple repro steps?

robertmclaws commented 4 months ago
  1. Open 64-bit Visual Studio 2022 17.11 Preview 5
  2. Create a LocalDB Database
  3. Add a couple tables
  4. Create a C# SDK-style project and set <TargetFrameworks>net48;net8.0</TargetFrameworks>
  5. Add <PackageReference Include="EntityFramework" Version="6.5.1" /> to an ItemGroup
  6. Add an EDMX file to the project and connect it to the LocalDB database
  7. Add the tables to the model & have them display on the designer
  8. Close the file
  9. Right click the file and select "Open with" and pick the XML editor
  10. Change the Provider to Microsoft.Data.SqlClient and save + close the file
  11. Double-click the file to re-open it
  12. Get an "Object reference not set to an instance of the object" message box
ErikEJ commented 4 months ago

@robertmclaws That looks like a duplicate of #31 actually

robertmclaws commented 4 months ago

It is not. It works just fine when you use the old provider. The problem is not with SDK-style projects, it's with parsing the provider string.