Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7887177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:30:40+00:00 2026-06-03T05:30:40+00:00

There is a need to serialize some BL structure that contains DrawingBrush. I’ve rewritten

  • 0

There is a need to serialize some BL structure that contains DrawingBrush. I’ve rewritten it as follows :

[ProtoContract]
public class BaseProtoBuf : INotifyPropertyChanged, IFormattable
{
    [ProtoMember(1)]
    public string ID { get; set; }
    // Bunch of properties of .net primitive types
    // ..
    private DrawingBrush _geometry;
    [ProtoMember(9)]
    [Browsable(false)]
    public DrawingBrush Geometry
    {
            get { return _geometry; }
            set
            {
                _geometry = value; 
                ScaleDrawing();
            }
    }
}
[ProtoContract]
[ProtoInclude(1, typeof(string))]
// All other includes
[ProtoInclude(9, typeof(DrawingBrush)]
public class DerivedProtoBuf : BaseProtoBuf, ICloneable
{        
    // Some additional properties of primitive types, annotated starting with ProtoMember 10 and so on
}

To serialize i’m executing following code :

const string fileName = "Protobuf.bin";
using (var file = File.Create(fileName))
{
    file.Position = 0;
    var testBase = new BaseProtoBuf
                                   {
                                      Height = 100,
                                      Width = 100,
                                      Name = "Test 1",
                                      OffsetX = 200,
                                      OffsetY = 200,
                                      Geometry = sourceList[0].Geometry // some not-null DrawingBrush
                                  };
    Serializer.Serialize(file, testBase);
    file.Position = 0;
    var restored = Serializer.Deserialize<BaseProtoBuf>>(file);
}
}

I need to serialize Derived class object, but during Base serialization i get “No suitable Default DrawingBrush encoding found”. Thought it’s because DrawingBrush can be null for some objects, but in test one it isn’t. Any workarounds to properly serialize 1) Base object with not-null DrawingBrush 2) Derived object with null DrawingBrush ? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:30:42+00:00Added an answer on June 3, 2026 at 5:30 am

    Correct RuntimeTypeModel configuration for serializing of simple WPF Brush :

    RuntimeTypeModel.Default.Add(typeof(Brush), false)
                   .AddSubType(300, typeof(SolidColorBrush));
    RuntimeTypeModel.Default.Add(typeof(SolidColorBrush), false)
                    .Add("Color");
    RuntimeTypeModel.Default.Add(typeof(Color), false)
                    .Add("A", "R", "G", "B"); // needed for proper color serialization
    RuntimeTypeModel.Default.Add(typeof(SolidColorBrush), false)
            .Add("Color");
    RuntimeTypeModel.Default.Add(typeof(DrawingBrush), false)
            .Add("Stretch", "Drawing");
    RuntimeTypeModel.Default.Add(typeof(Drawing), false)
            .AddSubType(100, typeof(DrawingGroup))
            .AddSubType(200, typeof(GeometryDrawing));
    RuntimeTypeModel.Default.Add(typeof(DrawingGroup), false)
            .Add("Children");
    RuntimeTypeModel.Default.Add(typeof(Pen), false)
            .Add("Brush", "Thickness", "LineJoin");
    RuntimeTypeModel.Default.Add(typeof(GeometryDrawing), false)
           .Add("Brush", "Geometry", "Pen");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that I need to binary serialize. The class contains one
I've got an quite simple class that contains some primitive types and some collections
Hi There I need to get the names and values of checkboxes that have
I need to XML serialize some classes, which in some cases do not adhere
I'm working on a project where I'll need to serialize some data in a
We have an application where we need to de-serialize some data from one stream
I need to serialize some objects loaded by iBatis, but am getting NotSerializableException because
I need to serialize a collection, but I would like to know if there
I've got a tree structure that I need to rearrange (drag and drop) and
I need to serialize/de-serialize some objects into/from string and transfer them as just opaque

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.