Bug 10271 - EntityFramework - NullReferenceException
Summary: EntityFramework - NullReferenceException
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Data ()
Version: master
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-02-13 07:42 UTC by Oleg
Modified: 2013-02-14 07:00 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Sample MonoDevelop project to reproduce error (2.34 MB, application/octet-stream)
2013-02-13 07:42 UTC, Oleg
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Oleg 2013-02-13 07:42:37 UTC
Created attachment 3364 [details]
Sample MonoDevelop project to reproduce error

Please, take a look on discussion at http://mono.1490590.n4.nabble.com/Entity-Framework-new-issues-tp4658551.html

There were bug 10245 and bug 6653 related to Entity Framework on Mono, they are fixed and next issue is NullReferenceException.

Attached archive contains sample MonoDevelop project with Entity Framework model first (bug affects code first approach too). Please note that archive includes trial license file that expires within a week. After this time it could be required to regenerate license file by following instructions at vendor site if there will be no open-source provider with EF 6 support at that time. Sample includes two optional libraries: System.Xml.dll and EntityFramework.dll, they are not required if you have latest sources from trunc, but they are if you use Mono 3.0.3 or earlier.

Full exception:

System.NullReferenceException: Object reference not set to an instance of an object 
  at System.Xml.XmlInputStream.Initialize (System.IO.Stream stream) [0x00000] in <filename unknown>:0 
  at System.Xml.XmlInputStream..ctor (System.IO.Stream stream) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Xml.XmlInputStream:.ctor (System.IO.Stream) 
  at System.Xml.XmlStreamReader..ctor (System.IO.Stream input) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Xml.XmlStreamReader:.ctor (System.IO.Stream) 
  at System.Xml.XmlTextReader..ctor (System.IO.Stream input) [0x00000] in <filename unknown>:0 
  at System.Xml.Schema.XmlSchema.Read (System.IO.Stream stream, System.Xml.Schema.ValidationEventHandler validationEventHandler) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.EntityModel.SchemaObjectModel.Schema+SomSchemaSetHelper.AddXmlSchemaToSet (System.Xml.Schema.XmlSchemaSet schemaSet, XmlSchemaResource schemaResource, System.Collections.Generic.HashSet`1 schemasAlreadyAdded) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.EntityModel.SchemaObjectModel.Schema+SomSchemaSetHelper.AddXmlSchemaToSet (System.Xml.Schema.XmlSchemaSet schemaSet, XmlSchemaResource schemaResource, System.Collections.Generic.HashSet`1 schemasAlreadyAdded) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.EntityModel.SchemaObjectModel.Schema+SomSchemaSetHelper.ComputeSchemaSet (SchemaDataModelOption dataModel) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.Common.Utils.Memoizer`2+<Evaluate>c__AnonStorey106[System.Data.Entity.Core.EntityModel.SchemaObjectModel.SchemaDataModelOption,System.Xml.Schema.XmlSchemaSet].<>m__100 () [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.Common.Utils.Memoizer`2+Result[System.Data.Entity.Core.EntityModel.SchemaObjectModel.SchemaDataModelOption,System.Xml.Schema.XmlSchemaSet].GetValue () [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.Common.Utils.Memoizer`2[System.Data.Entity.Core.EntityModel.SchemaObjectModel.SchemaDataModelOption,System.Xml.Schema.XmlSchemaSet].Evaluate (SchemaDataModelOption arg) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.EntityModel.SchemaObjectModel.Schema+SomSchemaSetHelper.GetSchemaSet (SchemaDataModelOption dataModel) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.EntityModel.SchemaObjectModel.Schema.CreateXmlReaderSettings () [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.EntityModel.SchemaObjectModel.Schema.Parse (System.Xml.XmlReader sourceReader, System.String sourceLocation) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.EntityModel.SchemaObjectModel.SchemaManager.ParseAndValidate (IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, System.Data.Entity.Core.EntityModel.SchemaObjectModel.AttributeValueNotification providerNotification, System.Data.Entity.Core.EntityModel.SchemaObjectModel.AttributeValueNotification providerManifestTokenNotification, System.Data.Entity.Core.EntityModel.SchemaObjectModel.ProviderManifestNeeded providerManifestNeeded, IList`1& schemaCollection) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection+Loader.LoadItems (IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection+Loader..ctor (IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, Boolean throwOnError) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Init (IEnumerable`1 xmlReaders, IEnumerable`1 filePaths, Boolean throwOnError, System.Data.Entity.Core.Common.DbProviderManifest& providerManifest, System.Data.Common.DbProviderFactory& providerFactory, System.String& providerManifestToken, System.Data.Entity.Core.Common.Utils.Memoizer`2& cachedCTypeFunction) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection..ctor (IEnumerable`1 xmlReaders, IEnumerable`1 filePaths) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.Metadata.Edm.MetadataCache+StoreMetadataEntry.LoadStoreCollection (System.Data.Entity.Core.Metadata.Edm.EdmItemCollection edmItemCollection, System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoader loader) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.Metadata.Edm.MetadataCache+StoreItemCollectionLoader.LoadItemCollection (System.Data.Entity.Core.Metadata.Edm.StoreMetadataEntry entry) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.Metadata.Edm.MetadataCache.LoadItemCollection[StoreMetadataEntry] (IItemCollectionLoader`1 itemCollectionLoader, System.Data.Entity.Core.Metadata.Edm.StoreMetadataEntry entry) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.Metadata.Edm.MetadataCache.GetOrCreateStoreAndMappingItemCollections (System.String cacheKey, System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoader loader, System.Data.Entity.Core.Metadata.Edm.EdmItemCollection edmItemCollection, System.Object& entryToken) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.EntityClient.EntityConnection.LoadStoreItemCollections (System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace workspace, System.Data.Common.DbConnection storeConnection, System.Data.Entity.Core.EntityClient.Internal.DbConnectionOptions connectionOptions, System.Data.Entity.Core.Metadata.Edm.EdmItemCollection edmItemCollection, System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoader artifactLoader) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.EntityClient.EntityConnection.GetMetadataWorkspace (Boolean initializeAllCollections) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.EntityClient.EntityConnection.GetMetadataWorkspace () [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.EntityClient.EntityConnection.InitializeMetadata (System.Data.Common.DbConnection newConnection, System.Data.Common.DbConnection originalConnection, Boolean closeOriginalConnectionOnFailure) [0x00000] in <filename unknown>:0
Comment 1 Atsushi Eno 2013-02-13 07:54:19 UTC
Reverting back to Sys.Data. There is nothing that says it is Sys.Xml issue.

The repro seems dependent on the private environment - I get this error instead:

Unhandled Exception:
System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> Devart.Data.PostgreSql.PgSqlException: Connection refused
  at Devart.Data.PostgreSql.v.w () [0x00000] in <filename unknown>:0 
  at Devart.Data.PostgreSql.v.b () [0x00000] in <filename unknown>:0 
  at Devart.Common.DbConnectionInternal.ax () [0x00000] in <filename unknown>:0 
  at Devart.Common.DbConnectionFactory.b (Devart.Common.DbConnectionBase A_0) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Data.Entity.Core.EntityClient.EntityConnection.OpenStoreConnectionIfStoreConnectionNotOpened (System.Data.Common.DbConnection storeConnectionToOpen, System.String exceptionCode, System.String attemptedOperation, System.Boolean& closeStoreConnectionOnFailure) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.EntityClient.EntityConnection.Open () [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection () [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.Objects.ObjectQuery`1[TestModel.Product].GetResults (Nullable`1 forMergeOption) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.Objects.ObjectQuery`1[TestModel.Product].<GetEnumerator>m__2C3 () [0x00000] in <filename unknown>:0 
  at System.Lazy`1[System.Collections.Generic.IEnumerator`1[TestModel.Product]].InitValue () [0x0014f] in /svn/mono/mcs/class/corlib/System/Lazy.cs:156 
[ERROR] FATAL UNHANDLED EXCEPTION: System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> Devart.Data.PostgreSql.PgSqlException: Connection refused
  at Devart.Data.PostgreSql.v.w () [0x00000] in <filename unknown>:0 
  at Devart.Data.PostgreSql.v.b () [0x00000] in <filename unknown>:0 
  at Devart.Common.DbConnectionInternal.ax () [0x00000] in <filename unknown>:0 
  at Devart.Common.DbConnectionFactory.b (Devart.Common.DbConnectionBase A_0) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Data.Entity.Core.EntityClient.EntityConnection.OpenStoreConnectionIfStoreConnectionNotOpened (System.Data.Common.DbConnection storeConnectionToOpen, System.String exceptionCode, System.String attemptedOperation, System.Boolean& closeStoreConnectionOnFailure) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.EntityClient.EntityConnection.Open () [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection () [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.Objects.ObjectQuery`1[TestModel.Product].GetResults (Nullable`1 forMergeOption) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Core.Objects.ObjectQuery`1[TestModel.Product].<GetEnumerator>m__2C3 () [0x00000] in <filename unknown>:0 
  at System.Lazy`1[System.Collections.Generic.IEnumerator`1[TestModel.Product]].InitValue () [0x0014f] in /svn/mono/mcs/class/corlib/System/Lazy.cs:156
Comment 2 Oleg 2013-02-13 08:04:08 UTC
Probably, it is related to connection string. It can be changed in App.config. I typed dummy localhost, port 5432, user postgres, password 123456; you may need to change it to your settings.
Comment 3 Atsushi Eno 2013-02-13 14:10:16 UTC
OK, fixed this issue in master (be167fd).

I'm still getting some error for some mis-configuration, but either it might work for you or it should be filed as another bug. Could you try anyways? Thanks.
Comment 4 Oleg 2013-02-14 07:00:21 UTC
It looks like bug. There is discussion on Devart forum at:
http://forums.devart.com/viewtopic.php?f=30&t=25699

I will try test with metadata in files, not embedded resources, and will reply about result.