EFPlus System.InvalidOperationException: Part does not exist

I am trying to develop and wpf application with selenium for learning purpouse, but i am facing someting strange. I want to use EFPlus to modify an Excel row at each itteration, on some computers works just fine, but also on another computers i get :

Nu s-a putut modifica EXCELUL cu SENT pentru id 3164092 + System.InvalidOperationException: Error saving file C:WPFSEleniumExcelFoldertest.xlsx ---> System.InvalidOperationException: Part does not exist.
   at OfficeOpenXml.Packaging.ZipPackage.GetPart(Uri partUri)
   at OfficeOpenXml.Packaging.ZipPackage.DeletePart(Uri Uri)
   at OfficeOpenXml.ExcelWorksheet.SaveDrawings()
   at OfficeOpenXml.ExcelWorksheet.Save()
   at OfficeOpenXml.ExcelWorkbook.Save()
   at OfficeOpenXml.ExcelPackage.Save()
   --- End of inner exception stack trace ---
   at OfficeOpenXml.ExcelPackage.Save()
   at WPFSElenium.MainWindow.<WaitForConfirmation>d__10.MoveNext() in C:WPFSEleniumWPFSEleniumWPFSEleniumMainWindow.xaml.cs:line 478

the code:

            confirmEvent
            
            private async void WaitForConfirmation()
                {
            confirmEvent.WaitOne();
            string chatId = "xxxxxxxxx";
            int controBlocareCont = 0;
            int idNegasiteConcomitent = 0;

            Application.Current.Dispatcher.Invoke(() =>
            {
                if (Application.Current.MainWindow != null)
                {
                    Application.Current.MainWindow.WindowState = WindowState.Minimized;
                }
            });
            Thread.Sleep(GenerateRandomInterval());
            
            string directoryPath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "ExcelFolder");
            if (Directory.Exists(directoryPath))
            {
                string[] excelFiles = Directory.GetFiles(directoryPath, "*.xlsx");
                if (excelFiles.Length > 0)
                {
                    string filePath = excelFiles[0];

                    // Add full permissions to the Excel file
                    FileInfo fileInfo = new FileInfo(filePath);
                    FileSecurity fileSecurity = fileInfo.GetAccessControl();
                    fileSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, AccessControlType.Allow));
                    fileInfo.SetAccessControl(fileSecurity);

                    using (var package = new ExcelPackage(new FileInfo(filePath)))
                    {
                        ExcelWorkbook workbook = package.Workbook;
                        if (workbook != null)
                        {
                            ExcelWorksheet worksheet = workbook.Worksheets[0];
                            int rowCount = worksheet.Dimension.End.Row;
                            worksheet.Protection.IsProtected = false;

                            for (int row = 2; row <= rowCount; row++)
                            {
                                if (worksheet.Cells[row, 4].Value == null)
                                {
                                    string id = worksheet.Cells[row, 1].Value?.ToString();
                                    if (id != null && (id.Length != 2 && id.Length != 1))
                                    {
                                       
                                        Thread.Sleep(GenerateRandomInterval());
                                        try
                                        {
                                                divElement.Text = "Test";
                                            string NumePersoana = divElement.Text;

                                            if (NumePersoana == worksheet.Cells[row, 2].Value.ToString())
                                            {
                                                divElement.Click();

                                                ExcelWorksheet worksheetMesaje = workbook.Worksheets[1];
                                                int rowCountMesaje = worksheetMesaje.Dimension.End.Row;
                                                Random random = new Random();
                                                int randomRow = random.Next(2, rowCountMesaje + 1);
                                                string mesajAleatoriu = worksheetMesaje.Cells[randomRow, 1].Value.ToString();

                                                IWebElement textArea = null;
                                                try
                                                {
                                                    textArea = driver.FindElement(By.XPath("));
                                                    Thread.Sleep(GenerateRandomInterval());
                                                    textArea.SendKeys(mesajAleatoriu);
                                                    Thread.Sleep(GenerateRandomInterval());
                                                    textArea.SendKeys(Keys.Enter);
                                                    Thread.Sleep(IntervalSendMessage);
                                                    worksheet.Cells[row, 4].Value = "Sent";
                                                    package.Save();
                                                    
                                                    InputID.SendKeys(Keys.Control + "a");
                                                    InputID.SendKeys(Keys.Delete);
                                                }
                                                catch (NoSuchElementException)
                                                {
                                                    worksheet.Cells[row, 4].Value = "Blocked";
                                                    package.Save();
                                                    InputID.SendKeys(Keys.Control + "a");
                                                    InputID.SendKeys(Keys.Delete);
                                                    continue;
                                                }
                                                catch (Exception ex)
                                                {
                                                    string messageSentErr = $"ATENTIE: Nu s-a putut modifica EXCELUL cu SENT pentru id {id} + {ex}";
                                                    InputID.SendKeys(Keys.Control + "a");
                                                    InputID.SendKeys(Keys.Delete);
                                                    await _botSender.SendMessageAsync(chatId, messageSentErr);
                                                }
                                            }
                                            else
                                            {
                                                worksheet.Cells[row, 4].Value = "Not Sent";
                                                package.Save();
                                                InputID.SendKeys(Keys.Control + "a");
                                                InputID.SendKeys(Keys.Delete);
                                                controBlocareCont++;

                                                if (controBlocareCont == 10)
                                                {
                                                    string messageBlocked = "ATENTIE: Posibil sa aveti contul BLOCAT. nVa rugam repornit BOT-ul cu un nou cont";
                                                    await _botSender.SendMessageAsync(chatId, messageBlocked);
                                                }
                                            }
                                        }
                                        catch (NoSuchElementException)
                                        {
                                            worksheet.Cells[row, 4].Value = "Not Sent";
                                            package.Save();
                                            InputID.SendKeys(Keys.Control + "a");
                                            InputID.SendKeys(Keys.Delete);
                                            idNegasiteConcomitent++;

                                            if (idNegasiteConcomitent % 10 == 0)
                                            {
                                                string messageElementNotFound = $"ATENTIE: {idNegasiteConcomitent} Id-uri nu a fost identificate la rand pe FACEBOOK nVerificati corectitudinea fisierului EXCEL";
                                                await _botSender.SendMessageAsync(chatId, messageElementNotFound);
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            string messageNotSentErr = $"ATENTIE: Nu s-a putut modifica EXCELUL cu NOT SENT pentru id {id} + {ex}";
                                            InputID.SendKeys(Keys.Control + "a");
                                            InputID.SendKeys(Keys.Delete);
                                            await _botSender.SendMessageAsync(chatId, messageNotSentErr);
                                        }
                                    }
                                }
                            }

                            package.Save();
                            package.Dispose();
                            string message = "ATENTIE: Au fost procesate toate PERSOANELE din EXCEL-ul furnizat. nVa rugam repornit BOT-ul cu un nou set de date";
                            await _botSender.SendMessageAsync(chatId, message);
                        }
                    }
                }
            }
        }

the problem appear at package.Save();

i tried to do package.Dispose() after every excel modification , but at the second itteration i get another erroar that says the worksheet is disposed

New contributor

SergiuBrk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật