question

HARISHVN-9018 avatar image
0 Votes"
HARISHVN-9018 asked DanielZhang-MSFT commented

System.ObjectDisposedException: Cannot access a closed Stream when running this statement MemoryStream stream = (MemoryStream)data.GetData(cbExpression, false)

public ResolvedExpression GetClipBoardExpression()
{
try
{

             IDataObject data = Clipboard.GetDataObject();
             if (!data.GetDataPresent(cbExpression, false))
                 return null;

             using (MemoryStream stream = (MemoryStream)data.GetData(cbExpression, false))   `**>>>>>> Exception comes here , And this happens when copy and pasting text using ctrl+c and ctrl+v  and only using RealVNC veiwer.**

             {
                     BinaryReader reader = new BinaryReader(stream, System.Text.Encoding.UTF8);
       }

dotnet-csharp
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Is this a custom clipboard format? Show how did you write the data to clipboard.



0 Votes 0 ·

Hi @HARISHVN-9018,
If you do not put the MemoryStream in the using statement, does the same error occur?
Please try to replace the using block with following code:

 MemoryStream stream = (MemoryStream)data.GetData(cbExpression, false);
 try
 {
      //...
    
 }
 catch
 {
    //...
     stream .Dispose();
     throw;
 }

Best Regards,
Daniel Zhang

0 Votes 0 ·

Hi
yes this solution was tried already but it is not working
The problem is when i take the node where application is running in VNC viewer then only this crash/exceptions happens
otherwise it does not happen

0 Votes 0 ·

Hi @HARISHVN-9018,
As it may be caused by the VNC viewer, it is recommended that you go to the VNC viewer related forum for more professional help.
Best Regards,
Daniel Zhang


0 Votes 0 ·

0 Answers