Skip to content

Scrutor stopped working after upgrading to .NET 8 preview 7 from .NET 8 preview 6 #208

@hankovich

Description

@hankovich

The following code stopped working after upgrading from .NET 8 preview 6 to .NET 8 preview 7.

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework> <!-- works well on net7.0 and net 8.0 preview 6, breaks on preview 7 -->
    <LangVersion>preview</LangVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Scrutor" Version="4.2.2" />
  </ItemGroup>

</Project>
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

var builder = WebApplication.CreateBuilder(args);

builder.Services
    .AddTransient<IService, Service>()
    .AddTransient<IDecorated, Decorated1>()
    .Decorate<IDecorated, Decorated2>();

var app = builder.Build();

app.Map("/", (IService s) => s.ToString());

app.UseRouting();

app.Run();

interface IService;

class Service(IDecorated decorated) : IService;

interface IDecorated;

class Decorated1 : IDecorated;

class Decorated2(IDecorated decorated) : IDecorated;
{
  "sdk": {
    "version": "8.0.100-preview.7.23376.3" // global.json
  }
}

With this exception

Unhandled exception. System.AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: IService Lifetime: Transient ImplementationType: Service': Unable to resolve service for type 'IDecorated' while attempting to activate 'Service'.)
 ---> System.InvalidOperationException: Error while validating the service descriptor 'ServiceType: IService Lifetime: Transient ImplementationType: Service': Unable to resolve service for type 'IDecorated' while attempting to activate 'Service'.
 ---> System.InvalidOperationException: Unable to resolve service for type 'IDecorated' while attempting to activate 'Service'.
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(ServiceIdentifier serviceIdentifier, Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache lifetime, ServiceIdentifier serviceIdentifier, Type implementationType, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor descriptor, ServiceIdentifier serviceIdentifier, CallSiteChain callSiteChain, Int32 slot)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(ServiceDescriptor serviceDescriptor, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.ValidateService(ServiceDescriptor descriptor)
   --- End of inner exception stack trace ---
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.ValidateService(ServiceDescriptor descriptor)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(ICollection`1 serviceDescriptors, ServiceProviderOptions options)
   --- End of inner exception stack trace ---
   at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(ICollection`1 serviceDescriptors, ServiceProviderOptions options)
   at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services, ServiceProviderOptions options)
   at Microsoft.Extensions.Hosting.HostApplicationBuilder.Build()
   at Microsoft.AspNetCore.Builder.WebApplicationBuilder.Build()
   at Program.<Main>$(String[] args) in C:\Users\i\hate\devlooped\SponsorLink\source\repos\but\love\scrutor\Program.cs:line 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions