You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Jens Geyer (Jira)" <ji...@apache.org> on 2026/05/14 22:22:00 UTC

[jira] [Resolved] (THRIFT-5997) netstd generator: binary and uuid constants emitted as C# const instead of static readonly

     [ https://issues.apache.org/jira/browse/THRIFT-5997?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jens Geyer resolved THRIFT-5997.
--------------------------------
    Fix Version/s: 0.24.0
       Resolution: Fixed

> netstd generator: binary and uuid constants emitted as C# const instead of static readonly
> ------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-5997
>                 URL: https://issues.apache.org/jira/browse/THRIFT-5997
>             Project: Thrift
>          Issue Type: Bug
>          Components: netcore - Library, netstd - Compiler
>            Reporter: Jens Geyer
>            Assignee: Jens Geyer
>            Priority: Major
>             Fix For: 0.24.0
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> The netstd code generator declares all Thrift {{const}} fields of base types using the C# {{const}} keyword ({{print_const_value}}, line ~619). Two base types cannot legally be C# {{const}}:
> 1. *binary* maps to {{byte[]}} in C#. Arrays are reference types and cannot be {{const}}. The generated code calls {{System.Text.Encoding.UTF8.GetBytes("...")}} as the initialiser, which is a runtime expression, not a compile-time constant. This produces CS0133 ("expression must be constant").
> 2. *uuid* maps to {{System.Guid}} in C#. {{Guid}} is a struct, but it is not one of the primitive types recognised by C# as a constant type (bool, char, numerics, string, enums). The generated {{new System.Guid("...")}} initialiser is also a runtime call. This produces both CS0283 ("type Guid cannot be declared as const") and CS0133.
> Fix: in {{print_const_value()}}, detect {{is_binary()}} and {{TYPE_UUID}} and emit {{public static readonly}} instead of {{public const}} for those two cases. The initialiser expression remains unchanged — it is legal for {{static readonly}} fields.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)