Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in 2.0.3 preview: NullReferenceException in RelationalDataReader.Dispose() on Migrate() #10147

Closed
OronDF343 opened this issue Oct 24, 2017 · 6 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@OronDF343
Copy link

The following simple case, which worked in 2.0.0, throws a NullReferenceException in the new preview:

var context = services.GetRequiredService<VolunteerDbContext>();
context.Database.Migrate();

Note that it happen with any of my DbContexts, not just the one shown above.
The exception is as follows:

Object reference not set to an instance of an object.
   at Microsoft.EntityFrameworkCore.Storage.RelationalDataReader.Dispose()
   at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.GetAppliedMigrations()
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
   at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate(DatabaseFacade databaseFacade)
   at TestAspNetCore.Program.Main(String[] args)

Additionally, when executing a CountAsync and a ToListAsync the following exceptions are thrown, respectively:

Microsoft.EntityFrameworkCore.Query: Error: An exception occurred in the database while iterating the results of a query for context type 'TestAspNetCore.Model.VolunteerDbContext'.
System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.EntityFrameworkCore.Storage.RelationalDataReader.Dispose()
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable`1.AsyncEnumerator.Dispose()
   at Microsoft.EntityFrameworkCore.Query.AsyncQueryMethodProvider.<GetResult>d__16`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.TaskResultAsyncEnumerable`1.Enumerator.<MoveNext>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.<MoveNext>d__5.MoveNext()

Microsoft.EntityFrameworkCore.Query: Error: An exception occurred in the database while iterating the results of a query for context type 'TestAspNetCore.Model.VolunteerDbContext'.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'WrappedMySqlDataReader'.
   at Microsoft.EntityFrameworkCore.Storage.Internal.WrappedMySqlDataReader.GetReader()
   at Microsoft.EntityFrameworkCore.Storage.Internal.WrappedMySqlDataReader.get_RecordsAffected()
   at Microsoft.EntityFrameworkCore.Storage.RelationalDataReader.Dispose()
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable`1.AsyncEnumerator.Dispose()
   at System.Linq.AsyncEnumerable.SelectEnumerableAsyncIterator`2.Dispose()
   at System.Linq.AsyncEnumerable.AsyncIterator`1.<MoveNext>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.<MoveNext>d__5.MoveNext()

Further technical details

EF Core version: 2.0.1-rtm-203
Database Provider: Pomelo.EntityFrameworkCore.MySql (version 2.0.0 as well as 2.0.1-preview-10072)
Operating system: Windows 7 x64
IDE: Visual Studio 2017 15.4.1

@ajcvickers
Copy link
Member

@OronDF343 Can you post a project or code listing so we can try to reproduce this?

@ajcvickers
Copy link
Member

@smitpatel Please investigate this per my email.

ajcvickers added a commit that referenced this issue Oct 24, 2017
…provider

Issue #10147

* MySQL provider sometimes has null Parameters collection
* MySQL provider sometimes throws when asking for records affected

Fix is to be defensive in our code and we will file issues on MySQL provider
@ajcvickers ajcvickers assigned ajcvickers and unassigned smitpatel Oct 24, 2017
@ajcvickers ajcvickers added this to the 2.0.3 milestone Oct 24, 2017
@ajcvickers
Copy link
Member

@ajcvickers ajcvickers added patch-approved closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed Servicing-consider labels Oct 24, 2017
@yukozh
Copy link
Contributor

yukozh commented Oct 24, 2017

Hi @OronDF343, I am from pomelo, we are fixing this issue, but not finished. For now, you can use .AddDbContext instead of .AddDbContextPool will work.

@OronDF343
Copy link
Author

Thanks, but unfortunately that workaround did not solve the issue (only one of the DbContext was using .AddDbContextPool and changing that produced the same exceptions). I guess I will downgrade to EF Core 2.0.0 for now (and use non-Async methods for now since 2.0.0 has a bug)

@ajcvickers
Copy link
Member

@OronDF343 A fix for this issue is being included in the 2.0.1 (2.0.3 meta package) patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

4 participants