Search Issue Tracker

Fix in review

Votes

0

Found in

Issue ID

805846

Regression

No

Wrong exception types don't fall through in generic methods, causing invalid cast exception

IL2CPP

-

-

Priority: 4Not yet prioritized for a release

-

Severity: 3Workaround is possible

Given this code, .NET and IL2CPP output differs:

using System;
using static System.Console;

class Program
{
public delegate void ActionDelegate();

static void CatchException<T>(ActionDelegate action) where T : Exception
{
try
{
action();
}
catch (T e)
{
WriteLine("Caught T: {0}", e.Message);
}
}

static void Main()
{
try
{
CatchException<NullReferenceException>(() => { throw new NotImplementedException(); });
}
catch (Exception e)
{
WriteLine("Caught something. Exception type: {0}", e.GetType());
}
}
}

>csc a.cs /nologo

>a.exe
Caught something. Exception type: System.NotImplementedException

>il2cpp.exe --outputpath=a_il2cpp.exe --cachedirectory="obj_cache" --generatedcppdir="generated_cpp" a.exe && a_il2cpp.exe
.....
Caught something. Exception type: System.InvalidCastException

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.