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

StackoverflowException on Get(name) after update from 3.3.4 to 3.3.5 #393

Closed
mur-dock opened this issue May 27, 2022 · 7 comments
Closed
Assignees
Labels

Comments

@mur-dock
Copy link

Hi there,

I ran into an major issue after updating Ninject up to version 3.3.5.

As you can see in the code below, I want to request an instance of "Dummy" with "TryGet(name)".
But before that I have not registered a corresponding binding of "Dummy".
Therefore, I expected "NULL" as the result of "TryGet".
Ninject tries to create an instance of "Dummy". However, the only constructor available requires that you pass a "string" as a parameter.

And if I pass a "name" as a parameter to "TryGet", then a StackoverflowException occurs.

internal class Program
{
    static void Main(string[] args)
    {
        var kernel = new StandardKernel();
        var dummy = kernel.TryGet<Dummy>("name");
        Debug.Assert(dummy == null);
    }
}

public class Dummy
{
    public Dummy(string name)
    {
        Name = name;
    }

    public string Name { get; set; }
}
@scott-xu scott-xu self-assigned this May 27, 2022
@scott-xu
Copy link
Member

Would you mind sharing the call stack?

@scott-xu
Copy link
Member

Just want to mention that the name here TryGet<Dummy>("name") is the name of the binding but not to supply the constructor parameter. It will look for the binding which named as "name".

@mur-dock
Copy link
Author

As it seems, I don't get the StackoverflowException reproduced right now.
What remains, however, is the case of running into a kind of infinite loop.

Here again is a specific code that shows that it is the "name" parameter that is passed:

internal class Program
{
    static void Main(string[] args)
    {
        var provider = new Provider();
        var dummy = provider.TryGet<Dummy>("My.Application.Composition");
        Debug.Assert(dummy == null);
    }
}

public class Provider
{
    private readonly IKernel _kernel;

    public Provider()
    {
        _kernel = new StandardKernel();
    }

    public T TryGet<T>(string name)
    {
        // some aspect code

        return _kernel.TryGet<T>(name: name); // <-- using T as Dummy running an infinite loop
    }
}

public class Dummy
{
    public Dummy(string name)
    {
        Name = name;
    }

    public string Name { get; set; }
}

@mur-dock
Copy link
Author

I'm using Ninject in a bigger application.
This application using a package.
An this package calls "TryGet" with a name parameter.

@scott-xu
Copy link
Member

Thanks @mur-dock , I can reproduce your issue. Will try make a fix soon.

@mur-dock
Copy link
Author

mur-dock commented May 27, 2022

In the whole application I get a StackoverflowException and this callstack:

mscorlib.dll!System.Collections.Generic.List<System.Func<Ninject.Planning.Bindings.IBinding, bool>>.Capacity.set(int value)
mscorlib.dll!System.Collections.Generic.List<System.__Canon>.EnsureCapacity(int min)
mscorlib.dll!System.Collections.Generic.List<System.Func<Ninject.Planning.Bindings.IBinding, bool>>.Add(System.Func<Ninject.Planning.Bindings.IBinding, bool> item)
Ninject.dll!Ninject.Planning.Bindings.BindingPrecedenceComparer.Compare(Ninject.Planning.Bindings.IBinding x, Ninject.Planning.Bindings.IBinding y)
System.Core.dll!System.Linq.EnumerableSorter<Ninject.Planning.Bindings.IBinding, Ninject.Planning.Bindings.IBinding>.CompareKeys(int index1, int index2)
System.Core.dll!System.Linq.EnumerableSorter<Ninject.Planning.Bindings.IBinding>.QuickSort(int[] map, int left, int right)
System.Core.dll!System.Linq.EnumerableSorter<Ninject.Planning.Bindings.IBinding>.QuickSort(int[] map, int left, int right)
System.Core.dll!System.Linq.EnumerableSorter<Ninject.Planning.Bindings.IBinding>.QuickSort(int[] map, int left, int right)
System.Core.dll!System.Linq.EnumerableSorter<Ninject.Planning.Bindings.IBinding>.QuickSort(int[] map, int left, int right)
System.Core.dll!System.Linq.EnumerableSorter<Ninject.Planning.Bindings.IBinding>.QuickSort(int[] map, int left, int right)
System.Core.dll!System.Linq.EnumerableSorter<Ninject.Planning.Bindings.IBinding>.QuickSort(int[] map, int left, int right)
System.Core.dll!System.Linq.EnumerableSorter<Ninject.Planning.Bindings.IBinding>.QuickSort(int[] map, int left, int right)
System.Core.dll!System.Linq.EnumerableSorter<Ninject.Planning.Bindings.IBinding>.QuickSort(int[] map, int left, int right)
System.Core.dll!System.Linq.EnumerableSorter<Ninject.Planning.Bindings.IBinding>.QuickSort(int[] map, int left, int right)
System.Core.dll!System.Linq.EnumerableSorter<System.__Canon>.Sort(System.__Canon[] elements, int count)
System.Core.dll!System.Linq.OrderedEnumerable<Ninject.Planning.Bindings.IBinding>.GetEnumerator()
mscorlib.dll!System.Collections.Generic.List<Ninject.Planning.Bindings.IBinding>.List(System.Collections.Generic.IEnumerable<Ninject.Planning.Bindings.IBinding> collection)
System.Core.dll!System.Linq.Enumerable.ToList<Ninject.Planning.Bindings.IBinding>(System.Collections.Generic.IEnumerable<Ninject.Planning.Bindings.IBinding> source)
Ninject.dll!Ninject.KernelBase.GetBindings(System.Type service)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request)
Ninject.dll!Ninject.KernelBase.Resolve(Ninject.Activation.IRequest request, bool handleMissingBindings)

scott-xu added a commit that referenced this issue May 27, 2022
@scott-xu
Copy link
Member

Ninject 3.3.6 is released and the issue is fixed.

scott-xu added a commit that referenced this issue May 27, 2022
@scott-xu scott-xu added the Bug label May 29, 2022
glenkeane-94 added a commit to glenkeane-94/Nin-ject that referenced this issue Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants