You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
When a native exception of corrupted state is thrown, nunit test thread crashes and the nunit-console process hangs #2091
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;
}
Fyi: this was never fixed. The PR has never had any effect because #1775 added [assembly: AllowPartiallyTrustedCallers] and the docs say this means that [HandleProcessCorruptedStateExceptions] is ignored:
The HandleProcessCorruptedStateExceptionsAttribute attribute is ignored when it is encountered in partially trusted or transparent code, because a trusted host should not allow an untrusted add-in to catch and ignore these serious exceptions.
Activity
jnm2 commentedon Oct 23, 2017
A note on
catch: In C#, any non-Exceptionobjects get wrapped andcatch (Exception e)already catches everything.See
RuntimeWrappedExceptionon MSDN.jnm2 commentedon Jul 2, 2019
Fyi: this was never fixed. The PR has never had any effect because #1775 added
[assembly: AllowPartiallyTrustedCallers]and the docs say this means that[HandleProcessCorruptedStateExceptions]is ignored: