Bug in debug mode in Visual Studio 2015, which depends on the file size

86 views Asked by At

Good afternoon I need to maintain a C# application that uses the EPPlus library. The application does not require installation; its task is to process and analyze MS Excel documents.

Until recently, I used Visual studio 2017 Community to debug code and make edits. Unfortunately, due to policy within the organization (restricted access to the Internet). I had to use Visual studio 2015 Enterprise. And here I encountered a problem: when I try to process a file larger than 20 MB in debug mode, a critical failure occurs in the application (Exception: ObjectDisposedException in mscorlib.dll Access to a closed stream is impossible).

However. If I run the same file (where the crash occurred) in VS 2017 in debug mode, there is no crash! Also, if I run a fully compiled application (both debug and release versions of the build) then there is no crash. The error occurs at the moment of creating an instance of the ExcelPackage class; the presence of the using directory has no effect (I tried removing it). I will provide a code fragment below. Failures occur only with large files (approximately more than 20Mb, it is quite difficult to calculate more accurately). Perhaps someone has encountered similar behavior in VS 2015? Yes, I understand that it is possible to separate threads, but I would like to understand the root cause. The program has already been successfully used by users. But I may need to debug...and specifically in the 2015 version. Framework version – 4.5, EPPlus – 4.5.8. The problem is reproduced on different computers, with different versions of operating systems, of course Windows)

I will be glad to receive suggestions, comments, ideas! Yes, I will also ask this question on the EPPlus forum. Code snippet:

public static bool Read_x2(string FilePath)
{
    bool res = false;
    errorCheck = string.Empty;
    currentFilePath = FilePath;

    showMessProcessStep?.Invoke($"Start processing the file {FilePath}");
    if (Program.debug) Console.WriteLine("Start reading the file .");
    FileInfo existingFile = new FileInfo(FilePath);
    string new_name = existingFile.Name.Replace(existingFile.Extension, "") + "_full_check_clear" + ".xlsm";
    FileInfo outputFile = new FileInfo(existingFile.DirectoryName + Path.DirectorySeparatorChar + new_name);
    string name_dis_trp = existingFile.DirectoryName + Path.DirectorySeparatorChar + "TRP_File_check" + ".xls";
    FileInfo TRP_Dis_File = new FileInfo(name_dis_trp);
    targetFilePath = outputFile.FullName;
    cycle = 1; //+ 23.05.2022 For cicle mode

    if (OpenResultExcel.launchedProcessFile(currentFilePath))
    {
        errorCheck = $"Close the file before running the file check {currentFilePath}";
        return false;
    }
    if (OpenResultExcel.launchedProcessFile(targetFilePath))
    {
        errorCheck = $"Close the file before running the file check {targetFilePath}";
        return false;
    }
    bool fOutputFileLock = false; //+ Delete the file if it exists
    if (outputFile.Exists)
    {
        try
        {
            outputFile.Delete();
        }
        catch
        {
            fOutputFileLock = true;
        }
    }
    if (!fOutputFileLock)
    {
        showMessProcessStep?.Invoke($"Finalizing file styles {existingFile.Name}");
                                                                                           
        OpenResultExcel.rewriteExcelFile_1(currentFilePath); //+ Resaving a document using Visual Basic - necessary for correct formatting inside the document

        using (ExcelPackage package = new ExcelPackage(existingFile, false)) // HERE IS A FAILURE IN DEBUG MODE!.
        {
            //Method body
        }
    }
}

I tried to load a new file that would not use any method - it did not help.

0

There are 0 answers