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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:45:36+00:00 2026-06-11T05:45:36+00:00

Okay, so let me see if I can make this as concise as possible.

  • 0

Okay, so let me see if I can make this as concise as possible. I am going to be passing in an object of an unknown type into a method that is going to internally use the BinaryFormatter to serialize the data it’s passed (I chose this because I have no idea what the data is so it’s the most abstract mechanism I could imagine). And let’s assume that method looks like this currently:

public void ProvideData(Guid providerKey, ISerializable data, string dataType)...

Now let’s assume I need to make sure what’s passed to me can in fact be serialized and so that why I thought I would require the object to implement ISerializable. However, one issue with this model is that I can’t even pass in a string because eventhough a string is [Serializable] it doesn’t implement ISerializable.

So, what is the proper way to structure this method to ensure that the value passed to me, simple or complex, is serializable?

  • 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-11T05:45:37+00:00Added an answer on June 11, 2026 at 5:45 am

    You can check by using the IsSerializable property on the Type.

    For example:

    bool canSerialize = myParameter.GetType().IsSerializable;
    

    EDIT BY OP: Final Implemented Method

    Below is the final implementation because of this answer (very good answer). It is just a prototype so that’s why there’s not a lot going on in the method but it proves the answer. One thing to note is that checking for the existence of the ISerializable interface holds no value because you won’t know until you try and serialize the object whether or not it should have implemented ISerializable so I was moving down the wrong path there.

    Thanks!

    public void ProvideData(Guid providerKey, object data, string dataType)
    {
        if (!data.GetType().IsSerializable)
        {
            throw new ArgumentException("The data passed is not serializable and therefore is not valid.", "data");
        }
    
        var formatter = new BinaryFormatter();
        using (var fileStream = new FileStream("data.dat", FileMode.Create))
        {
            formatter.Serialize(fileStream, data);
            fileStream.Close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay let me see if I can explain this right. In wordpress we have
Okay, let's see if I can explain what I mean, here's an image to
Okay so let's say I have class A... CLASS A has a method that
Let's see...where to start here? Okay, yes I am working in Joomla and trying
I have this value from database: '2009-1-1 00:00:00', okay, let me paste my code:
I want to take an object, let's say this object: public class BenchmarkList {
Okay, let's see if I'm thinking straight: If I simply want to read some
Okay this question is very simple: I have a facebook page, and a website.
Okay, I feel a bit foolish for having to ask this but I guess
Okay - I have a dilemma. So far my script converts page titles into

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.