Don't wrap default type activator exception if it's not related to constructor

This commit is contained in:
Oleksii Holub
2022-04-16 13:54:44 +00:00
committed by GitHub
parent 33f95d941d
commit 86742755e8

View File

@@ -16,14 +16,15 @@ public class DefaultTypeActivator : ITypeActivator
{ {
return Activator.CreateInstance(type); return Activator.CreateInstance(type);
} }
catch (Exception ex) // Only catch MemberAccessException because the constructor can throw for its own reasons too
catch (MemberAccessException ex)
{ {
throw CliFxException.InternalError( throw CliFxException.InternalError(
$"Failed to create an instance of type `{type.FullName}`." + $"Failed to create an instance of type `{type.FullName}`, could not access the constructor." +
Environment.NewLine + Environment.NewLine +
"Default type activator is only capable of instantiating a type if it has a public parameterless constructor." + "Default type activator is only capable of instantiating a type if it has a public parameterless constructor." +
Environment.NewLine + Environment.NewLine +
"To fix this, either add a parameterless constructor to the type or configure a custom activator on the application.", "To fix this, either add a parameterless constructor to the type or configure a custom activator for the application.",
ex ex
); );
} }