Skip to content

Unhandled exception on Linux ignores Dispose #79155

Closed
@macias

Description

@macias

Description

When you have unhandled exception which goes through using, Dispose is ignored on Linux.

Reproduction Steps

Run code with following content on Linux machine:

 public class Disposal : IDisposable
    {
        public void Dispose()
        {
            Console.WriteLine("disposed");
        }
    }

   class Program
    {
        static void Main(string[] args)
        {
                using (new Disposal())
                {
                    throw new Exception();
                }
         }
    }

Expected behavior

Message "disposed" shown in terminal.

Actual behavior

No message.

Regression?

I don't know.

Known Workarounds

At top level wrap around everything in:

try
{
   .... your code goes here
}
catch 
{
  throw;
}

Configuration

openSUSE 15.3, x64. I see this bug when using dotnet 6.0 and 7.0.

I also tested it on Windows 10, x64 with dotnet 5.0, the program runs correctly (i.e. the message is displayed).

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions