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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:08:27+00:00 2026-05-24T22:08:27+00:00

From http://msdn.microsoft.com/en-us/library/system.io.memorystream%28v=VS.90%29.aspx : Memory streams created with an unsigned byte array provide a non-resizable

  • 0

From http://msdn.microsoft.com/en-us/library/system.io.memorystream%28v=VS.90%29.aspx:

Memory streams created with an unsigned byte array provide a
non-resizable stream of the data. When using a byte array, you can
neither append to nor shrink the stream, although you might be able to
modify the existing contents depending on the parameters passed into
the constructor. Empty memory streams are resizable, and can be
written to and read from.

When provided a reference to a MemoryStream (or even just a Stream), how can one check if it’s resizable?

The situation arose when using the OpenXML SDK, which requires the streams passed to it be resizable. I can ensure resizability by deep copying to a resizable stream, I’m just wondering if there’s a particular reason why the library doesn’t throw an exception when a bad parameter is passed to it (i.e. an unresizable stream).

  • 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-24T22:08:28+00:00Added an answer on May 24, 2026 at 10:08 pm

    Here’s one kinda ugly way were you catch the NotSupportedException when attempting to resize.

    public static bool IsResizable(this Stream stream)
        {
            bool result;
            long oldLength = stream.Length;
    
            try
            {
                stream.SetLength(oldLength + 1);
                result = true;
            }
            catch (NotSupportedException)
            {
                result = false;
            }
    
            if (result)
            {
                stream.SetLength(oldLength);
            }
    
            return result;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I see an example from the website http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser%28v=VS.90%29.aspx Here they are using a statement
The following code was grabbed from MSDN: http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.stringlengthattribute.aspx [MetadataType(typeof(ProductMetadata))] public partial class Product {
Using the function from: http://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndaelmanaged.aspx public static byte[] encryptStringToBytes_AES(string plainText, byte[] Key, byte[] IV)
A quote from MSDN: http://msdn.microsoft.com/en-us/library/6kac2kdh.aspx One or more managed threads (represented by System.Threading.Thread) can
From http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.structlayoutattribute(VS.71).aspx: [C++] [StructLayout(LayoutKind::Explicit, Size=16, CharSet=CharSet::Ansi)] __value class MySystemTime { public: [FieldOffset(0)] short int
From this sample code from MSDN http://msdn.microsoft.com/en-us/library/system.string.gethashcode.aspx The hash code for abc is: 536991770
I got below code from http://msdn.microsoft.com/en-us/library/dd584174(office.11).aspx for adding custom property in webpart tool pane.
I have installed a sample database, specifically Northwind from http://msdn.microsoft.com/en-us/library/8b6y4c7s.aspx . After installing the
I'm looking at the TPL exception handling example from MSDN @ http://msdn.microsoft.com/en-us/library/dd537614(v=VS.100).aspx The basic
How can I use the ListView_GetBkImage macro: http://msdn.microsoft.com/en-us/library/bb761246(v=VS.85).aspx ... from a C#/WinForms application? 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.