Null Reference Exception in generated Data Service class
See original GitHub issueHi, the last update has introduced an issue in the generated Data Service class. The following generated code throws a null reference exception when the result from the data operation is null.
public static Task<Tenant> GetByHostNameAsync(string? hostName)
{
return DataSvcInvoker.Default.InvokeAsync(typeof(TenantDataSvc), async () =>
{
var __result = await Factory.Create<ITenantData>().GetByHostNameAsync(hostName).ConfigureAwait(false);
ExecutionContext.Current.CacheSet(__result.UniqueKey, __result);
if (_getByHostNameOnAfterAsync != null) await _getByHostNameOnAfterAsync(__result, hostName).ConfigureAwait(false);
return __result;
});
}
This is generated using:
<Entity Name="Tenant" Text="Tenant configuration" Implements="IETag, IChangeLog, ITenant" Collection="true" WebApiRoutePrefix="api/v1/tenants" CollectionResult="true"
AutoImplement="Database" DatabaseSchema="dbo">
...
<Operation Name="GetByHostName" OperationType="Custom" ReturnType="Tenant" WebApiRoute="hostName/{hostName}" WebApiMethod="HttpGet">
<Parameter Name="HostName" Type="string" />
</Operation>
</Entity>
I think this is due to the change to line 481 - https://github.com/Avanade/Beef/blame/master/tools/Beef.CodeGen.Core/Templates/EntityDataSvc_cs.xml#L481
ExecutionContext.Current.CacheSet<{{Operation.ReturnType}}>(__result?.UniqueKey ?? UniqueKey.Empty, __result);
has been changed to:
ExecutionContext.Current.CacheSet(__result.UniqueKey, __result);
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
c# - What is a NullReferenceException, and how do I fix it?
This means the reference is null , and you cannot access members (such as methods) through a null reference. The simplest case: string...
Read more >Object Reference Not Set to an Instance of an Object
This exception is thrown when you try to access a member—for instance, a method or a property—on a variable that currently holds a...
Read more >NullReferenceException Class (System)
The exception that is thrown when there is an attempt to dereference a null object reference.
Read more >c# - Determining the object that caused a null reference ...
Frequently in applications we encounter situations that could throw a NullReferenceException ; for example, assuming the following method's ...
Read more >Getting Null Reference Exception when trying to connect to ...
At runtime I am getting a Null Reference Exception that seems to be coming from the System.ServiceModel class. This null reference exception is ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks @edjo23 - I have merged in the PR and published an updated NuGet package for
Beef.CodeGen.Core
v3.1.7.Thanks