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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:20:35+00:00 2026-05-17T18:20:35+00:00

Using C#/.NET for my application, I’ve got a series of classes in my main

  • 0

Using C#/.NET for my application, I’ve got a series of classes in my main data model that represent "binary" (as opposed to text) content. I’ve got a inheritance setup like this:

alt text

Basically, the abstract class BinaryContent contains a MemoryStream that stores arbitrary binary data. That data is read from a file on disk. Each type of binary data I plan to store will be a derived type, such as ImageContent and FontContent. Those derived types will interpret the binary data in BinaryContent.Content. ImageContent for example, would create a BitmapImage (stored in an ImageSource) from the MemoryStream. FontContent would of course create a font from the BinaryContent.Content. I chose this way of doing things because I wanted to be able to basically store a copy of the content file (ie an image) and not have to rely on the file being in a particular location on disk time after time.

I’m also storing instances of these classes in a "project file" using binary serialization. I’ve done this to basically "package" everything together. I’m having trouble when I attempt to deserialize the MemoryStream, it seems. The problem happens when I create the image from the MemoryStream. When the following method runs after deserialization, a FileFormatexception occurs.

private void RefreshImageFromContent()
{
    BitmapImage image = null;
    if (Content != null &&
        Content.Length != 0L)
    {
        image = new BitmapImage();
        image.BeginInit();
        image.StreamSource = Content;
        image.EndInit(); //throws FileFormatException
    }

    Image = image;
}

The FileFormatException message is:
"The image cannot be decoded. The image header might be corrupted."
Inner Exception: "Exception from HRESULT: 0x88982F61"

My best guess right now is that something is happening to corrupt the data in BinaryContent.Content when during serialization or deserialization.

This leads me to ask 2 questions.

  1. Does anyone have any suggestions to fix this problem?
  2. Does anyone have other suggested ways to store arbitrary binary data that is going to be (de)serialized?

Please feel free to ask for clarification on anything about my question.

Thanks.

  • 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-17T18:20:36+00:00Added an answer on May 17, 2026 at 6:20 pm

    What is the content.Position at image.StreamSource = Content;?

    It is likely that the position of the stream is not set to the start (or the correct position in thw stream).

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

Sidebar

Related Questions

I'm using Lucene.Net in an ASP.NET application on a shared host. Got this stack
I have a asp.net application in that I am using ado.net entity framework in
I have an ASP.NET application that is using ASP.NET AJAX. I am using the
I have an application that is built using ASP.NET, with an embedded Silverlight Object
I'm running a .NET remoting application built using .NET 2.0. It is a console
I'm using .NET 3.5 SP1 in ASP.NET MVC application. While using ObjectContext with Http
I maintain a legacy ASP.Net Web application (using .Net 2.0 + SQL Server 2005
I'm attaching a new database programatically using VB.net application. I wrote DB scripts and
Im using c# .net windows application form. I have created many databases with many
I want to test ASP.NET application using NUnit, but it seems WebConfigurationManager.ConnectionStrings collection is

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.