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

Resolving a record without registration causes a StackOverflowException #446

Closed
joelweiss opened this issue Jan 6, 2022 · 5 comments
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@joelweiss
Copy link

The following code will throw a StackOverflowException, am I missing something?
.Net Fiddle

void Main()
{
    var container = new Container(Rules.Default.WithAutoConcreteTypeResolution());
    //container.Register<Foo>();
    container.Resolve<Foo>();
}

public record Foo { };
@dadhi dadhi self-assigned this Jan 6, 2022
@dadhi dadhi added the bug Something isn't working label Jan 6, 2022
@dadhi dadhi added this to the v4.8.6 milestone Jan 6, 2022
@dadhi
Copy link
Owner

dadhi commented Jan 6, 2022

@joelweiss

The problem that record generates the protected "copy" constructor in addition to the default constructor,
and DryIoc prefers the former because it has more parameters. Instead, DryIoc should prefer public over the non-public constructors first.

@dadhi
Copy link
Owner

dadhi commented Jan 6, 2022

@joelweiss

Moreover, I think that using the protected constructor for the injection is wrong because it normally supposed to be called by the other constructor of the inherited class. So I may just exclude the protected constructors from the most resolvable constructor lookup.

@dadhi
Copy link
Owner

dadhi commented Jan 6, 2022

@joelweiss

OK. The change with excluding the protected will be breaking and need to be more thoughtful.
But for the specific case with AutoConcrete type resolution will be enough to filter out recursive constructors with the same type as parameter.

@dadhi dadhi closed this as completed in 1fc25ba Jan 6, 2022
@joelweiss
Copy link
Author

@dadhi Thanks.

What is the difference when registering explicitly, why didn't it throw then?

@dadhi
Copy link
Owner

dadhi commented Jan 19, 2022

@joelweiss Explicit registration looks up for the single public constructor, otherwise throws by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants