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 reference exception in codegen #1027

Closed
davidfowl opened this issue Apr 27, 2021 · 6 comments
Closed

Null reference exception in codegen #1027

davidfowl opened this issue Apr 27, 2021 · 6 comments
Labels
area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation

Comments

@davidfowl
Copy link
Member

C:\Users\david\source\repos\WebApplication462\WebApplication462> dotnet publish -r win-x64
Microsoft (R) Build Engine version 16.10.0-preview-21227-01+79bef822b for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  Restored C:\Users\david\source\repos\WebApplication462\WebApplication462\WebApplication462.csproj (in 154 ms).
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
  WebApplication462 -> C:\Users\david\source\repos\WebApplication462\WebApplication462\bin\Debug\net6.0\win-x64\WebApplication462.dll
  Generating native code
  Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
     at ILCompiler.RootingHelpers.TryGetDependenciesForReflectedType(DependencyList& dependencies, NodeFactory factory, TypeDesc type, String reason)
     at ILCompiler.RootingHelpers.TryGetDependenciesForReflectedField(DependencyList& dependencies, NodeFactory factory, FieldDesc field, String reason)
     at ILCompiler.DependencyAnalysis.DynamicDependencyAttributeAlgorithm.AddDependenciesDueToDynamicDependencyAttribute(DependencyList& dependencies, NodeFactory factory, EcmaMethod method)
     at ILCompiler.UsageBasedMetadataManager.GetDependenciesDueToMethodCodePresenceInternal(DependencyList& dependencies, NodeFactory factory, MethodDesc method, MethodIL methodIL)
     at ILCompiler.DependencyAnalysis.CodeBasedDependencyAlgorithm.AddDependenciesDueToMethodCodePresence(DependencyList& dependencies, NodeFactory factory, MethodDesc method, MethodIL methodIL)
     at Internal.JitInterface.CorInfoImpl.PublishCode()
     at Internal.JitInterface.CorInfoImpl.CompileMethodInternal(IMethodNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at Internal.JitInterface.CorInfoImpl.CompileMethod(MethodCodeNode methodCodeNodeNeedingCode, MethodIL methodIL)
     at ILCompiler.RyuJitCompilation.CompileSingleMethod(CorInfoImpl corInfo, MethodCodeNode methodCodeNodeNeedingCode)
     at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
     at System.Threading.ThreadPoolWorkQueue.Dispatch()
     at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
C:\Users\david\.nuget\packages\microsoft.dotnet.ilcompiler\6.0.0-preview.5.21226.5\build\Microsoft.NETCore.Native.targets(282,5): error MSB3073: The command ""C:\Users\david\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\6.0.0-preview.5.21226.5\tools\ilc" @"obj\Debug\net6.0\win-x64\native\WebApplication462.ilc.rsp"" exited with code -1073741819. [C:\Users\david\source\repos\WebApplication462\WebApplication462\WebApplication462.csproj]
<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <IlcDisableReflection>true</IlcDisableReflection>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.DotNet.ILCompiler" Version="6.0.0-preview.5.21226.5" />
  </ItemGroup>
</Project>
C:\Users\david\source\repos\WebApplication462\WebApplication462> dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.100-preview.4.21226.14
 Commit:    d354ca2a89

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19041
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.100-preview.4.21226.14\

Host (useful for support):
  Version: 6.0.0-preview.4.21222.10
  Commit:  bd2d701e75

.NET SDKs installed:
  2.1.801 [C:\Program Files\dotnet\sdk]
  2.1.802 [C:\Program Files\dotnet\sdk]
  2.2.102 [C:\Program Files\dotnet\sdk]
  2.2.402 [C:\Program Files\dotnet\sdk]
  3.0.100 [C:\Program Files\dotnet\sdk]
  3.1.101 [C:\Program Files\dotnet\sdk]
  3.1.201 [C:\Program Files\dotnet\sdk]
  5.0.103 [C:\Program Files\dotnet\sdk]
  5.0.300-preview.21180.15 [C:\Program Files\dotnet\sdk]
  6.0.100-preview.4.21226.14 [C:\Program Files\dotnet\sdk]
@jkotas jkotas added the area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation label Apr 27, 2021
@kant2002
Copy link
Contributor

@davidfowl How do you able to build it?

dotnet restore -r win-x64
  Determining projects to restore...
D:\davidissue\davidissue.csproj : error NU1102: Unable to find package Microsoft.NETCore.App.Runtime.win-x64 with version (= 6.0.0-preview.4.21222.10)
D:\davidissue\davidissue.csproj : error NU1102:   - Found 45 version(s) in dotnet-public [ Nearest version: 6.0.0-preview.3.21201.4 ]
D:\davidissue\davidissue.csproj : error NU1102:   - Found 11 version(s) in dotnet-experimental [ Nearest version: 6.0.0-s390x.1.20553.1 ]
D:\davidissue\davidissue.csproj : error NU1102: Unable to find package Microsoft.WindowsDesktop.App.Runtime.win-x64 with version (= 6.0.0-preview.4.21223.2)
D:\davidissue\davidissue.csproj : error NU1102:   - Found 45 version(s) in dotnet-public [ Nearest version: 6.0.0-preview.3.21201.3 ]
D:\davidissue\davidissue.csproj : error NU1102:   - Found 0 version(s) in dotnet-experimental
D:\davidissue\davidissue.csproj : error NU1102: Unable to find package Microsoft.AspNetCore.App.Runtime.win-x64 with version (= 6.0.0-preview.4.21222.16)
D:\davidissue\davidissue.csproj : error NU1102:   - Found 48 version(s) in dotnet-public [ Nearest version: 6.0.0-preview.3.21201.13 ]
D:\davidissue\davidissue.csproj : error NU1102:   - Found 0 version(s) in dotnet-experimental

nuget.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <!--To inherit the global NuGet package sources remove the <clear/> line below -->
    <clear />
    <add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
    <add key="dotnet-experimental" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json" />
  </packageSources>
</configuration>

dotnet --info

dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.100-preview.4.21226.14
 Commit:    d354ca2a89

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19042
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.100-preview.4.21226.14\

Host (useful for support):
  Version: 6.0.0-preview.4.21222.10
  Commit:  bd2d701e75

.NET SDKs installed:
  3.1.114 [C:\Program Files\dotnet\sdk]
  5.0.104 [C:\Program Files\dotnet\sdk]
  5.0.202 [C:\Program Files\dotnet\sdk]
  6.0.100-preview.4.21226.14 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.4.21222.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-preview.4.21222.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.0-preview.4.21223.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@kant2002
Copy link
Contributor

kant2002 commented Apr 27, 2021

Issue at {[Microsoft.AspNetCore.Server.IIS]Microsoft.AspNetCore.Server.IIS.NativeMethods.http_get_application_properties(IISConfigurationData&)}

Tracked as #167 so probably I would be there soon, once ComWrappers works will be ready_

And it perfectly breaks even if targets net5.0

Actually during processing {[System.Linq.Expressions]System.Linq.Expressions.Utils.GetStrongBoxValueField(Expression)}
at https://github.com/dotnet/runtimelab/blob/feature/NativeAOT/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/RootingHelpers.cs#L240

at ILCompiler.RootingHelpers.TryGetDependenciesForReflectedType(DependencyList& dependencies, NodeFactory factory, TypeDesc type, String reason) in D:\d\kant\GitHub\dotnet\runtimelab\src\coreclr\tools\aot\ILCompiler.Compiler\Compiler\RootingHelpers.cs:line 240
   at ILCompiler.RootingHelpers.TryGetDependenciesForReflectedField(DependencyList& dependencies, NodeFactory factory, FieldDesc field, String reason) in D:\d\kant\GitHub\dotnet\runtimelab\src\coreclr\tools\aot\ILCompiler.Compiler\Compiler\RootingHelpers.cs:line 172
   at ILCompiler.DependencyAnalysis.DynamicDependencyAttributeAlgorithm.AddDependenciesDueToDynamicDependencyAttribute(DependencyList& dependencies, NodeFactory factory, EcmaMethod method) in D:\d\kant\GitHub\dotnet\runtimelab\src\coreclr\tools\aot\ILCompiler.Compiler\Compiler\DependencyAnalysis\DynamicDependencyAttributeAlgorithm.cs:line 140
   at ILCompiler.UsageBasedMetadataManager.GetDependenciesDueToMethodCodePresenceInternal(DependencyList& dependencies, NodeFactory factory, MethodDesc method, MethodIL methodIL) in D:\d\kant\GitHub\dotnet\runtimelab\src\coreclr\tools\aot\ILCompiler.Compiler\Compiler\UsageBasedMetadataManager.cs:line 381
   at ILCompiler.MetadataManager.GetDependenciesDueToMethodCodePresence(DependencyList& dependencies, NodeFactory factory, MethodDesc method, MethodIL methodIL) in D:\d\kant\GitHub\dotnet\runtimelab\src\coreclr\tools\aot\ILCompiler.Compiler\Compiler\MetadataManager.cs:line 418
   at ILCompiler.DependencyAnalysis.CodeBasedDependencyAlgorithm.AddDependenciesDueToMethodCodePresence(DependencyList& dependencies, NodeFactory factory, MethodDesc method, MethodIL methodIL) in D:\d\kant\GitHub\dotnet\runtimelab\src\coreclr\tools\aot\ILCompiler.Compiler\Compiler\DependencyAnalysis\CodeBasedDependencyAlgorithm.cs:line 63
   at Internal.JitInterface.CorInfoImpl.PublishCode() in D:\d\kant\GitHub\dotnet\runtimelab\src\coreclr\tools\Common\JitInterface\CorInfoImpl.cs:line 412
   at Internal.JitInterface.CorInfoImpl.CompileMethodInternal(IMethodNode methodCodeNodeNeedingCode, MethodIL methodIL) in D:\d\kant\GitHub\dotnet\runtimelab\src\coreclr\tools\Common\JitInterface\CorInfoImpl.cs:line 332
   at Internal.JitInterface.CorInfoImpl.CompileMethod(MethodCodeNode methodCodeNodeNeedingCode, MethodIL methodIL) in D:\d\kant\GitHub\dotnet\runtimelab\src\coreclr\tools\aot\ILCompiler.RyuJit\JitInterface\CorInfoImpl.RyuJit.cs:line 62
   at ILCompiler.RyuJitCompilation.CompileSingleMethod(CorInfoImpl corInfo, MethodCodeNode methodCodeNodeNeedingCode) in D:\d\kant\GitHub\dotnet\runtimelab\src\coreclr\tools\aot\ILCompiler.RyuJit\Compiler\RyuJitCompilation.cs:line 161
   at ILCompiler.RyuJitCompilation.<CompileMultiThreaded>b__14_0(Object m) in D:\d\kant\GitHub\dotnet\runtimelab\src\coreclr\tools\aot\ILCompiler.RyuJit\Compiler\RyuJitCompilation.cs:line 123
   at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

@MichalStrehovsky
Copy link
Member

I'll assume this was fixed in #1028 (Github won't autoclose this because it didn't merge into the default branch of the repo).

@kant2002
Copy link
Contributor

@MichalStrehovsky Can this be catch by using nullable types? I understand that some code is shared with Crossgen2 (?) so maybe not an option.

@MichalStrehovsky
Copy link
Member

@MichalStrehovsky Can this be catch by using nullable types? I understand that some code is shared with Crossgen2 (?) so maybe not an option.

Eh, based on what I've seen happening in the libraries, nullable types will litter the code with ?, [NotNullIfNotNull], etc. and one still has to use a bunch of ! because the annotation just cannot express everything. Then one gets NullRefException bugs in the places that had to use ! anyway (we already started hitting those in the libraries). Trying to fit what I'm doing into what nullable annotations can express is similar level of cognitive load to Rust's memory ownership. It's often more productive not to have to care about that.

@kant2002
Copy link
Contributor

Thanks for explanation. I probably agree with Rust cognition load statement, but personally think that in the long run it atually simplify cognitive load. Anyway, you are high-performer in that area, so I just was curious, what kind of practical matters prevent nullable annotations from being applied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation
Projects
None yet
Development

No branches or pull requests

4 participants