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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:25:53+00:00 2026-05-31T02:25:53+00:00

I use ProtoBuf to serialize class. Unfortunately Serializer.Deserialize method gives error Type is not

  • 0

I use ProtoBuf to serialize class. Unfortunately Serializer.Deserialize method gives error “Type is not expected, and no contract can be inferred: System.Object”. Any hint how to solve this.

private void WriteToFile( string siteID, object objectTemp, stringfileSystemPath)
        {
            var type = objectTemp.GetType();
using (var file = File.Create(fileSystemPath))
                {
                    Serializer.NonGeneric.Serialize(file, objectTemp);
                }
        }

private object ReadFromFile( string siteID, object objectTemp, stringfileSystemPath)
        {
            Type type = objectTemp.GetType();   
            object objectTemp2=null;
                using (var file = File.OpenRead(fileSystemPath))
                {
                    objectTemp2 = Serializer.NonGeneric.Deserialize(type, file);
                }
                return objectTemp2;
            }
        }

I am using protobuf.Net v2 beta with .Net 3.5

  • 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-31T02:25:54+00:00Added an answer on May 31, 2026 at 2:25 am

    Serializer.NonGeneric.Deserialize wants to be provided a protobuf-generated type. (you are giving it the type of System.Object. It doesn’t know what to do with that).

    Look at the C# code generated by protoc, and specify a typeof() of the class you are trying to read from file.

    Or put another way, if WriteToFile is succeeding, then use the type of objectTemp. The type that went in to the file is the type that needs to come out of the file.

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

Sidebar

Related Questions

I use ProtoBuf to serialize class which is created at runtime using Activator.CreateInstance. Unfortunately
Using Protobuf-Net, I see that it does not seem possible to deserialize a class
C#, How can I use ProtoBuf .NET to serialize a dataTable? Can I please
I'd like to use protobuf-net to serialize a derived class as its base class.
I'm trying to serialize a model using the great Protobuf-NET. I cannot use the
Can I use net.tcp bindings for protobuf-net WCF? Can I use ClientBase or I
I'm trying to serialize some objects with protobuf-net , but unfortunately they make liberal
I am trying to use protobuf to serialize my WCF calls, but it seems
Use case: Wanna insert custom annotation to fields in java class generated by JAXB
Use case: class MyTask(Task): queue = 'default_queue' def run(self): # do work Normally I

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.