No Source Available Error With Ninject When Debugging Code

六月ゝ 毕业季﹏ 提交于 2019-12-09 01:35:10

问题


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?

Does anyone have any idea why this may be occuring?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/8506618/no-source-available-error-with-ninject-when-debugging-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!