Skip to content

When a native exception of corrupted state is thrown, nunit test thread crashes and the nunit-console process hangs #2091

Closed
@endrih

Description

@endrih

When using NUnit in C++/CLI and the state is somehow corrupted (unrecoverable errors), the nunit thread that runs the test crashes. The nunit-console thread that is waiting on the operation to complete, never exits the wait and therefore hangs the whole process.

Maybe using NUnit for C++/CLI is not supported, but we have a lot of them.

I have made a quick fix like this in NUnit.Framework.Internal.Reflect in Reflect.cs:

[HandleProcessCorruptedStateExceptions] //put here to handle native corrupt state exceptions. 
        public static object InvokeMethod( MethodInfo method, object fixture, params object[] args )
        {
            if(method != null)
            {
                try
                {
                    return method.Invoke(fixture, args);
                }
#if !PORTABLE && !NETSTANDARD1_6
                catch (System.Threading.ThreadAbortException)
                {
                    // No need to wrap or rethrow ThreadAbortException
                    return null;
                }
#endif
                catch (TargetInvocationException e)
                {
                    throw new NUnitException("Rethrown", e.InnerException);
                }
                catch (Exception e)
                {
                    throw new NUnitException("Rethrown", e);
                }
#pragma warning disable 1058
                catch
#pragma warning restore 1058
                {
                    throw new NUnitException("Rethrown", new Exception("Unknown Native exception thrown."));
                }
            }

            return null;
        }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions