Closed abatishchev closed 2 years ago
Under certain (unknown) circumstances the following code fails with NullReferenceException:
NullReferenceException
public override async Task Invoke(IOwinContext context) { var sw = Stopwatch.StartNew(); try { await this.Next.Invoke(context).ConfigureAwait(false); } catch (Exception ex) { LogException(ex); } finally { sw.Stop(); LogHttpRequest(context, operation, tenant, x509Cert); } } private void LogHttpRequest(IOwinContext context) { // here var remoteIpAddress = context.Request?.RemoteIpAddress; // or here var hostName = context.Request?.Host.Value; }
Environment:
.NET Framework 4.6.2 Azure Service Fabric
Packages:
<PackageReference Include="Microsoft.Owin" Version="4.2.0" /> <PackageReference Include="Microsoft.Owin.FileSystems" Version="4.2.0" /> <PackageReference Include="Microsoft.Owin.Host.HttpListener" Version="4.2.0" /> <PackageReference Include="Microsoft.Owin.Hosting" Version="4.2.0" /> <PackageReference Include="Microsoft.Owin.Security" Version="4.2.0" /> <PackageReference Include="Microsoft.Owin.Security.ActiveDirectory" Version="4.2.0" /> <PackageReference Include="Microsoft.Owin.StaticFiles" Version="4.2.0" />
It turned out the method in question was wrapped with a try/catch that was swallowing the exception. I've removed it and will report back if the exception comes back, or it's gone.
try/catch
Under certain (unknown) circumstances the following code fails with
NullReferenceException
:Environment:
Packages: