Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent first-chance exceptions #557

Closed
dotnetjunkie opened this issue May 16, 2018 · 3 comments
Closed

Prevent first-chance exceptions #557

dotnetjunkie opened this issue May 16, 2018 · 3 comments

Comments

@dotnetjunkie
Copy link
Collaborator

@dotnetjunkie dotnetjunkie commented May 16, 2018

There are still a few places in the Simple Injector code bases that swallow exceptions and continue. Newer versions of Visual Studio, however, show first chance exceptions by default in the debugger, and this behavior is quite hard to disable.

Because of this, it can lead to confusing situations, where users think there is a problem they need to fix, while everything is actually working fine.

Whenever possible, these first chance exceptions should be prevented.

@dotnetjunkie dotnetjunkie added the task label May 16, 2018
@dotnetjunkie dotnetjunkie modified the milestones: v5.0, Backlog May 16, 2018
@dotnetjunkie dotnetjunkie modified the milestones: Backlog, v4.4 May 29, 2018
@dotnetjunkie
Copy link
Collaborator Author

@dotnetjunkie dotnetjunkie commented Jul 14, 2018

There are four places in particular that swallor exceptions:

  • GenericTypeBuilder.IsImplementationApplicableToEveryGenericType
  • GenericTypeBuilder.BuildClosedGenericImplementationBasedOnMatchingServiceType
  • Container.SelectImplementationTypeConstructorOrNull
  • ContainerOptions.IsConstructableType

The first two, inside the GenericTypeBuilder, are places that can't be easily fixed. They work around corner case scenario's when dealing with generic type constraints.

The last two, however, are the cases that should be fixed.

Problem with both the SelectImplementationTypeConstructorOrNull and IsConstructableType methods, however, is that they wrap a call to IConstructorResolutionBehavior.GetConstructor, which by design either returns a valid constructor or throws an exception.

These fixes can, therefore, only be made by changing IConstructorResolutionBehavior and thus introducing a breaking change.

@dotnetjunkie dotnetjunkie modified the milestones: v4.4, v5.0 Jul 17, 2018
@dotnetjunkie dotnetjunkie removed the task label Dec 12, 2019
@dotnetjunkie
Copy link
Collaborator Author

@dotnetjunkie dotnetjunkie commented Apr 25, 2020

feature-557 branch created.

@dotnetjunkie
Copy link
Collaborator Author

@dotnetjunkie dotnetjunkie commented Jun 1, 2020

API Changes:

  • ConstructorInfo GetConstructor(Type) method of IConstructorResolutionBehavior interface replaced with ConstructorInfo? TryGetConstructor(Type, out string?) method.
  • void Verify(InjectionConsumerInfo) method of IDependencyInjectionBehavior interface replaced with bool VerifyDependency(InjectionConsumerInfo, out string?) method.
  • New LegacyBehaviorExtensions class added with the following two extension method:
    • ConstructorInfo GetConstructor(this IConstructorResolutionBehavior, Type)
    • void Verify(this IDependencyInjectionBehavior, InjectionConsumerInfo)
      These methods mimic the old behavior, which prevents calling code to be changed. (recompile is still required)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant