System.NotSupportedException: Stream does not support writing

Originally Posted 9 November 2016, 4:04 am EST

  • Originally Posted 9 November 2016, 4:04 am EST

    Hi There,

    Sometimes when I am saving my exported data to C1Excel file, I am getting below error message.

    ************** Exception Text **************
    System.NotSupportedException: Stream does not support writing.
    at System.IO.FileStream.SetLength(Int64 value)
    at C1.C1Zip.ZipEntryStreamWriter.AddCompressed()
    at C1.C1Zip.ZipEntryStreamWriter.Close()
    at C1.C1Zip.C1ZipFile.Add(Stream srcStream, String entryName)
    at C1.C1Excel.OpenXmlWriter.Save(C1ZipFile zipFile)
    at C1.C1Excel.OpenXmlWriter.Save(String fileName)
    at C1.C1Excel.C1XLBook.SaveInternalOpenXml(String fileName)
    at C1.C1Excel.C1XLBook.Save(String fileName, FileFormat format)

    I suspect this issue is happening on this line of code.
    mWorkBook.Save(mSaveFileName, FileFormat.OpenXml)

    where mSaveFileName is the path where I want to save the file and in .xlsx format(mentioned in save method)

    This is happening very rarely so I am unable to figure it out why this is happening.

    Any suggestions will be appreciated!!
    S Malleswararao
  • Reply

    Hello S Malleswararao,

    We suspect that the error is not because of exporting to C1Excel File but it is due to C1Zip which you are using in your application. This error could be caused by any software scanning the files and making them read only or your anti virus turning off real time scanning of zip file etc. Therefore we suggest you to check for Zip File related functionality in your application. If the problem is still not resolved then we request you to kindly share with us all information regarding Zip file and share with us your application, so that we can help you further.

  • Reply

    Hello Pragati,

    Thank you for your response. I wonder why this error is caused due to C1Zip because we are not using C1Zip anywhere in our application. We are only using C1Excel and C1Flexgrid in our application but no other C1 components. Looking at the Exception stack, this error starts when application is trying to save the C1Excel workbook.

    If I explain about my application's architecture, it is windows application running on Terminal servers which users will access through Citrix portal and all the exported files will be saved on to user accessible network drive. But as you said if it could be caused due to scanning software or anti virus restrictions, then how can I check those permissions/logs on user's machine?

    Kindly let me know if more information is required.

    Thanks & Regards
    S Malleswararao
  • Marked as Answer


    Hi S Malleswararao,

    Since you are not using C1Zip anywhere in your application and still getting the said error, I would request you to please share a stripped down application demonstrating the behavior so that I can investigate further into this and help you better. In case you do not want share it on public forums, you can create a case at SupportOne and post the problem there along with your application:

  • Reply

    We are also getting this exact error for some of our customer. However, we are using C1ZIP and the error happened when adding a file to be zipped. This error apparently only happens to some of our customers.

    Has there been a solution to this problem?

    System.NotSupportedException: Stream does not support writing.
    at System.IO.FileStream.SetLength(Int64 value)
    at C1.C1Zip.d.a()
    at C1.C1Zip.d.c()
    at System.IO.Stream.Dispose()
    at C1.C1Zip.C1ZipFile.a(Stream A_0, String A_1, DateTime A_2)
    at C1.C1Zip.C1ZipFile.a(String A_0, String A_1, DateTime A_2)
    at C1.C1Zip.C1ZipEntryCollection.Add(String fileName, String entryName, DateTime dateTime)
    at C1.C1Zip.C1ZipEntryCollection.Add(String fileName, String entryName)
    at C1.C1Zip.C1ZipEntryCollection.Add(String fileName)
    at #ULf.#I4f.AddFile(String #n4f) in C:\Build\CMS\AA_Release\AAUtility\CompressionUtilObj.cs:line 179
    at #ULf.#M2f.SendFile(String #Ob) in C:\Build\CMS\AA_Release\AAUtility\ServerComponentObj.cs:line 254
    at #ULf.#C2f.SendFile(String #Ob) in C:\Build\CMS\AA_Release\AAUtility\ServerComponentObj.cs:line 92
  • Reply


    We could not replicate this issue at our end, please refer to the sample attached. If you are doing something different then please modify the sample accordingly and let us know. Also please provide the environment details where you are getting this issue so that we can investigate this issue further.

    Prabhat Sharma.
  • Reply

    Our application is a Windows desktop app. We use C1Zip to zip up files before uploading to our data center. The zip files are created at Environment.SpecialFolder.LocalApplicationData \ Our-Application-Name \ which equals to C:\Users\stephen.lee\AppData\Local\Our-Application-Name\Temp.

    The error happens only occasionally. It may create 100 files without error and then the next one will crash the system because we are not handling the particular error.

    Do you think it may have something to do with a virus scanner?

  • Reply

    Hi Stephen,

    Such issues were reported earlier and as per our investigation, it occurs in the specific environment only and they were by design.
    So could you please let us know your environment details and the build version of the controls that you are using.‚ÄčAlso let us know the file formats of the files that you zip.

    We don't think it is related to the virus scanner but you can check at your end if the issue occurs after setting the virus scanner off.

    Prabhat Sharma.
  • Reply

    We are using C1.C1Zip.4, Version=4.0.20152.67. The files we were adding to the zip file were straightly ASCII files. As I said in the previous comment, the location of the zip file was at "Environment.SpecialFolder.LocalApplicationData" so the application should always has access to that folder. This error happens only occasionally on some computers.
  • Reply

    Hi Stephen,

    We still could not replicate this issue at our end. As you are using a very old version of controls and some earlier reported issues were for the 2018 version so I would request you to upgrade the controls to the latest version and let us know if the issue still occurs.

    We have checked this in the following environment:
    Win 10 + VS 2019
    Win 10 + VS2017

    Prabhat Sharma.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels