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?

Dangerous
  • 4,818
  • 3
  • 33
  • 48
  • 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. – Erik Funkenbusch Dec 14 '11 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. – Dangerous Dec 15 '11 at 09: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. – Dangerous Dec 15 '11 at 09:44

2 Answers2

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

Remo Gloor
  • 32,665
  • 4
  • 68
  • 98
  • I followed your suggestion but could not get it working. I followed the suggestion on the following link also (http://stackoverflow.com/questions/2806993/no-source-available) but still no luck. – Dangerous Dec 15 '11 at 09:21
  • 1
    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. – Remo Gloor Dec 15 '11 at 09:47
  • I realise now (since asking the question) that this is not an ninject related problem but thank you for your help. – Dangerous Dec 15 '11 at 09:51
  • thanks Remo, I deleted ninject.pdb and the problem is solved. – Agus Syahputra Feb 08 '12 at 04:45
  • I think that the pdb files should not be included on nuget.org in the first place. I have opened an issue [here](https://github.com/ninject/ninject/issues/62). – StriplingWarrior Jul 02 '12 at 18:50
  • For others with this problem, the answer on this question is what worked for me: http://stackoverflow.com/questions/10801385/step-into-is-suddenly-not-working-in-visual-studio – adam0101 Aug 23 '13 at 16:56
  • This problem happened for me again. It turns out it was because when we added a new project for our service layer (which used Ninject) the build configuration for the _project_ was **Release** even though the configuration for the _solution_ was **Debug**. We just had to change the projects in the Visual Studio Configuration Manager dialog and now we can step into code just fine :) – adam0101 Sep 12 '13 at 21:11
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.

Jason Down
  • 21,731
  • 12
  • 83
  • 117
TripleEmcoder
  • 641
  • 5
  • 8