2

I have used NuGet to install the latest version of Ninject (v2.2.1.4).

I have then created my own NinjectDependencyResolver (credit to Adam Freeman & Steve Sanderson):

public class NinjectDependencyResolver : IDependencyResolver
{
    private IKernel kernel;

    public NinjectDependencyResolver()
    {
        kernel = new StandardKernel();
        AddBindings();
    }

    public object GetService(Type serviceType)
    {
        return kernel.TryGet(serviceType);
    }

    public IEnumerable<object> GetServices(Type serviceType) {
        return kernel.GetAll(serviceType);
    }

    public IBindingToSyntax<T> Bind<T>()
    {
        return kernel.Bind<T>();
    }

    public IKernel Kernel
    {
         get { return kernel; }
    }

    private void AddBindings()
    {
        kernel.Bind<ITitleRepository>().To<TitleRepository>();
        kernel.Bind<IDayRepository>().To<DayRepository>();
        kernel.Bind<IMonthRepository>().To<MonthRepository>();
    }
}

And then registered the dependency resolver in the global.asax applcation startup:

    protected void Application_Start()
    {
        //...other code

        DependencyResolver.SetResolver(new NinjectDependencyResolver());
    }

I then have the following line in my code:

ITitleRepository titleRepository = (ITitleRepository)DependencyResolver.Current.GetService(typeof(ITitleRepository));

If I run the code through in debug mode it appears to work correctly, however, if I step into this code (line by line) then when it runs the kernel.TryGet(serviceType) the following error occurs:

No Source Available

Hopefully the image will be visible?

enter image description here

Does anyone have any idea why this may be occuring?

3
  • 2
    Why are you replacing the default dependency resolver? What is your reasoning? You don't seem to be doing anything that Ninject.MVC3 isn't doing, but in a less maintainable way. Why not just install Ninject.MVC3 via nuget and configure the NinjectMVC3.cs file, then you can update Ninject via Nuget easily and you don't have to fiddle with the global.asax or maintaining your custom dependency resolver. Commented Dec 14, 2011 at 17:33
  • @MystereMan From what I gather, by calling the .SetResolver() method, I am not replacing the default dependency resolver but instead am adding my own dependency resolver using ninject. If the GetService() method that I implement cannot resolve the dependency then it will return null and then fall back to the default implementation. Commented Dec 15, 2011 at 9:43
  • @MystereMan And my reasoning for using Ninject from nuget and not Ninject.MVC3 is simple - I followed the recipe for adding ninject from the book Pro ASP.NET MVC3 Framework and there is no mention of the Ninject.MVC3 package so I didn't realise it existed. I have added now removed my original implementation and switched to this new one so thankyou for the suggestion. However, my question still stands as I still get this error. Commented Dec 15, 2011 at 9:44

2 Answers 2

4

This happens because Visual Studio does not find the source code for Ninject.

Do one of the following:

  • Download the appropriate source code and point VS to it
  • Configure VS to use symbolsource.org as symbol server (Only for Ninject 3.0.0-rc3 and later)
  • Delete all the Ninject pdb's
  • Disable debuging of other then your code in the VS settings (Tools/Options/Debugging/Enable Just My Code)

See http://msdn.microsoft.com/en-us/library/3sehk0fb%28v=vs.100%29.aspx

Sign up to request clarification or add additional context in comments.

7 Comments

I followed your suggestion but could not get it working. I followed the suggestion on the following link also (stackoverflow.com/questions/2806993/no-source-available) but still no luck.
This is not a Ninject related problem but wrong usage of Visual Studio. So you may better ask a question about how to disable debugging of 3rd party libraries in visual studio. For me it always worked to check the option I mentioned above or to open the requested file. Probably deleting the Ninject pdbs will also do the trick.
I realise now (since asking the question) that this is not an ninject related problem but thank you for your help.
thanks Remo, I deleted ninject.pdb and the problem is solved.
I think that the pdb files should not be included on nuget.org in the first place. I have opened an issue here.
|
1

You should ask package maintainers to publish symbols, e.g. through SymbolSource. Then you'll be able to load them and step into Ninject source.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.