We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Can't save workbook because used by another process

Thread ID:

Created:

Updated:

Platform:

Replies:

145816 Jul 9,2019 01:50 PM UTC Jul 24,2019 12:27 PM UTC WinForms 5
loading
Tags: XlsIO
Paul Meems
Asked On July 9, 2019 01:50 PM UTC

I've got a weird problem.
When I call my class from a unit test, it works great.
When I call it from a button click on my form I can't save the workbook anymore.

My class opens the workbook in its constructor. A method is opening other Excel files, reads them and puts some data in the first workbook.
When calling 
_workbookWerkbestand.Save();
or 
_workbookWerkbestand.Close(true);

I get the error: Can't save workbook because used by another process 

I'm not using any multithreading or paralyzation mechanisms.

My unit test:
            try
            {
                using (var service = new InventarisatieFormulierService(werkbestand))
                {
                    foreach (var formulier in formulieren)
                    {
                        service.MergeData(formulier);
                    }
                }
            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }

My button click:
            try
            {
                using (var service = new InventarisatieFormulierService(_werkbestandLocation))
                {
                    foreach (var formulierLocation in _formulierLocations)
                    {
                        service.MergeData(formulierLocation);
                    }
                }
                ShowEnd(true);
            }
            catch (Exception exception)
            {
                ShowEnd(false);
            }
            
My InventarisatieFormulierService (relevant parts):
    public class InventarisatieFormulierService : IDisposable
    {
        private readonly XlsService _xlsService = new XlsService();
        private readonly IWorkbook _workbookWerkbestand;

        public InventarisatieFormulierService(string werkbestandLocation)
        {
            _workbookWerkbestand = _xlsService.OpenWorkbook(werkbestandLocation);
        }

        public void Dispose()
        {
            _workbookWerkbestand.Close(true);  <---- Throws error
            _xlsService?.Dispose();
        }

        public void MergeData(string formulier)
        {
            var workbookFormulier = _xlsService.OpenWorkbook(formulier);
            var sheet3Werkbestand = _workbookWerkbestand.Worksheets[3];
            ...
           // Loop through formulierWorksheet:

              // Write some data to first worksheet:
              sheet3Werkbestand.Range[goodRow, 2].Number = 9;
              sheet3Werkbestand.Range[goodRow, 5].Text = "DGR, "

           // Close workbookFormulier:
           workbookFormulier.Close();
        }
  }

My XlsService class (relevant parts):
public class XlsService: IDisposable
{
        public XlsService()
        {
            _excelEngine = new ExcelEngine();
            _application = _excelEngine.Excel;
            _application.DefaultVersion = ExcelVersion.Xlsx;
            _application.EnableIncrementalFormula = true;
        }
        public IWorkbook OpenWorkbook(string fileName)
        {
            return OpenWorkbook(fileName, false);
        }

        private IWorkbook OpenWorkbook(string fileName, bool readOnly)
        {
            if (!File.Exists(fileName)) return null;

            if (!_application.IsSupported(fileName))
                throw new NotSupportedException("This Excel version is not supported and the file cannot be opened.",
                    new Exception("Working with " + fileName));

            return readOnly ? _application.Workbooks.OpenReadOnly(fileName) : _application.Workbooks.Open(fileName);
        }
        public void Dispose()
        {
            _excelEngine?.Dispose();
        }
}

What am I missing?

Abirami Varadharajan [Syncfusion]
Replied On July 10, 2019 03:52 PM UTC

Hi Paul, 
  
Greetings from Syncfusion. 
  
We are able to reproduce the issue and validating it currently. We will update further details by 12th July 2019. 
  
Regards, 
Abirami 


Abirami Varadharajan [Syncfusion]
Replied On July 12, 2019 01:15 PM UTC

Hi Paul, 

Thank you for your patience. 

We confirmed issue with “Saving the workbook throws exception after invoking IApplication.IsSupported method” is a defect and logged a defect report for the same. The patch for this issue is estimated to be available on 17th July 2019. 

Regards, 
Abirami 


Abirami Varadharajan [Syncfusion]
Replied On July 17, 2019 01:51 PM UTC

Hi Paul, 
 
The issue with “Saving the workbook throws exception after invoking IApplication.IsSupported method has been fixed and the patch for this fix can be downloaded from the following location. 

Recommended approach - exe will perform automatic configuration
Please find the patch setup from below location:
http://syncfusion.com/Installs/support/patch/17.1.0.47/156585/I145816/SyncfusionPatch_17.1.0.47_156585_7172019075401015_I145816.exe

Advanced approach – use only if you have specific needs and can directly replace existing assemblies for your build environment
Please find the patch assemblies alone from below location:
http://syncfusion.com/Installs/support/patch/17.1.0.47/156585/I145816/SyncfusionPatch_17.1.0.47_156585_7172019075401015_I145816.zip 
 

Assembly Version: 17.1.0.47
 
Installation Directions : 
This patch should replace the files “Syncfusion.XlsIO.Base” under the following folder.
$system drive:\ Files\Syncfusion\Essential Studio\$Version # \precompiledassemblies\$Version#\4.5
Eg : $system drive:\Program Files\Syncfusion\Essential Studio\17.1.0.47\precompiledassemblies\17.1.0.47\4.5

To automatically run the Assembly Manager, please check the Run assembly manager checkbox option while installing the patch. If this option is unchecked, the patch will replace the assemblies in precompiled assemblies’ folder only. Then, you will have to manually copy and paste them to the preferred location or you will have to run the Syncfusion Assembly Manager application (available from the Syncfusion Dashboard, installed as a shortcut in the Application menu) to re-install assemblies.

Note : 
To change how you receive bug fixes, ask your license management portal admin to change your project’s patch delivery mode.

https://www.syncfusion.com/account/license

Disclaimer : 
Please note that we have created this patch for version 17.1.0.47 specifically to resolve the following issue(s) reported in this/the forum 145816.
 

If you have received other patches for the same version for other products, please apply all patches in the order received.
 
This fix will be included in our release version 16.2 SP1 which will be available by mid of August 2019. 
 
Regards, 
Abirami 
 


Paul Meems
Replied On July 22, 2019 11:34 AM UTC

I can confirm the patch is working.
Thanks for the quick solution.

Abirami Varadharajan [Syncfusion]
Replied On July 24, 2019 12:27 PM UTC

Hi Paul, 

Thank you for updating us. 

We are glad that the issue is resolved at your end. Please let us know if you need further assistance. 

Regards, 
Abirami 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon