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

Null parameters of C# decimal? type cause NullReferenceException #315

Closed
ghost opened this issue Aug 1, 2018 · 4 comments
Closed

Null parameters of C# decimal? type cause NullReferenceException #315

ghost opened this issue Aug 1, 2018 · 4 comments

Comments

@ghost
Copy link

ghost commented Aug 1, 2018

In our project, we are using Dapper for SqlServer database and MiniProfiler.
After upgrading to MiniProfiler 4.0.133, following sample code (assuming the stored procedure has all respective parameters that accept NULL values):

decimal? a = null;
int? b = null;
Guid? c = null;

await profiledDbConnection.ExecuteScalarAsync<int>("SomeStoredProcedure",
 new { a, b, c },
 commandType: CommandType.StoredProcedure).ConfigureAwait(false)

throws NullReferenceException:

at StackExchange.Profiling.SqlFormatters.SqlServerFormatter.<>c__DisplayClass3_0.<GetWithDecimalFormatter>b__0(SqlTimingParameter p)
at StackExchange.Profiling.SqlFormatters.SqlServerFormatter.GenerateParamText(StringBuilder buffer, List`1 parameters)
at StackExchange.Profiling.SqlFormatters.SqlServerFormatter.FormatSql(String commandText, List`1 parameters, IDbCommand command)
at StackExchange.Profiling.SqlFormatters.SqlServerFormatter.FormatSql(String commandText, List`1 parameters)
at StackExchange.Profiling.SqlFormatters.SqlFormatterExtensions.GetFormattedSql(ISqlFormatter sqlFormatter, String commandText, List`1 parameters, IDbCommand command)
at StackExchange.Profiling.SqlFormatters.SqlFormatterExtensions.GetFormattedSql(ISqlFormatter sqlFormatter, IDbCommand command)
at StackExchange.Profiling.Internal.IDbCommandExtensions.GetTiming(IDbCommand command, String commandType, MiniProfiler profiler, String customType)
at StackExchange.Profiling.MiniProfiler.StackExchange.Profiling.Data.IDbProfiler.ExecuteStart(IDbCommand profiledDbCommand, SqlExecuteType executeType)
at StackExchange.Profiling.Data.ProfiledDbCommand.<ExecuteDbDataReaderAsync>d__35.MoveNext()

If we remove the decimal? parameter, the query works OK. The MiniProfiler version 4.0.0 has no issues with decimal? parameters.

I believe the issue has been introduced in the dotnet/src/MiniProfiler.Shared/SqlFormatters/SqlServerFormatter.cs commit "SQL formatting for numeric types" on Jun 12, 2018

NickCraver added a commit that referenced this issue Aug 2, 2018
@NickCraver
Copy link
Member

Thanks for the report! Fixed for the next release in fb4b1a9, it'll be up on MyGet shortly.

@robertmiles3
Copy link

I just hit this in the latest version on NuGet (4.0.133). Since it's in the latest, is there any chance of getting a new package up with this fix?

@NickCraver
Copy link
Member

@robertmiles3 absolutely - have a stack trace by chance?

@NickCraver NickCraver reopened this Sep 23, 2018
@NickCraver
Copy link
Member

Going to close this out since latest should have all the fixes...if anyone's hitting it in 4.0.138 a repro would be super helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants