Specification icon indicating copy to clipboard operation
Specification copied to clipboard

Object reference not set to an instance of an object error.

Open commodus opened this issue 5 months ago • 0 comments

Hello,

I’m using version 8.0.0 of the Ardalis.Specification library. When the CreateBrandRequest event is triggered as shown in the screenshot, the FluentValidation implemented CreateBrandRequestValidator method runs. The IReadRepository<Brand> _repository is injected and is not null, and the name parameter is not null, but when I call the repository method with the BrandByNameSpec parameter on line 27, I get a System.NullReferenceException: 'Object reference not set to an instance of an object.' error on this line. I would appreciate your help. Thank you.

image

Stack Trace : at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable1 source, Expression expression, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable1 source, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.FirstOrDefaultAsync[TSource](IQueryable1 source, CancellationToken cancellationToken) at Ardalis.Specification.EntityFrameworkCore.RepositoryBase1.<FirstOrDefaultAsync>d__15.MoveNext() at JTR.WebApi.Application.Catalog.Brands.CreateBrandRequestValidator.<>c__DisplayClass1_0.<<-ctor>b__1>d.MoveNext()

image

commodus avatar Sep 14 '24 20:09 commodus