diff --git a/CliFx/Infrastructure/DefaultTypeActivator.cs b/CliFx/Infrastructure/DefaultTypeActivator.cs index 0edc320..d541c99 100644 --- a/CliFx/Infrastructure/DefaultTypeActivator.cs +++ b/CliFx/Infrastructure/DefaultTypeActivator.cs @@ -16,14 +16,15 @@ public class DefaultTypeActivator : ITypeActivator { 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( - $"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 + "Default type activator is only capable of instantiating a type if it has a public parameterless constructor." + 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 ); }