Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception during static constructor loading is not cleaned up #13714

Closed
marek-safar opened this issue Mar 28, 2019 · 2 comments
Assignees

Comments

@marek-safar
Copy link
Member

@marek-safar marek-safar commented Mar 28, 2019

Steps to Reproduce

  1. Compiler following sample
using System;
using System.Reflection;


public static class Test
{
	static Test ()
	{
		throw new ApplicationException ();
	}

	public static void Foo ()
	{

	}
}

class Run
{
	public static void Main ()
	{
		var m = typeof (Test).GetMethod ("Foo");

		try
		{
			m.Invoke (null, null);
		}
		catch (Exception e)
		{
		}

		try
		{
			m.Invoke (null, null);
		}
		catch (Exception e)
		{
		}

		try
		{
			m.Invoke (null, null);
		}
		catch (Exception e)
		{
		}

		m.Invoke (null, null);
	}
}
  1. mono sample.xe

Current Behavior

The stack trace from each failure is accumulated with results like

Unhandled Exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'Test' threw an exception. ---> System.ApplicationException: Error in the application.
  at Test..cctor () [0x00001] in <c6d9d0a1394b4a2bbbf5f1d7351b1b11>:0 
   --- End of inner exception stack trace ---
  at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <c1faa05c43c14f57bc6406ddc22d57d3>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <c1faa05c43c14f57bc6406ddc22d57d3>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <c1faa05c43c14f57bc6406ddc22d57d3>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <c1faa05c43c14f57bc6406ddc22d57d3>:0 
   --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00083] in <c1faa05c43c14f57bc6406ddc22d57d3>:0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <c1faa05c43c14f57bc6406ddc22d57d3>:0 
  at Run.Main () [0x0004e] in <c6d9d0a1394b4a2bbbf5f1d7351b1b11>:0 

Expected Behavior

Correct stack trace

On which platforms did you notice this

[ ] macOS
[ ] Linux
[ ] Windows

Version Used: master

@marek-safar

This comment has been minimized.

Copy link
Member Author

@marek-safar marek-safar commented Mar 28, 2019

/cc @aleksey

@lambdageek lambdageek self-assigned this Mar 28, 2019
@lambdageek

This comment has been minimized.

Copy link
Member

@lambdageek lambdageek commented Apr 8, 2019

@thaystg This type initialization is an interesting place in Mono.

thaystg added a commit to thaystg/mono that referenced this issue Apr 9, 2019
monojenkins added a commit that referenced this issue Apr 10, 2019
Cleaning exceptions during static constructor loading

Reset the stack_trace and trace_ips because the type initialization exception is reused.
Fixes #13714
filipnavara added a commit to filipnavara/mono that referenced this issue Apr 11, 2019
Cleaning exceptions during static constructor loading

Reset the stack_trace and trace_ips because the type initialization exception is reused.
Fixes mono#13714
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.