Skip to content

Misaligned read in 9.0.300 causes a razor generator crash #11863

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

Open
333fred opened this issue May 15, 2025 · 5 comments
Open

Misaligned read in 9.0.300 causes a razor generator crash #11863

333fred opened this issue May 15, 2025 · 5 comments
Assignees
Labels
area-compiler Umbrella for all compiler issues ✔️ resolution: fixed
Milestone

Comments

@333fred
Copy link
Member

333fred commented May 15, 2025

In Azure Pipelines using ubuntu-latest image and 9.0.300 SDK all our builds failed due to

CSC error CS8785: Generator 'RazorSourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentOutOfRangeException' with message 'Specified argument was out of the range of valid values.'. [/home/vsts/work/1/s/src/***.Web/***.Web.csproj]

Messages
    Microsoft (R) Visual C# Compiler version 4.14.0-3.25218.8 (d7bde97e)
    Copyright (C) Microsoft Corporation. All rights reserved.
    System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
    at Microsoft.AspNetCore.Razor.Language.CodeGeneration.CodeWriter.Reader.Read(Char[] buffer, Int32 index, Int32 count)
    at System.IO.TextReader.ReadBlock(Char[] buffer, Int32 index, Int32 count)
    at Microsoft.CodeAnalysis.Text.LargeText.ReadChunksFromTextReader(TextReader reader, Int32 maxCharRemainingGuess, Boolean throwIfBinaryDetected)
    at Microsoft.AspNetCore.Razor.Language.CodeGeneration.CodeWriter.GetText()
    at Microsoft.AspNetCore.Razor.Language.CodeGeneration.DefaultDocumentWriter.WriteDocument(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
    at Microsoft.AspNetCore.Razor.Language.DefaultRazorCSharpLoweringPhase.ExecuteCore(RazorCodeDocument codeDocument, CancellationToken cancellationToken)
    at Microsoft.AspNetCore.Razor.Language.RazorEnginePhaseBase.Execute(RazorCodeDocument codeDocument, CancellationToken cancellationToken)
    at Microsoft.NET.Sdk.Razor.SourceGenerators.SourceGeneratorProjectEngine.ExecutePhases(ReadOnlySpan`1 phases, RazorCodeDocument codeDocument)
    at Microsoft.NET.Sdk.Razor.SourceGenerators.SourceGeneratorProjectEngine.ProcessRemaining(SourceGeneratorRazorCodeDocument sgDocument)
    at Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator.<>c__DisplayClass6_2.<Initialize>b__26(ValueTuple`3 pair, CancellationToken _)
    at Microsoft.CodeAnalysis.TransformNode`2.<>c__DisplayClass6_0.<.ctor>b__0(TInput i, CancellationToken token)
    at Microsoft.CodeAnalysis.TransformNode`2.UpdateStateTable(Builder builder, NodeStateTable`1 previousTable, CancellationToken cancellationToken)
    -----

Setting fixed SDK version to 9.0.204 in Azure Pipeline fix issue with builds.

I can provide binlog on request (privately)

Originally posted by @alfeg in #9885

@333fred
Copy link
Member Author

333fred commented May 15, 2025

@alfeg, @srudenkoyb, @jscarle:

Thanks for the logs. We've traced it to a very precise loop error that will be fixed in #11861. We expect to publish a toolset package you can use to work around the error in the next couple of days, with permanent fix in the next version. Thanks for the prompt reporting!

Originally posted by @333fred in #9885

@333fred 333fred modified the milestones: 17.14 P3, 2025-06 June May 15, 2025
@333fred 333fred removed the untriaged label May 15, 2025
@333fred
Copy link
Member Author

333fred commented May 15, 2025

To work around the razor issue before new SDK version is released, you can temporarily reference razor toolset package:

https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet-tools/NuGet/Microsoft.Net.Compilers.Razor.Toolset/overview/9.0.0-preview.25264.2

You need to add the nuget feed, e.g., like this to a nuget.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="nuget" value="https://api.nuget.org/v3/index.json" />
    <add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
  </packageSources>
</configuration>

And then you can install the toolset package with the fix in your project file or Directory.Build.props:

  <ItemGroup>
    <PackageReference Include="Microsoft.Net.Compilers.Razor.Toolset" Version="9.0.0-preview.25264.2">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>

Originally posted by @jjonescz in #9885

@333fred
Copy link
Member Author

333fred commented May 15, 2025

A simpler workaround is now available: Simply depend on https://www.nuget.org/packages/Microsoft.Net.Compilers.Razor.Toolset/9.0.0-preview.25264.2, no need for the additional nuget.config entry.

  <ItemGroup>
    <PackageReference Include="Microsoft.Net.Compilers.Razor.Toolset" Version="9.0.0-preview.25264.2">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>

Warning

Do not depend on this package long-term. Please remove it as soon as there an SDK with this fix in it, which we expect to be 9.0.301.

@jscarle
Copy link

jscarle commented May 16, 2025

@333fred I can confirm that building our solution using .NET 9.0.300 and this package does indeed resolve the issue.

@333fred
Copy link
Member Author

333fred commented May 16, 2025

Thanks for the confirmation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-compiler Umbrella for all compiler issues ✔️ resolution: fixed
Projects
None yet
Development

No branches or pull requests

2 participants