'RavenReader.Web.Controllers.UserController' does not have a default constructor - asp.net-web-api

Here is my Error Message which is shown when I browse: ../api/User
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
Type 'RavenReader.Web.Controllers.UserController' does not have a default constructor
</ExceptionMessage>
<ExceptionType>System.ArgumentException</ExceptionType>
<StackTrace>
at System.Linq.Expressions.Expression.New(Type type) at System.Web.Http.Internal.TypeActivator.Create[TBase](Type instanceType) at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage request, Type controllerType, Func`1& activator) at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
</StackTrace>
</Error>
My Controller Classes are
public class BaseController : ApiController
{
private readonly ICookieStorageService _cookieStorageService;
public BaseController(ICookieStorageService cookieStorageService)
{
_cookieStorageService = cookieStorageService;
}
}
public class UserController : BaseController
{
private readonly RavenUserFacade _facade;
private readonly ICookieStorageService _cookieStorageService;
public UserController(ICookieStorageService cookieStorageService, RavenUserFacade facade):base(cookieStorageService)
{
_facade = facade;
}
// GET api/User
public IEnumerable<RavenUserView> Get()
{
var users = _facade.GetAllUser();
return users.RavenUsers;
}
..........................................
..........................................
}
According to http://www.peterprovost.org/blog/2012/06/19/adding-ninject-to-web-api/ this blog I organized my NinjectDependencyScope class, NinjectDependencyResolver class and NinjectWebCommon as follows:
public class NinjectDependencyScope : IDependencyScope
{
private IResolutionRoot resolver;
internal NinjectDependencyScope(IResolutionRoot resolver)
{
Contract.Assert(resolver != null);
this.resolver = resolver;
}
public void Dispose()
{
var disposable = resolver as IDisposable;
if (disposable != null)
disposable.Dispose();
resolver = null;
}
public object GetService(Type serviceType)
{
if (resolver == null)
throw new ObjectDisposedException("this", "This scope has already been disposed");
return resolver.TryGet(serviceType);
}
public IEnumerable<object> GetServices(Type serviceType)
{
if (resolver == null)
throw new ObjectDisposedException("this", "This scope has already been disposed");
return resolver.GetAll(serviceType);
}
}
public class NinjectDependencyResolver : NinjectDependencyScope, IDependencyResolver
{
private IKernel kernel;
public NinjectDependencyResolver(IKernel kernel)
: base(kernel)
{
this.kernel = kernel;
}
public IDependencyScope BeginScope()
{
return new NinjectDependencyScope(kernel.BeginBlock());
}
}
public static class NinjectWebCommon
{
private static readonly Bootstrapper bootstrapper = new Bootstrapper();
/// <summary>
/// Starts the application
/// </summary>
public static void Start()
{
DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
bootstrapper.Initialize(CreateKernel);
}
/// <summary>
/// Stops the application.
/// </summary>
public static void Stop()
{
bootstrapper.ShutDown();
}
/// <summary>
/// Creates the kernel that will manage your application.
/// </summary>
/// <returns>The created kernel.</returns>
public static IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
RegisterServices(kernel);
GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel);
return kernel;
}
/// <summary>
/// Load your modules or register your services here!
/// </summary>
/// <param name="kernel">The kernel.</param>
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<IDbFactory>().To<IDbFactory>().InSingletonScope();
kernel.Bind<IUnitOfWork>().To<EFUnitOfWork>();
kernel.Bind<IRavenUserRepository>().To<RavenUserRepository>();
kernel.Bind<IRavenUserFacade>().To<RavenUserFacade>();
kernel.Bind<ICookieStorageService>().To<CookieStorageService>();
kernel.Bind<ICacheStorage>().To<HttpContextCacheAdapter>();
}
}
I am using visual Studio 2013 Ninject For MVC-3

I am posting this answer in order to help you track down the root issue you are facing. It is not a solution but this is how I reproduced the exact same error you are having.
First of all, you should use a different implementation for the NinjectDependencyResolver. I've set this gist. The reason behind that is avoiding problem with scopes (specially singletons), which you can learn more about here.
Back to your problem, the error is in your bindings, somewhere. First, try removing the InSingletonScope from your IDbFactory. Then, try removing one dependency from your controller constructor and check if that works. Finally, strip out the base class and see if it works.
These steps are just to guide you track down the problem. I've replicated your scenario here and I couldn't face the same issue. My setup was like this:
public class BaseController : ApiController
{
protected readonly IService _service;
public BaseController(IService service)
{
_service = service;
}
}
public class ValuesController : BaseController
{
public ISomeOtherDependency Dependency { get; set; }
public ValuesController(IService service, ISomeOtherDependency dependency) : base(service)
{
Dependency = dependency;
}
// GET api/values/5
public string Get(int id)
{
return _service.CreatedAt.ToString("u");
}
}
public interface ISomeOtherDependency
{
}
public class ConcreteDependency : ISomeOtherDependency
{
}
public interface IService
{
DateTime CreatedAt { get; }
}
public class Service : IService
{
public Service()
{
CreatedAt = DateTime.Now;
}
public DateTime CreatedAt { get; private set; }
}
And my bindings:
kernel.Bind<IService>().To<Service>(); // If I comment this, I get the same exception.
kernel.Bind<ISomeOtherDependency>().To<ConcreteDependency>();
But by commenting out one of these bindings, I get the exact same error as you:
ValuesController' does not have a default constructor
I hope this gets you on the right track to fix your issue.

Thanks for your reply. I followed each your steps but same results here. Finally I debugged by bindings that belongs inside NinjectWebCommon.cs and I found a problem here. While debugging it shows me following problem:
Locating source for
Bootstrapper.cs not found
You need to find Bootstrapper.cs to view the source for the current call stack frame
'c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\Bootstrapper.cs'. Checksum: MD5 {13 3e b1 f3 ba a7 65 14 f6 dc 4d f1 dd aa 21 bf}
The file 'c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\Bootstrapper.cs' does not exist.
Looking in script documents for 'c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\Bootstrapper.cs'...
Looking in the projects for 'c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\Bootstrapper.cs'.
The file was not found in a project.
Looking in directory 'C:\Program Files\Microsoft Visual Studio 11.0\VC\crt\src\'...
Looking in directory 'C:\Program Files\Microsoft Visual Studio 11.0\VC\crt\src\vccorlib\'...
Looking in directory 'C:\Program Files\Microsoft Visual Studio 11.0\VC\atlmfc\src\mfc\'...
Looking in directory 'C:\Program Files\Microsoft Visual Studio 11.0\VC\atlmfc\src\atl\'...
Looking in directory 'C:\Program Files\Microsoft Visual Studio 11.0\VC\atlmfc\include'...
The debug source files settings for the active solution indicate that the debugger will not ask the user to find the file: c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\Bootstrapper.cs.
The debugger could not locate the source file 'c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\Bootstrapper.cs'.

Related

In AspNet Boilerplate DotNetCore Console App that uses a custom AppService it does not perform the dependency injection

I am trying to make a console app that uses a custom AppService by adapting from the example https://github.com/aspnetboilerplate/aspnetboilerplate-samples/blob/master/AbpEfConsoleApp/AbpEfConsoleApp/Program.cs
It works for me to call the service, but when I try to use a IRepository gives me the following error
Castle.MicroKernel.Handlers.HandlerException: 'Can't create component 'VCloud.Rtdm.CashAudit.TestManager' as it has dependencies to be satisfied.
It's as if I didn't have the IRepository registered.
Program.cs
class Program
{
static void Main(string[] args)
{
TestUserReferencedService();
}
/// <summary>
/// Prueba de USAR un servicio de aspnetzero referenciando al proyecto. Spoiler: No funciona
/// </summary>
static async void TestUserReferencedService()
{
Clock.Provider = ClockProviders.Utc;
Console.WriteLine("Starting");
//Bootstrapping ABP system
using (var bootstrapper = AbpBootstrapper.Create<VCloudConsoleApplicationModule>())
{
bootstrapper.IocManager
.IocContainer
.AddFacility<LoggingFacility>(f => f.UseAbpLog4Net().WithConfig("log4net.config"));
bootstrapper.Initialize();
//Getting a Tester object from DI and running it
using (var tester = bootstrapper.IocManager.ResolveAsDisposable<TestAppService>())
{
var x = (await tester.Object.TestCount());
} //Disposes tester and all it's dependencies
Console.WriteLine("Press enter to exit...");
Console.ReadLine();
}
}
}
VCloudConsoleApplicationModule.cs
[DependsOn(
typeof(VCloudApplicationSharedModule),
typeof(VCloudConsoleCoreModule),
typeof(AbpEntityFrameworkCoreModule),
typeof(AbpDapperModule),
typeof(AbpZeroCommonModule)
)]
public class VCloudConsoleApplicationModule : AbpModule
{
public override void PreInitialize()
{
//Adding authorization providers
Configuration.Authorization.Providers.Add<AppAuthorizationProvider>();
//Adding custom AutoMapper configuration
Configuration.Modules.AbpAutoMapper().Configurators.Add(CustomDtoMapper.CreateMappings);
Configuration.BackgroundJobs.IsJobExecutionEnabled = false;
}
public override void Initialize()
{
IocManager.RegisterAssemblyByConvention(typeof(VCloudConsoleApplicationModule).GetAssembly());
DapperExtensions.DapperExtensions.SetMappingAssemblies(new List<Assembly>
{typeof(VCloudConsoleApplicationModule).GetAssembly()});
DapperExtensions.DapperExtensions.SetMappingAssemblies(new List<Assembly>
{
typeof(VCloud.Dapper.Mappers.DapperMapper_RtdmOrder).GetAssembly(),
typeof(VCloud.Dapper.Mappers.DapperMapper_RtdmOrderItem).GetAssembly(),
typeof(VCloud.Dapper.Mappers.DapperMapper_RtdmCompany).GetAssembly(),
typeof(VCloud.Dapper.Mappers.DapperMapper_RtdmRestaurant).GetAssembly()
});
//DapperExtensions.DapperExtensions.Configure();
//Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true;
}
}
TestManager.cs
public class TestManager : VCloudDomainServiceBase, ITestManager
{
private IRepository<Invoice> _repository;
public TestManager(IRepository<Invoice> repository)
{
_repository = repository;
}
public async Task<int> GetCount()
{
return await _repository.CountAsync();
}
}
Your problem is not related to Dependeny Injection, the problem may be you forget to add the entity Invoice to the DbContext of your application in EntityFramework project.
Once you add it your problem will be solved.
public class VCloudApplicationDbContext : AbpZeroDbContext<Tenant, Role, User, VCloudApplicationDbContext>, IAbpPersistedGrantDbContext
{
public DbSet<Invoice> Invoice { get; set; }
}
I hope it could help you

Ninject InSingletonScope with Web Api RC

I'm having some difficulty using Ninject's InSingletonScope binding with Web Api RC. No matter how I create my binding, it looks like perhaps Web Api is handling scope/lifetime instead of Ninject.
I've tried a few variations on wiring up Ninject. The most common is identical to the answer here:
ASP.NET Web API binding with ninject
I've also tried this version:
http://www.peterprovost.org/blog/2012/06/19/adding-ninject-to-web-api/
In both, I'm literally creating an out of the box Web Api project, then adding the Ninject packages as described in either post. Finally, I'm adding the Resolver and Scope classes, such as this for the StackOverflow version:
public class NinjectDependencyScope : IDependencyScope
{
private IResolutionRoot resolver;
internal NinjectDependencyScope(IResolutionRoot resolver)
{
Contract.Assert(resolver != null);
this.resolver = resolver;
}
public void Dispose()
{
IDisposable disposable = resolver as IDisposable;
if (disposable != null)
disposable.Dispose();
resolver = null;
}
public object GetService(Type serviceType)
{
if (resolver == null)
throw new ObjectDisposedException("this", "This scope has already been disposed");
return resolver.TryGet(serviceType);
}
public IEnumerable<object> GetServices(Type serviceType)
{
if (resolver == null)
throw new ObjectDisposedException("this", "This scope has already been disposed");
return resolver.GetAll(serviceType);
}
}
and:
public class NinjectDependencyResolver : NinjectDependencyScope, IDependencyResolver
{
private IKernel kernel;
public NinjectDependencyResolver(IKernel kernel)
: base(kernel)
{
this.kernel = kernel;
}
public IDependencyScope BeginScope()
{
return new NinjectDependencyScope(kernel.BeginBlock());
}
}
Then, NinjectWebCommon looks like this:
using System.Web.Http;
using MvcApplication2.Controllers;
[assembly: WebActivator.PreApplicationStartMethod(typeof(MvcApplication2.App_Start.NinjectWebCommon), "Start")]
[assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(MvcApplication2.App_Start.NinjectWebCommon), "Stop")]
namespace MvcApplication2.App_Start
{
using System;
using System.Web;
using Microsoft.Web.Infrastructure.DynamicModuleHelper;
using Ninject;
using Ninject.Web.Common;
public static class NinjectWebCommon
{
private static readonly Bootstrapper bootstrapper = new Bootstrapper();
/// <summary>
/// Starts the application
/// </summary>
public static void Start()
{
DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
bootstrapper.Initialize(CreateKernel);
}
/// <summary>
/// Stops the application.
/// </summary>
public static void Stop()
{
bootstrapper.ShutDown();
}
/// <summary>
/// Creates the kernel that will manage your application.
/// </summary>
/// <returns>The created kernel.</returns>
private static IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
// Register Dependencies
RegisterServices(kernel);
// Set Web API Resolver
GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel);
return kernel;
}
/// <summary>
/// Load your modules or register your services here!
/// </summary>
/// <param name="kernel">The kernel.</param>
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<ILogger>().To<Logger>().InSingletonScope();
}
}
}
The ILogger and Logger objects don't do anything, but illustrate the issue. Logger does Debug.Writeline so that I can see when it was instantiated. And each refresh of the page shows that it's being refreshed per call, rather than the singleton I'd hoped for. Here is a controller using the Logger:
public class ValuesController : ApiController
{
private readonly ILogger _logger;
public ValuesController(ILogger logger)
{
_logger = logger;
_logger.Log("Logger created at " + System.DateTime.Now.ToLongTimeString());
}
// GET api/values
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
public string Get(int id)
{
return "value";
}
// POST api/values
public void Post(string value)
{
}
// PUT api/values/5
public void Put(int id, string value)
{
}
// DELETE api/values/5
public void Delete(int id)
{
}
}
When I put trace information into the creation of the kernel, it seems to show that the kernel is only created once. So... what am I not seeing? Why isn't the singleton persisted?
use
public IDependencyScope BeginScope()
{
return new NinjectDependencyScope(kernel);
}
and don't dispose the kernel in the NinjectDependencyScope
#Remo Gloor
When I run your code in InMemoryHost of WebAPI and run Integration tests everything works fine and I do have singleton.
If I run WebAPI solution inside VS Cassini web server first run is successful
and when I click refresh I receive exception :
Error loading Ninject component ICache
No such component has been registered in the kernel's component container.
If I return old code with BeginBlock it works in Cassini but IsSingleton not working anymore in integration tests.
Instead of not disposing the kernel (which will not call the internal dispose) you can simply implement your own singleton:
public static class NinjectSingletonExtension
{
public static CustomSingletonKernelModel<T> SingletonBind<T>(this IKernel i_KernelInstance)
{
return new CustomSingletonKernelModel<T>(i_KernelInstance);
}
}
public class CustomSingletonKernelModel<T>
{
private const string k_ConstantInjectionName = "Implementation";
private readonly IKernel _kernel;
private T _concreteInstance;
public CustomSingletonKernelModel(IKernel i_KernelInstance)
{
this._kernel = i_KernelInstance;
}
public IBindingInNamedWithOrOnSyntax<T> To<TImplement>(TImplement i_Constant = null) where TImplement : class, T
{
_kernel.Bind<T>().To<TImplement>().Named(k_ConstantInjectionName);
var toReturn =
_kernel.Bind<T>().ToMethod(x =>
{
if (i_Constant != null)
{
return i_Constant;
}
if (_concreteInstance == null)
{
_concreteInstance = _kernel.Get<T>(k_ConstantInjectionName);
}
return _concreteInstance;
}).When(x => true);
return toReturn;
}
}
And then simply use:
i_Kernel.SingletonBind<T>().To<TImplement>();
Rather then
i_Kernel.Bind<T>().To<TImplement>().InSingletonScope();
note: although it is only matters for the first request, this implementation is not thread safe.

Is it VS2010 designer bug? or what I have done wrong? Designer error: The method or operation is not implemented

Base user control BaseUserControl.cs
namespace BaseClass
{
public partial class BaseUserControl : UserControl
{
protected ResourceManager _translator = null;
public BaseUserControl()
{
InitializeComponent();
InitTranslation();
}
#if DEBUG
/// <summary>
/// Initialize translation component (ResourceManager)
/// </summary>
protected virtual void InitTranslation()
{
throw new NotImplementedException();
}
#else
public abstract void InitTranslation();
#endif
}
}
Implementation of base user control
namespace BaseClass
{
public class Implemented : BaseUserControl
{
public Implemented() : base()
{
}
protected virtual override void InitTranslation()
{
_translator = null; //null only for int this example otherwise initialize
}
}
}
The issue is that if you try to open Implemented class in the designer it gives an error "The method or operation is not implemented." and preventing that.
The idea was to force the implementaion of InitTraslation() in inherited class.
Stack info:
at BaseClass.BaseUserControl.InitTranslation() in C:\Users\XXX\Documents\Visual Studio 2010\Projects\BaseClass\BaseClass\BaseUserControl.cs:line 55
at BaseClass.BaseUserControl..ctor() in C:\Users\XXX\Documents\Visual Studio 2010\Projects\BaseClass\BaseClass\BaseUserControl.cs:line 22

Getting SNAP AOP Framework working with Ninject MVC 3

I want to try out so SOA style logging using Snap in my MVC3 application. I'm using Ninject for IoC so have installed Ninject.MVC and Snap.Ninject via Nuget all had a look at the sample code in GitHub for Snap.Ninject. I also read Getting SNAP(AOP), NInject and ASP.Net MVC 3 working together
which seems to be doing exactly what I want.
I've updated my NinjctMVC3.cs accordingly but when I add the interceptor attribute to my method, I get an object ref error from Snap AspectUtility. Here is my NinjectMVC3.cs
public static class NinjectMVC3 {
private static readonly Bootstrapper bootstrapper = new Bootstrapper();
/// <summary>
/// Starts the application
/// </summary>
public static void Start() {
DynamicModuleUtility.RegisterModule(typeof(OnePerRequestModule));
DynamicModuleUtility.RegisterModule(typeof(HttpApplicationInitializationModule));
bootstrapper.Initialize(CreateKernel);
}
/// <summary>
/// Stops the application.
/// </summary>
public static void Stop() {
bootstrapper.ShutDown();
}
/// <summary>
/// Creates the kernel that will manage your application.
/// </summary>
/// <returns>The created kernel.</returns>
private static IKernel CreateKernel() {
//var kernel = new StandardKernel();
NinjectAopConfiguration.NinjectAopConfigure();
var kernel = NinjectAopConfiguration._container.Kernel;
RegisterServices(kernel);
return kernel;
}
/// <summary>
/// Load your modules or register your services here!
/// </summary>
/// <param name="kernel">The kernel.</param>
private static void RegisterServices(IKernel kernel) {
kernel.Bind<ILogger>().To<NLogger>()
.WithConstructorArgument("currentClassName", x => x.Request.ParentContext.Request.Service.FullName); ;
kernel.Bind<ISomeDataFactory>().To<SomeDataFactory>();
}
}
public static class NinjectAopConfiguration {
public readonly static NinjectAspectContainer _container;
static NinjectAopConfiguration() {
_container = new NinjectAspectContainer();
}
public static void NinjectAopConfigure() {
SnapConfiguration.For(_container).Configure(c => {
c.IncludeNamespace("TestAopLogging.Model.*");
c.Bind<MyMethodInterceptor>().To<MyInterceptorAttribute>();
});
}
}
public class MyMethodInterceptor : MethodInterceptor {
public override void InterceptMethod(Castle.DynamicProxy.IInvocation invocation, MethodBase method, System.Attribute attribute) {
var logger = new NLogger(method.DeclaringType.ToString());
logger.LogInfo("Hello AOP Logger. Your method (" + method.Name + ") has been intercepted");
invocation.Proceed();
}
public override void BeforeInvocation() {
var logger = new NLogger("How do I work out what class I'm in?");
base.BeforeInvocation();
}
public override void AfterInvocation() {
var logger = new NLogger("How do I work out what class I'm in?");
logger.LogInfo("Hello AOP Logger. After Invocation");
base.AfterInvocation();
}
}
public class MyInterceptorAttribute : MethodInterceptAttribute { }
And the controller
public class HomeController : Controller
{
private ILogger _logger;
private ISomeDataFactory _someDataFactory;
public HomeController(ILogger logger, ISomeDataFactory someDataFactory) {
_logger = logger;
_someDataFactory = someDataFactory;
}
public ActionResult Index()
{
_logger.LogInfo("I've hit the index action");
_someDataFactory.GetStuffAndLogTheOldWay();
_someDataFactory.GetStuffAndLogUsingAOP();
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View();
}
public ActionResult About()
{
return View();
}
}
and the factory class with the method with the intercept attribute
public interface ISomeDataFactory {
string GetStuffAndLogTheOldWay();
string GetStuffAndLogUsingAOP();
}
public class SomeDataFactory : ISomeDataFactory {
private ILogger _logger;
public SomeDataFactory(ILogger logger) {
_logger = logger;
}
public string GetStuffAndLogTheOldWay() {
_logger.LogInfo(MethodBase.GetCurrentMethod().Name + " was called");
return "I called GetStuffAndLogTheOldWay";
}
[MyInterceptor] // If I comment this out, then all is good
public string GetStuffAndLogUsingAOP() {
return "I called GetStuffAndLogUsingAOP";
}
}
and this results in the following exception
[NullReferenceException: Object reference not set to an instance of an object.]
Snap.AspectUtility.CreateProxy(Type interfaceType, Object instanceToWrap, IInterceptor[] interceptors) +29
Snap.AspectUtility.CreatePseudoProxy(IMasterProxy proxy, Type interfaceType, Object instanceToWrap) +184
Snap.Ninject.AspectProxyActivationStrategy.Activate(IContext context, InstanceReference reference) +376
Ninject.Activation.<>c__DisplayClass2.b__0(IActivationStrategy s) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Activation\Pipeline.cs:58
Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map(IEnumerable1 series, Action1 action) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Infrastructure\Language\ExtensionsForIEnumerableOfT.cs:23
Ninject.Activation.Pipeline.Activate(IContext context, InstanceReference reference) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Activation\Pipeline.cs:58
Ninject.Activation.Context.Resolve() in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Activation\Context.cs:182
Ninject.KernelBase.b__7(IContext context) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\KernelBase.cs:375
System.Linq.<>c__DisplayClass123.<CombineSelectors>b__11(TSource x) +32
System.Linq.WhereSelectEnumerableIterator2.MoveNext() +151
System.Linq.Enumerable.SingleOrDefault(IEnumerable1 source) +4178557
Ninject.Planning.Targets.Target1.GetValue(Type service, IContext parent) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Planning\Targets\Target.cs:179
Ninject.Planning.Targets.Target1.ResolveWithin(IContext parent) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Planning\Targets\Target.cs:147
Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:97
Ninject.Activation.Providers.<>c__DisplayClass2.<Create>b__1(ITarget target) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:81
System.Linq.WhereSelectArrayIterator2.MoveNext() +85
System.Linq.Buffer1..ctor(IEnumerable1 source) +325
System.Linq.Enumerable.ToArray(IEnumerable1 source) +78
Ninject.Activation.Providers.StandardProvider.Create(IContext context) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:81
Ninject.Activation.Context.Resolve() in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Activation\Context.cs:157
Ninject.KernelBase.<Resolve>b__7(IContext context) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\KernelBase.cs:375
System.Linq.<>c__DisplayClass123.b__11(TSource x) +32
System.Linq.WhereSelectEnumerableIterator2.MoveNext() +151
System.Linq.Enumerable.SingleOrDefault(IEnumerable1 source) +4178557
Ninject.Web.Mvc.NinjectDependencyResolver.GetService(Type serviceType) in c:\Projects\Ninject\Maintenance2.2\ninject.web.mvc\mvc3\src\Ninject.Web.Mvc\NinjectDependencyResolver.cs:56
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +51
Thanks in advance. I want a working demo of it failing then let me know.
Thanks to Tyler Brinks for spotting my typo!
Update the namespace reference to
c.IncludeNamespace("TestAopLogging.Models.*");
and all is well.
Hope someone finds this useful.

Custom Work Item Control not working in Visual Studio 2015 TFS 2013

I have a simple custom work item control that works flawlessly in VS 2013. I recently installed VS 2015 on my Windows 10 box and the control throws an error like so:
TF400939: The custom control type 'TimSheetsControl.WITimeSheetControl' does not implement the IWorkItemControl interface or is compiled for a different version of Visual Studio.
This is frustrating because the control does implement IWorkItemControl Interface. Also compiling to a version of Visual Studio doesn't seem to be a thing, at least as far as I understand it.
I tried to create a very simple control (just a ComboBox on a screen) to do some testing and I got exactly the same error.
I guess I have a couple questions:
Should I be doing this type of custom control in Visual Studio anymore? Or should I be creating web controls to replace what was once done in Visual Studio.
Is there something I'm doing terribly wrong which is causing this to fail?
The very simple control code I created is below, I'm happy to answer questions about my environment if that information is useful.
Thanks for your time and attention.
UserControl Code Behind (WITimeSheetControl):
namespace TimSheetsControl
{
public partial class WITimeSheetControl : UserControl, IWorkItemControl
{
private object WorkItemDataSource;
protected IServiceProvider ServiceProvider = null;
public WITimeSheetControl()
{
InitializeComponent();
}
public StringDictionary Properties{get; set;}
public bool ReadOnly { get; set; }
public object WorkItemDatasource
{
get
{
return WorkItemDataSource;
}
set
{
WorkItemDataSource = value;
}
}
public string WorkItemFieldName { get; set; }
public event EventHandler AfterUpdateDatasource;
public event EventHandler BeforeUpdateDatasource;
public void Clear()
{
}
public void FlushToDatasource()
{
}
public void InvalidateDatasource()
{
if (string.IsNullOrEmpty(WorkItemFieldName))
{
throw new ArgumentNullException("The fieldname property for the WITimeSheetControl is not set.");
}
cmbPosition.SelectedIndex = -1;
}
public void SetSite(IServiceProvider serviceProvider)
{
ServiceProvider = serviceProvider;
}
}
}
UserControl Designer Code:
namespace TimSheetsControl
{
partial class WITimeSheetControl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.cmbPosition = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// cmbPosition
//
this.cmbPosition.DropDownWidth = 145;
this.cmbPosition.FormattingEnabled = true;
this.cmbPosition.Items.AddRange(new object[] {
"Business Analyst",
"Programmer"});
this.cmbPosition.Location = new System.Drawing.Point(139, 23);
this.cmbPosition.MaximumSize = new System.Drawing.Size(165, 0);
this.cmbPosition.Name = "cmbPosition";
this.cmbPosition.Size = new System.Drawing.Size(151, 21);
this.cmbPosition.TabIndex = 0;
//
// WITimeSheetControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.cmbPosition);
this.Name = "WITimeSheetControl";
this.Size = new System.Drawing.Size(1219, 565);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ComboBox cmbPosition;
}
}
wicc:
<?xml version="1.0" encoding="utf-8" ?>
<CustomControl xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Assembly>TimSheetsControl.dll</Assembly>
<FullClassName>TimSheetsControl.WITimeSheetControl</FullClassName>
</CustomControl>
You need to compile a version of your custom control that targets the TFS 2015 binaries in order for your control to load in VS 2015.

Resources