Different exception is thrown in newer version. Is this a bug or a design decision?
Hello,
I have some code which used Unity 5.8.6. When a resolution of a class failed, it used to throw a Unity.Exceptions.ResolutionFailedException.
In Unity 5.11.1, it throws a System.Reflection.TargetInvocationException now. Is this a design decision or a bug?
Example: The following code registers a class, which throws an exception in the constructor:
using System.Reflection;
using Unity;
namespace UnityNewException
{
class Program
{
static void Main(string[] args)
{
UnityContainer container = new UnityContainer();
container.RegisterType<ITestClass, TestClass>();
try
{
// The implementation should throw an exception in the constructor.
var config = container.Resolve<ITestClass>();
}
// Thrown in Unity 5.8.6
catch (ResolutionFailedException e)
{
System.Console.WriteLine("Exception = " + e.GetType());
System.Console.WriteLine("Inner exception = " + e.InnerException.GetType());
}
// Thrown in Unity 5.11.1
catch (TargetInvocationException e)
{
System.Console.WriteLine("Exception = " + e.GetType());
System.Console.WriteLine("Inner exception = " + e.InnerException.GetType());
}
System.Console.ReadKey();
}
}
}
Is there any difference between ResolutionFailedException and TargetInvocationException? Is ResolutionFailedException outdated or is this a bug?
Thanks.
It would help if you could create a test case I can execute.
@ENikS
Thank you for the fast response.
You can download my test solution containing two projects containing the same code but using different unity container versions.