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

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

Closed
hankovich opened this issue Aug 10, 2023 · 4 comments · Fixed by #209
Closed

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

hankovich opened this issue Aug 10, 2023 · 4 comments · Fixed by #209

Comments

@hankovich
Copy link

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
@khellang
Copy link
Owner

Thanks for raising this @hankovich! I'll wait for the results of dotnet/runtime#90334 to see if there's anything I need to do on the Scrutor-side.

Carl-Hugo added a commit to Carl-Hugo/An-Atypical-ASP.NET-Core-8-Design-Patterns-Guide that referenced this issue Aug 20, 2023
The CI Build failure is related to the following:

- khellang/Scrutor#208
- dotnet/runtime#90334
@hankovich
Copy link
Author

I think this may be closed now, since Scrutor works perfectly with .NET 8 RC1

@khellang
Copy link
Owner

Thanks @hankovich! Once .NET 8 is out, I'll probably release a new major version of this library which will get rid of some of the problematic workarounds as well ☺️

@mdg215199
Copy link

mdg215199 commented Feb 6, 2024

For wh

Thanks @hankovich! Once .NET 8 is out, I'll probably release a new major version of this library which will get rid of some of the problematic workarounds as well ☺️

When updating to net8, I ran into the following issue:
Could not load type 'SqlGuidCaster' from assembly 'Microsoft.Data.SqlClient, Version=5.0.0.0,

The above issue is resolved when using changes in branch "/tree/feature/net8.0". @khellang will you be releasing the major version (5.x) soon?

Disregard the above question... as that's stated here #209

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants