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

  • Home
  • SEARCH
  • 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 9263159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T13:31:09+00:00 2026-06-18T13:31:09+00:00

Recently I have been writing some serializable object that also deals with specific logic

  • 0

Recently I have been writing some serializable object that also deals with specific logic and has specific life-cycle. In order for it to work properly, it has to be instantiated with an appropriate constructor, that takes mandatory arguments. For serialization purposes, however, I must also add a public default constructor.

The object will be publicly available by our API and 3rd party developers should be able to instantiate and use it. Although there will be an appropriate documentation for how to correctly manipulate with that object, it is no guarantee that someone will be tempted to use the incorrect constructor – and then have trouble.

I am looking for a neat way to apply some guidance while the 3rd party developers are writing their code. The Obsolete attribute came to my mind – I could annotate the serialization constructor with an appropriate comment as a message. The message will then appear in the output warnings and direct the developer to the right line of code. Also, the constructor usage will get appropriately highlighted by both Visual Studio and any code inspection add-on used.

What is bothering me in this approach is that the purpose of the Obsolete attribute is quite different. It’s semantical meaning is that the decorated item is deprecated and will probably be removed in further versions. In the serialization constructor scenario this is wrong, and there will be a discrepancy between the usage and meaning of this attribute. Not to mention the option “treat warnings as errors” that might be enabled in some development departments…

So, the question is – is it a an acceptable practice for such usage of the attribute? Are there any other legal and universal ways to achieve the same effect (by universal I mean not relying on 3rd party code inspection add-ons and etc. – I do not control who uses the code and what is their setup) ?


In regards to the comments in the answer below, (which is still useful to me), I must clarify that I am using a protected default constructor on an inheritable class. The constructor is there to support XML serialization, but should not be used for initializing the class in business logic. Inheriting classes should call some of the other base constructors and developers writing the inherited classes need to know that. Still, the developers deriving from this code must also have the means to enable XML serialization for their inherited classes if needed.

  • 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-18T13:31:10+00:00Added an answer on June 18, 2026 at 1:31 pm

    Hm, I don’t think that this is a good solution. However, do you really need a default constructor?

    Note that the serialization API has methods to create uninitialized instances without using a constructor at all (see MSDN: FormatterServices.GetUninitializedObject).

    Also, the normal custom serialization constructor is not a default constructor but one taking a SerializationInfo and a StreamingContext. If you have some custom serialization, you may also be able to solve your issue by making the default constructor internal and apply a InternalsVisibleToAttribute for the assembly performing the serialization.

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

Sidebar

Related Questions

I have recently been doing some work that has been quite in depth, i
Recently, I have been writing many classes which have, apart from generic variant, some
I have recently been writing a Java NIO based server with non-blocking sockets and
I have been running into some troubles recently and I think I need your
Recently I have been trying to update some code to utilise the standard C++
Recently several tools have been released such as pyjamas and Scheme2js that allow one
I have been writing C code for many years, but I recently came accross
I have been writing command-line Python scripts for a while, but recently I felt
This isn't my code, I'm just troubleshooting it. Some code that has been working
I have recently been exposed to some ETL tools such as Talend and Apatar

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.