© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•15mo ago•
8 replies
joo

Source code generation not working with partial record, only with partial class

Using a basic incremental source code generator to generate some serializer-like functionality.


[Generators.Pkt]
public partial record/class ChatMsgReq
{
    public int Ticks { get; set; }
    public required string Msg { get; set; }
    public bool OnlyBalloon { get; set; }
}
[Generators.Pkt]
public partial record/class ChatMsgReq
{
    public int Ticks { get; set; }
    public required string Msg { get; set; }
    public bool OnlyBalloon { get; set; }
}


Generated Code:

* Record:
// <auto-generated/>

using System;
using System.Collections.Generic;

using A.Net;

namespace A.Proto;

public partial record ChatMsgReq : IDecodePacket<ChatMsgReq>, IEncodePacket
{
    public static ChatMsgReq DecodePacket(ref PacketReader r)
    {
        return new ChatMsgReq
        {
            Ticks = r.ReadInt(),
            Msg = r.ReadString(),
            OnlyBalloon = r.ReadBool(),
        };
    }

    public void EncodePacket(ref PacketWriter w)
    {
        w.WriteInt(Ticks);
        w.WriteString(Msg);
        w.WriteBool(OnlyBalloon);
    }
}
// <auto-generated/>

using System;
using System.Collections.Generic;

using A.Net;

namespace A.Proto;

public partial record ChatMsgReq : IDecodePacket<ChatMsgReq>, IEncodePacket
{
    public static ChatMsgReq DecodePacket(ref PacketReader r)
    {
        return new ChatMsgReq
        {
            Ticks = r.ReadInt(),
            Msg = r.ReadString(),
            OnlyBalloon = r.ReadBool(),
        };
    }

    public void EncodePacket(ref PacketWriter w)
    {
        w.WriteInt(Ticks);
        w.WriteString(Msg);
        w.WriteBool(OnlyBalloon);
    }
}


* Class:

// <auto-generated/>

using System;
using System.Collections.Generic;

using A.Net;

namespace A.Proto;

public partial class ChatMsgReq : IDecodePacket<ChatMsgReq>, IEncodePacket
{
    public static ChatMsgReq DecodePacket(ref PacketReader r)
    {
        return new ChatMsgReq
        {
            Ticks = r.ReadInt(),
            Msg = r.ReadString(),
            OnlyBalloon = r.ReadBool(),
        };
    }

    public void EncodePacket(ref PacketWriter w)
    {
        w.WriteInt(Ticks);
        w.WriteString(Msg);
        w.WriteBool(OnlyBalloon);
    }
}
// <auto-generated/>

using System;
using System.Collections.Generic;

using A.Net;

namespace A.Proto;

public partial class ChatMsgReq : IDecodePacket<ChatMsgReq>, IEncodePacket
{
    public static ChatMsgReq DecodePacket(ref PacketReader r)
    {
        return new ChatMsgReq
        {
            Ticks = r.ReadInt(),
            Msg = r.ReadString(),
            OnlyBalloon = r.ReadBool(),
        };
    }

    public void EncodePacket(ref PacketWriter w)
    {
        w.WriteInt(Ticks);
        w.WriteString(Msg);
        w.WriteBool(OnlyBalloon);
    }
}



With class I can access
DecodePacket
DecodePacket
and
EncodePacket
EncodePacket
just fine, however for the record I'm unable to access It. Also If I copy the
partial record
partial record
without any source code just below the original
record
record
It works fine aswell.

Any Idea why this isn't working for records?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ OneOf library code generation not working?
C#CC# / help
8mo ago
Partial class problem
C#CC# / help
3mo ago
CS0122, just with a partial class...
C#CC# / help
3y ago