-
ABP Framework version: v4.3
-
UI type: Angular
-
DB provider: EF Core
-
Tiered (MVC) or Identity Server Separated (Angular): Seperated
-
Exception message and stack trace:
-
Steps to reproduce the issue:"
I have a background job where I am attempting to select records from a trap table. When the code gets to _list = query.ToList() I get the error System.NullReferenceException: 'Object reference not set to an instance of an object.' in List.cs. What am I doing wrong? Any ideas of why this error is occuring?
foreach (var row in values)
{
IQueryable<Trap> queryable = await _trapsSheet.GetQueryableAsync();
var query = queryable.Where(x => x.Asset.Equals(ConvertInt64(row[0].ToString())));
if(query.Any())
{
try
{
var _c1 = MapValues(row);
List<Trap> _list = new List<Trap>();
_list = query.ToList();
Trap _result = ObjectMapper(_c1, _list[0]);
mTrapExist.Add(_result);
}catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
else
{
try
{
Trap _result = MapValues(row);
System.Diagnostics.Debug.WriteLine(_result.Asset.ToString());
mTrap.Add(_result);
}catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
}
18 Answer(s)
-
0
hi
Can you share the full error stack?
-
0
This is all I get
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Microsoft.EntityFrameworkCore.Relational
StackTrace:
at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.Enumerator.Dispose() -
0
Maliming. I did. That is all it is giving me.
-
0
Can you check this
(x => x.Asset.Equals(ConvertInt64(row[0].ToString())))
Try to use constant expressions.
-
1
I did and I am still getting the error.
-
0
Maybe the
x.Asset
is null. Can you try to include it? or ignore it? -
0
So I check the database and the records exist. Here is a snippet of the table.
-
1
The funny part is, I can insert records just fine with this code. This is within the same class for the background job.
try
{
Trap _result = MapValues(row);
System.Diagnostics.Debug.WriteLine(_result.Asset.ToString());
mTrap.Add(_result);}catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}if(mTrap.Count > 0)
{
await _trapsSheet.InsertManyAsync(mTrap, true);
await uow.SaveChangesAsync();
} -
0
-
0
Not sure I am understanding. Here is what I have
private readonly IUnitOfWorkManager _unitOfWorkManager;
private readonly IRepository<Trap, Guid> _trapsSheet;
private readonly IObjectMapper _objectMapper;
private readonly IEmailSender _emailSender;
private readonly ITemplateRenderer _templateRenderer;
private static readonly string[] Scopes = { SheetsService.Scope.Spreadsheets };public TrapLoader(IUnitOfWorkManager unitOfWorkManager, IRepository<Trap, Guid> traps, IObjectMapper objectMapper, IEmailSender emailSender, ITemplateRenderer templateRenderer)
{
_unitOfWorkManager = unitOfWorkManager;
** _trapsSheet = traps**;
_objectMapper = objectMapper;
_emailSender = emailSender;
_templateRenderer = templateRenderer;
} -
0
You need to
include
your navigation entity.https://support.abp.io/QA/Questions/2301#answer-c47f204b-9a58-626b-5c6a-3a00e7a19105
-
0
I'll give that a try in the AM. I'll tell you know what happens.
-
0
👍
-
0
I went in and attempted to use .Include, but it appears .Include is not part of the IQueryable. A little background. I am using the IQueryable because when I inject the service and attempt to use the service directly in a background job I get Access denied because the user isnt authenticated, so instead I am accessing the data using the IRepository<Trap, Guid>. I have done this in other background jobs without any issues, but this one is throwing an exception and not sure why.
-
0
So I regenerated the table with a different name with ABP SUITE and now things seem to be working. What I would like to understand is why did the original not work properly as it was generated with ABP Suite?
-
0
You can compare the code to see. I'm not sure.
-
0
Since this is mainly ABP code. Where should I look and compare?
-
0
You can check the difference in git. before and after.