1

I a running the dotnet 8 preview 7 and I keep getting the below error message when I make a call to Host.CreateDefaultBuilder().

Stack Trace

Could not load type 'System.Runtime.CompilerServices.NullableContextAttribute' from assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
   at System.ModuleHandle.ResolveType(QCallModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
   at System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
   at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctorWithParameters, Boolean& isVarArg)
   at System.Reflection.CustomAttribute.IsCustomAttributeDefined(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Int32 attributeCtorToken, Boolean mustBeInheritable)
   at System.Reflection.CustomAttribute.IsDefined(RuntimeType type, RuntimeType caType, Boolean inherit)
   at System.Diagnostics.StackTrace.ToString(TraceFormat traceFormat, StringBuilder sb)
   at System.Diagnostics.StackTrace.ToString(TraceFormat traceFormat)
   at System.Exception.get_StackTrace()

Any idea what I am missing. Thanks in advance.

Edit

This project structure is CQRS so there is a couple of csproj files that I have listed the contents below

Entry Application csproj

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

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net8.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
    </PropertyGroup>
    
    <ItemGroup>
      <PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
      <PackageReference Include="Serilog.AspNetCore.Enrichers.CorrelationId" Version="1.0.0" />
      <PackageReference Include="Serilog.Exceptions" Version="8.4.0" />
      <PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
    </ItemGroup>

    <ItemGroup>
        <ProjectReference Include="..\..\..\Jetpack.Extensions.Hosting\src\Jetpack.Extensions.Hosting\Jetpack.Extensions.Hosting.csproj" />
        <ProjectReference Include="..\CQRS.Application\CQRS.Application.csproj" />
        <ProjectReference Include="..\CQRS.Infrastructure\CQRS.Infrastructure.csproj" />
        <ProjectReference Include="..\CQRS.Persistence\CQRS.Persistence.csproj" />
    </ItemGroup>

    <ItemGroup>
        <None Update="appsettings.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
    </ItemGroup>

</Project>

Application csproj

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

    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
    </PropertyGroup>

    <ItemGroup>
      <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
      <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" Version="8.0.0-preview.4" />
      <PackageReference Include="Twilio" Version="6.11.0" />
      <PackageReference Include="WolverineFx" Version="1.5.0" />
      <PackageReference Include="WolverineFx.FluentValidation" Version="1.5.0" />
    </ItemGroup>

    <ItemGroup>
      <ProjectReference Include="..\CQRS.Domain\CQRS.Domain.csproj" />
    </ItemGroup>

</Project>

Domain csproj

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

    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
    </PropertyGroup>

    <ItemGroup>
      <Folder Include="Enums\" />
    </ItemGroup>

    <ItemGroup>
      <PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="8.0.0-preview.7.23375.9" />
      <PackageReference Include="NodaTime" Version="3.1.9" />
    </ItemGroup>

</Project>

Infrastructure csproj

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

    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
    </PropertyGroup>

    <ItemGroup>
      <ProjectReference Include="..\CQRS.Application\CQRS.Application.csproj" />
    </ItemGroup>


    <ItemGroup>
      <PackageReference Include="Flurl.Http" Version="4.0.0-pre3" />
      <PackageReference Include="MailKit" Version="4.1.0" />
      <PackageReference Include="SendGrid" Version="9.28.1" />
      <PackageReference Include="Stripe.net" Version="41.27.0" />
      <PackageReference Include="Twilio" Version="6.11.0" />
    </ItemGroup>
</Project>

Persistence csproj

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

    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <WarningsAsErrors>Nullable</WarningsAsErrors>
    </PropertyGroup>

    <ItemGroup>
      <ProjectReference Include="..\CQRS.Application\CQRS.Application.csproj" />
    </ItemGroup>

    <ItemGroup>
      <PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
      <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0-preview.7.23375.9" />
      <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" Version="8.0.0-preview.4" />
    </ItemGroup>
    
</Project>
Dblock247
  • 6,167
  • 10
  • 44
  • 66
  • Can you please provide a [mre]? Please show the csproj file. – Guru Stron Aug 11 '23 at 15:52
  • @GuruStron please see the update above. – Dblock247 Aug 11 '23 at 16:54
  • Why do you have `Microsoft.AspNetCore.Identity` package which is deprecated? – Guru Stron Aug 11 '23 at 17:07
  • @GuruStron I was customizing Identity. What is the replacement. – Dblock247 Aug 11 '23 at 20:15
  • Is not `Microsoft.AspNetCore.Identity.EntityFrameworkCore` enough? – Guru Stron Aug 11 '23 at 20:16
  • Also based on the naming it should be part of the ASP.NET Core so you do not need to add is explicitly for correct project types. Just remove the package. – Guru Stron Aug 11 '23 at 20:17
  • @GuruStron I thought it would be but for some reason SignInManager is not in `Microsoft.AspNetCore.Identity.EntityFrameworkCore`. I was able to use. `Microsoft.AspNetCore.Identity.UI`. However I still get the same error. – Dblock247 Aug 11 '23 at 20:30
  • Please share the full code. [`SignInManager`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.identity.signinmanager-1?view=aspnetcore-8.0) should be in place. – Guru Stron Aug 11 '23 at 20:32
  • @GuruStron please see this repo https://github.com/dblock247/CQRS-V8 – Dblock247 Aug 11 '23 at 20:47
  • @GuruStron so it seems that the issue comes when referencing a packages in Microsofts `8.0.0-preview.7.23375.6` versions. Downgrading to `8.0.0-preview.6.23329.7` versions seems to fix the issue. – Dblock247 Aug 12 '23 at 04:24
  • Do you have [.NET 8 preview 7](https://github.com/dotnet/core/blob/main/release-notes/8.0/preview/8.0.0-preview.7.md?WT.mc_id=dotnet-35129-website) installed on your machine? – Guru Stron Aug 15 '23 at 15:02
  • @GuruStron you are so right. I accidentally had the wrong version install. Thanks for your help. – Dblock247 Aug 17 '23 at 04:52

1 Answers1

1

To use latest .NET latest preview packages be sure to install corresponding .NET preview version, in this case - .NET 8.0.0 Preview 7 .

P.S.

Microsoft.AspNetCore.Identity package is deprecated and should not be used.

Guru Stron
  • 102,774
  • 10
  • 95
  • 132