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

EF Core 2.0.0-preview3-26027 NullReferenceException on RelationalCommand #9041

Closed
carlosga opened this issue Jul 2, 2017 · 2 comments
Closed
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

@carlosga
Copy link

carlosga commented Jul 2, 2017

RelationalCommand throws a NullReferenceException when the underliying ADO.NET data provider returns null for their command Parameters property on disposed commands.

With the changes done on commit #9023 the Parameters collection of the DbCommand implementation maybe accessed after the command has been disposed and the connection closed, if the underliying provider is setting it to null on disposal it will throw a NullReferenceException

if (!readerOpen)
{
     dbCommand.Dispose();
     connection.Close();
}

**dbCommand.Parameters.Clear();**

Exception details:

System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace:
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.RelationalDatabaseCleaner.Clean(DatabaseFacade facade)
at PostgreSql.EntityFrameworkCore.Utilities.PostgreSqlDatabaseFacadeExtensions.<>c.<EnsureClean>b__0_0(DatabaseFacade database)
at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.<>c__2`1.<Execute>b__2_0(<>f__AnonymousType0`2 s)
at PostgreSql.EntityFrameworkCore.Storage.Internal.PostgreSqlExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState](IExecutionStrategy strategy, TState state, Action`1 operation)
at PostgreSql.EntityFrameworkCore.Utilities.PostgreSqlDatabaseFacadeExtensions.EnsureClean(DatabaseFacade databaseFacade)
at PostgreSql.EntityFrameworkCore.Utilities.PostgreSqlTestStore.Clean(String name)
at PostgreSql.EntityFrameworkCore.Utilities.PostgreSqlTestStore.CreateDatabase()
at PostgreSql.EntityFrameworkCore.Utilities.PostgreSqlTestStore.<>c__DisplayClass20_0.<CreateShared>b__0()
at Microsoft.EntityFrameworkCore.TestStore.CreateShared(String name, Action initializeDatabase)
at PostgreSql.EntityFrameworkCore.Utilities.PostgreSqlTestStore.CreateShared(Action initializeDatabase)
at PostgreSql.EntityFrameworkCore.Utilities.PostgreSqlTestStore.GetOrCreateShared(String name, Action initializeDatabase, Boolean cleanDatabase)
at PostgreSql.EntityFrameworkCore.ExecutionStrategyTest..ctor(ExecutionStrategyFixture fixture)

Further technical details

EF Core version: 2.0.0-preview3-26027
Operating system: Ubuntu 17.10
IDE: Visual Studio Code

@ErikEJ
Copy link
Contributor

ErikEJ commented Jul 2, 2017

@bricelam Looks like the SQL CE ADO.NET provider also will be hit by this, please look into it before 2.0!

@ajcvickers ajcvickers added this to the 2.0.0 milestone Jul 3, 2017
@bricelam
Copy link
Contributor

bricelam commented Jul 3, 2017

Found out why we clear them at all: #6249

I'm surprised we didn't hit this before; the previous code also disposed before clearing.

I'll update it to clear before disposing.

@bricelam bricelam added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jul 5, 2017
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