Skip to content
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

Replace Guid serialization #292

Closed
rushfrisby opened this issue Aug 2, 2017 · 3 comments
Closed

Replace Guid serialization #292

rushfrisby opened this issue Aug 2, 2017 · 3 comments

Comments

@rushfrisby
Copy link

rushfrisby commented Aug 2, 2017

To work around protobuf-net's handling of Guids which other languages don't know about I've ended up doing this a lot:

[DataContract]
public class TestResult
{
    public Guid Id { get; set; }

    [DataMember(Order = 1)]
    private string IdValue
    {
        get
        {
            return Id.ToString();
        }
        set
        {
            Id = Guid.Parse(value);
        }
    }
}

This can get messy if Guids are used a lot so I'd like to use a surrogate instead:

RuntimeTypeModel.Default.Add(typeof(Guid), true).SetSurrogate(typeof(GuidSurrogate));

however, I get this runtime exception:

System.ArgumentException: 'Data of this type has inbuilt behaviour, and cannot be added to a model in this way: System.Guid'

Is there any way to get around this?

@mgravell
Copy link
Member

mgravell commented Aug 2, 2017 via email

@kibblewhite
Copy link

kibblewhite commented Apr 25, 2022

Not sure if this will help (for others also as I realise this post comes a little late) but there are some ideas here floating around here:

@mgravell
Copy link
Member

For today: this topic is actually addressed by Compatibility Level: https://protobuf-net.github.io/protobuf-net/compatibilitylevel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants