Skip to content

net9.0-ios regression causing InvalidProgramException in certain circumstances  #108108

@rdavisau

Description

@rdavisau

Description

Regression introduced in .net9 preview 5, and still present in rc1. On iOS, certain code that worked on .net9 preview 4 and all previous versions of .net now crashes with InvalidProgramException in release builds.

Triggering code is a path of DryIoc's interpreter. From what I could isolate, it occurs in these circumstances:

  • multiple singleton service types (A, B), depend on another singleton type (Z)
  • the Z type is injected lazily (Lazy<Z> constructor parameter)
  • DryIoC is configured to use its own interpreter
  • DryIoC attempts to resolve one of the service types (e.g. B), after having previously resolved the other service type (e.g. A)

Circumstances that don't cause it:

  • Z type is injected directly, not lazily
  • Only one of the service types is resolved, including repeated resolutions of the same type.

Tagging @dadhi the DryIoC library author who may be able to provide information on what specific parts of the interpreter are exercised in this "resolution of second service injecting lazy dependency" case that differ from the cases that don't trigger the crash.

Reproduction Steps

Expected behavior

Application launches and remains running with log output:

Resolve a service that depends on Lazy<Thing> once
Ok
Resolve the same service that depends on Lazy<Thing> a second time
Ok
Resolve a different service that depends on Lazy<Thing>
Ok

Actual behavior

Application launches and quickly crashes, with log output:

Resolve a service that depends on Lazy<Thing> once
Ok
Resolve the same service that depends on Lazy<Thing> a second time
Ok
Resolve a different service that depends on Lazy<Thing>

Terminating app due to uncaught exception 'System.InvalidProgramException', reason: ' (System.InvalidProgramException) 
at DryIoc.Interpreter.TryInterpretSingletonAndUnwrapContainerException(IResolverContext r, Expression expr, ImMapEntry`1 itemRef, Object& result) 
at DryIoc.Factory.ApplyReuse(Expression serviceExpr, Request request) at DryIoc.Factory.GetExpressionOrDefault(Request request) 
at DryIoc.Container.ResolveAndCache(Int32 serviceTypeHash, Type serviceType, IfUnresolved ifUnresolved) 
at DryIoc.Container.DryIoc.IResolver.Resolve(Type serviceType, IfUnresolved ifUnresolved) 
at DryIoc.Resolver.Resolve[IServiceB](IResolver resolver, IfUnresolved ifUnresolved) 
at InvalidProgram.AppDelegate.FinishedLaunching(UIApplication application, NSDictionary launchOptions) 
at InvalidProgram.AppDelegate.Registrar_Callbacks.callback_2_InvalidProgram_AppDelegate_FinishedLaunching(IntPtr pobj, IntPtr sel, IntPtr p0, IntPtr p1, IntPtr* exception_gchandle) '

(sometimes, app may crash before exception details are written to console)

Regression?

Yes. This was working in .net9 preview 4 and earlier stables.
Introduced in .net9 preview 5 and still present in .net9 rc1.

Known Workarounds

No response

Configuration

dotnet --info

.NET SDK:
 Version:           9.0.100-rc.1.24452.12
 Commit:            81a714c6d3
 Workload version:  9.0.100-manifests.b772b23d
 MSBuild version:   17.12.0-preview-24422-09+d17ec720d

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  14.6
 OS Platform: Darwin
 RID:         osx-arm64
 Base Path:   /usr/local/share/dotnet/sdk/9.0.100-rc.1.24452.12/

.NET workloads installed:
Configured to use loose manifests when installing new manifests.
 [ios]
   Installation Source: SDK 9.0.100-rc.1
   Manifest Version:    17.5.9270-net9-rc1/9.0.100-rc.1
   Manifest Path:       /usr/local/share/dotnet/sdk-manifests/9.0.100-rc.1/microsoft.net.sdk.ios/17.5.9270-net9-rc1/WorkloadManifest.json
   Install Type:        FileBased

 [maui]
   Installation Source: SDK 9.0.100-rc.1
   Manifest Version:    9.0.0-rc.1.24453.9/9.0.100-rc.1
   Manifest Path:       /usr/local/share/dotnet/sdk-manifests/9.0.100-rc.1/microsoft.net.sdk.maui/9.0.0-rc.1.24453.9/WorkloadManifest.json
   Install Type:        FileBased


Host:
  Version:      9.0.0-rc.1.24431.7
  Architecture: arm64
  Commit:       static

.NET SDKs installed:
  6.0.417 [/usr/local/share/dotnet/sdk]
  7.0.404 [/usr/local/share/dotnet/sdk]
  8.0.100 [/usr/local/share/dotnet/sdk]
  8.0.204 [/usr/local/share/dotnet/sdk]
  9.0.100-preview.3.24204.13 [/usr/local/share/dotnet/sdk]
  9.0.100-preview.4.24267.66 [/usr/local/share/dotnet/sdk]
  9.0.100-preview.5.24307.3 [/usr/local/share/dotnet/sdk]
  9.0.100-preview.6.24328.19 [/usr/local/share/dotnet/sdk]
  9.0.100-preview.7.24407.12 [/usr/local/share/dotnet/sdk]
  9.0.100-rc.1.24452.12 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.25 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.14 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0-preview.3.24172.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0-preview.4.24267.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0-preview.5.24306.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0-preview.6.24328.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0-preview.7.24406.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0-rc.1.24452.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.25 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.14 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0-preview.3.24172.9 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0-preview.4.24266.19 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0-preview.5.24306.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0-preview.6.24327.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0-preview.7.24405.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0-rc.1.24431.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

Other information

No response

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions