Skip to main content
All docs
V21.2

.NET 5.0: Operation is Not Valid Due to the Current State of the Object

When you use .NET 5.0 RC 1 and try to publish a Blazor project, the following exception can occur:

System.InvalidOperationException: Operation is not valid due to the current state of the object

This issue relates to the internal code of .NET 5.0. For more information, refer to the following issue in the linker‘s repository: Generic type array causes InvalidOperationException in ReflectionMethodBodyScanner.GetValueNodeFromGenericArgument.

To resolve this issue, try to disable the trimming feature. In your *.csproj file, disable the PublishTrimmed flag.

<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
    <PropertyGroup>
        <TargetFramework>net5.0</TargetFramework>
        ...
        <PublishTrimmed>false</PublishTrimmed>
    </PropertyGroup>
    ...
</Project>