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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:13:28+00:00 2026-06-06T04:13:28+00:00

When reading normally from an SslStream using the Read(byte[] buffer, int offset, int count)

  • 0

When reading normally from an SslStream using the Read(byte[] buffer, int offset, int count) method, I get the expected results.

However, if I move the SslStream object into a new AppDomain, the read still appears to function correctly (i.e. the correct number of bytes read is returned), but the buffer array is empty.

Why is this?

  • 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-06T04:13:29+00:00Added an answer on June 6, 2026 at 4:13 am

    After some investigation, it appears that the contents of parameter arrays are not marshalled across AppDomains (probably for performance reasons).

    Therefore, the data in the buffer parameter is only passed one way. Modifications to the array in the remote AppDomain will not be seen by the caller in the local AppDomain.

    The way to force data in array parameters to be returned is to add the [Out] attribute to the parameter.

    To solve the problem stated in the question, create a wrapper class for the SslStream and use that instead:

    [Serializable]
    internal class SslStreamWrapper : SslStream
    {
        public SslStreamWrapper(
            Stream innerStream,
            Boolean leaveInnerStreamOpen,
            RemoteCertificateValidationCallback validationCallback,
            LocalCertificateSelectionCallback selectionCallback)
         : base(innerStream, leaveInnerStreamOpen, validationCallback, selectionCallback)
        {
        }
    
        // Add the [Out] attribute to the 'buffer' parameter.
        public override Int32 Read([In, Out] Byte[] buffer, Int32 offset, Int32 count)
        {
            return base.Read(buffer, offset, count);
        }
    }
    

    The class has the [Serializable] attribute, allowing it to be passed between AppDomains, and the implicit [In] parameter is included for consistency with other Stream classes.

    Many other .NET classes inheriting from Stream (such as MemoryStream and BufferedStream – and even Stream itself) include the [In, Out] attributes for the buffer parameter in the Read() method.

    I wonder if it was a deliberate choice to omit them for SslStream… This goes for all versions of .NET.

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

Sidebar

Related Questions

I am reading data from a scale using a serial port. Communication is working
Reading some posts from Jimmy Boggard and wondering - how exactly is it possible
Reading through the SendAsync , BeginAsync method illustrations of Socket s, I realized that
I'm not a Javascript person normally, but I've been diving in, reading Douglas Crockford's
I got the Hello, Android program to work after reading the tutorials from Google's
I was reading about this scenario where making use of the C# using statement
I'm working on a small component for writing and reading AT Commands using an
I'm using Vim to read man and I'm trying to set up a script
I'm having a problem reading and processing data from my server. I've spent hours
I have a text string i'm trying to select the spans from using jQuery.

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.