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 6692641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:53:27+00:00 2026-05-26T05:53:27+00:00

I wanted to use protocolbuf .net version without attributes, with RuntimeTypeModel created via specific

  • 0

I wanted to use protocolbuf .net version without attributes, with RuntimeTypeModel created via specific code. It worked pretty good till I hit the case, which was extracted in the case below. The referenced protobuf-net library’s version is 2.0.0.447. What’s wrong with this model’s creation? Any clues?

public class ProtoBufFailingTest
{
    public abstract class Message
    {
    }

    public class SomeMessage : Message
    {
        public readonly Descriptor Desc;

        public SomeMessage(Descriptor desc)
        {
            Desc = desc;
        }
    }

    public struct Descriptor
    {
        public readonly Event EventData;

        public Descriptor(Event eventData)
        {
            EventData = eventData;
        }
    }

    public abstract class Event
    {
    }

    public class SomeEvent : Event
    {
        public int SomeField;
    }

    [Test]
    public void FailingTest( )
    {
        var model = TypeModel.Create();

        // message hierarchy
        {
            var messages = model.Add(typeof(Message), true);
            messages.AddSubType(1, typeof(SomeMessage));
            model[typeof(SomeMessage)].UseConstructor = false;
        }

        // events hierarchy
        {
            var events = model.Add(typeof (Event), true);
            events.AddSubType(1, typeof (SomeEvent));
            model[typeof (SomeEvent)].UseConstructor = false;
        }

        // descriptor
        var eventDescriptorModel = model.Add(typeof(Descriptor), true);
        eventDescriptorModel.UseConstructor = false;

        var typeModel = model.Compile();

        const PrefixStyle prefixStyle = PrefixStyle.Base128;
        const int testValue = 5;
        using (var ms = new MemoryStream())
        {

            typeModel.SerializeWithLengthPrefix(ms, new SomeMessage(new Descriptor(new SomeEvent { SomeField = testValue })), null, prefixStyle, 0);

            ms.Seek(0, SeekOrigin.Begin);

            // fails here
            var message = (SomeMessage)typeModel.DeserializeWithLengthPrefix(ms, null, typeof(Message), prefixStyle, 0);

            Assert.AreEqual(testValue, ((SomeEvent)message.Desc.EventData).SomeField);
        }
    }
}
  • 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-05-26T05:53:28+00:00Added an answer on May 26, 2026 at 5:53 am

    Very simply; the library has (had) a bug, emitting

    initobj {type}
    stloc.0
    

    when obviously (cough) for a value-type Descriptor it should have been emitting

    ldloca.s 0
    initobj {type}
    

    I’ll get this deployed as soon as I’ve checked I haven’t destabilised anything.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying out the version 1.2 appcelerator and wanted to use the NSUserDefaults with
I wanted to use the following code from here: How can I save all
I wanted to use the Flying Saucer Java API in .NET so I tried
I created a subclass of UITableView and wanted to use it with a UITableViewController
I wanted to use .net's System.IO.Compression.GZipStream to compress and decompress a directory. But I
I wanted to use the currentStateChange event in my application but whatever code being
I wanted to use a native Dll in my C# .net application as this:
I wanted to use ASMifierClassVisitor tool to get the asm code of creating a
I saw the following code, and wanted to use it for a simple activity
I wanted to use count() function in ColdFusion Query object. Here is my code

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.