locked
Access to a disposed object of type ' ' is not possible RRS feed

  • Question

  • Hi,

    I'm getting "Access to a disposed object of type ' ' is not possible." error while running nunit test cases.

    The test cases were running fine. All of a sudden, I'm getting the message for some of the test cases.

    I feel some configuration would have been changed. Can anybody please let me know what causes for this error?

    Kindly waiting for your reference.

    Thanks,

    Santosh

    • Moved by Fei Hu Monday, April 2, 2018 5:43 AM Moved From C#
    Saturday, March 31, 2018 6:14 PM

All replies

  • You did not use any code?

    Success
    Cor

    Saturday, March 31, 2018 6:36 PM
  • The test cases which fails are random. I mean some test cases which fail at one instance will pass in the next instance...without any modification.

    Saturday, March 31, 2018 6:55 PM
  • Hello Santosh,

    According to your question is more related to unit test, I will move the thread to unit test forum for better support and solution.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vsunittest

    The Visual C# discuss and ask the C# programming language, IDE, libraries, samples and tools. If you have some grammar or code errors, please feel free to contact us. We will try our best to give you a solution.

    Best Regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Edited by Fei Hu Monday, April 2, 2018 5:42 AM
    Monday, April 2, 2018 5:42 AM
  • In Nunit console it shows, erorr in c:\Users\XYZ\AppData\Local\Temp\me1ewkmc.55.cs:line 418.

    But this file is not available to access...

    Monday, April 2, 2018 6:52 AM
  • Hi Santosh,

    What’s the Visual Studio version do you use?

    Do you run your test project via VS IDE?

    Based on the error, it means that you can’t access the object, how is your test code?

    Could you please share your test project to me, that will help to test in my side and find the solution. You could upload your project to OneDrive and share a link here.

    Thanks for your understanding.

    Regards,

    Judyzh


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 2, 2018 7:56 AM
  • Hi,

    Thanks for the response.

    Please find the code as below:

    public void Test_Import(string fileName)
            {
                           var result = Import(fileName);

    // Assert statement
            }

    private bool Import(string fileName)
            {
                string filePath = GetFilePath(fileName);

                try
                {
                    Provider provider = GetProvide();
                    Console.WriteLine("BEFORE IMPORT CALL");
                    Console.ReadLine();
                    if (provider != null &&
                        provider.Import(new FileInfo(filePath)); // after this call I get the exception. The exception is not always. It comes few times only.
                    {
                        Console.WriteLine("AFTER IMPORT CALL");
                        Console.ReadLine();
                        return true;
                    }
                    return false;
                }
                catch (Exception ex)
                {
                    string fileName = Path.GetTempFileName();
                    FileInfo fileInfo = new FileInfo(fileName);
                    fileInfo.Attributes = FileAttributes.Temporary;

                    Console.WriteLine("TEMP file created at: " + fileName);
                    string message = ex.Message;
                    return false;
                }


    Monday, April 2, 2018 8:49 AM
  • Hi Santosh,

    >> In Nunit console it shows, erorr in c:\Users\XYZ\AppData\Local\Temp\me1ewkmc.55.cs:line 418.

    Do you run your unit test project via Nunit Console?

    I suggest you could run the test via VS IDE, did you encounter the same issue?

    Please refer to following do a check, before code “if (provider != null &&
                        provider.Import(new FileInfo(filePath));

    if provider.IsDisposed then return;

    In order to repro your issue in my side, could provide the full code to me? You could upload your project to OneDrive and share a link here.

    Thanks for your understanding and cooperation.

    Regards,

    Judyzh


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, April 3, 2018 5:56 AM