mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Don't wrap default type activator exception if it's not related to constructor
This commit is contained in:
@@ -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
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user