Share via

Error Encountered While Upgrading .NET 9 Project to .NET 10

Tirth Shah 10 Reputation points
2025-11-19T08:59:35.0533333+00:00

Hello Microsoft Support Team,

I am in the process of upgrading my project from .NET 9 to .NET 10. During the upgrade, I encountered the following error:

Property or indexer 'IOpenApiMediaType.Example' cannot be assigned to -- it is read-only

This error appears when building the project after the upgrade.

Could you please advise on the cause of this issue and the recommended solution to resolve it?

I am attaching Screen Shot as Below.

User's image

Thank you for your assistance.

Best regards,

Tirth Shah

Softweb Solutions PVT LTD

******@softwebsolutions.com

Developer technologies | ASP.NET | ASP.NET Core

4 answers

Sort by: Most helpful
  1. Jack Dang (WICLOUD CORPORATION) 17,585 Reputation points Microsoft External Staff Moderator
    2025-11-20T03:40:17.7+00:00

    Hi @Tirth Shah ,

    Thanks for reaching out.

    Property or indexer 'IOpenApiMediaType.Example' cannot be assigned to -- it is read-only

    The error occurs because Microsoft.OpenApi 3.x introduced breaking changes, including making certain OpenAPI model properties (such as IOpenApiMediaType.Example) read-only. When upgrading a project to .NET 10, dependency updates may cause the OpenAPI package to move from 2.x (compatible) to 3.x (incompatible).

    .NET 10’s OpenAPI generator was built against the 2.x OpenAPI model, so when version 3.x is present, the generator attempts to assign values to properties that are no longer writable - resulting in the build failure you’re seeing.

    I have done some research on this behavior, and based on community findings, the issue occurs specifically when Microsoft.OpenApi 3.x is used with .NET 10. Rolling the package back to a 2.x version restores the original property behavior and resolves the build error.

    At this time, .NET 10 does not provide full support for Microsoft.OpenApi 3.x, and broader support is expected in a future .NET release.

    Recommended solution:

    • Downgrade Microsoft.OpenApi to a 2.x version (for example, 2.3.9) to restore compatibility.

    For more information, please check this link: https://github.com/dotnet/aspnetcore/issues/64317

    Hope this helps! If my answer was helpful - kindly follow the instructions here so others with the same problem can benefit as well.

    Was this answer helpful?

    3 people found this answer helpful.

  2. can kucukgultekin 330 Reputation points
    2025-11-20T23:20:56.3166667+00:00

    Hello Tirth Shah, this one isnt your fault, its a known incompatibility between microsoft.aspnetcore.openapi 10 and microsoft.openapi 3.0.0.

    whats going on: asp.net core 10s microsoft.aspnetcore.openapi package is built against the 2.x line of microsoft.openapi. in your project microsoft.openapi got auto-upgraded to 3.0.0 (either directly in the csproj via directory.packages.props or via a floating version). microsoft.openapi 3.0.0 introduces breaking changes, one of them is that iopenapiMediatype.example is now read-only. the asp.net core openapi source generator still assumes the old contract and generates code like:

    foreach (var mediaType in content)
    {
        mediaType.Example = jsonString.Parse();
    }
    

    since the interface no longer has a setter the compiler quite correctly throws "property or indexer iopenapiMediatype.example cannot be assigned to -- it is read only". so this is basically a package version mismatch/bug not an issue in your own code.

    how to fix it: pin microsoft.openapi to a 2.x version, add an explicit reference in your project:

    <ItemGroup>
      <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0" />
      
    

    or if youre using central package management (directory.packages.props):

    <ItemGroup>
      <PackageVersion Include="Microsoft.OpenApi" Version="2.0.0" />
    </ItemGroup>
    

    then clean the solution (dotnet clean), delete bin/obj if needed, rebuild. once youre back on microsoft.openapi 2.x the example property again matches what microsoft.aspnetcore.openapi expects and the build error disappears.

    double-check where 3.0.0 is coming from: if you didnt add microsoft.openapi yourself run:

    dotnet list YourProject.csproj package
    

    and see if some other package or a central props file bumped it to 3.0.0. override it with an explicit 2.x reference as shown above.

    if you really need microsoft.openapi 3.0.0 today: right now (late 2025) microsoft.openapi 3.0.0 simply isnt compatible with asp.net core 10s built-in openapi implementation, this is explicitly called out in the github issue. if you must use 3.0.0 features immediately youd have to drop microsoft.aspnetcore.openapi from your app, build your openapi documents manually using microsoft.openapi 3.0.0 and wire up swagger ui/redoc yourself. for 99% of use cases tho the pragmatic fix is: stick to microsoft.openapi 2.x for now let asp.net core handle openapi the usual way and remove the explicit pin once a future asp.net core version officially supports 3.x.


    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  3. Simon L 0 Reputation points
    2025-11-27T14:41:48.2733333+00:00

    I had a reference to OpenAPI v3 in my packages.lock.json and not in my projects. Deleting the package.lock.json solved the error. Thank you all.

    Was this answer helpful?

    0 comments No comments

  4. Raj Kansagara 0 Reputation points
    2025-11-19T12:53:52.51+00:00

    Possible fix:-
    Update the below package and try to clean solution and run again.
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.0" />

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.