public ApplicationView(string[] args)
{
InitializeComponent();
string configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.config");
FileInfo configFileInfo = new FileInfo(configFilePath);
XmlConfigurator.ConfigureAndWatch(configFileInfo);
IConfigurationSource configSource = ConfigurationManager.GetSection("ActiveRecord") as IConfigurationSource;
Assembly assembly = Assembly.Load("Danel.Nursing.Model");
ActiveRecordStarter.Initialize(assembly, configSource);
WindsorContainer windsorContainer = ApplicationUtils.GetWindsorContainer();
windsorContainer.Kernel.AddComponentInstance<ApplicationView>(this);
windsorContainer.Kernel.AddComponent(typeof(ApplicationController).Name, typeof(ApplicationController));
controller = windsorContainer.Resolve<ApplicationController>(); // exception is thrown here
OnApplicationLoad(args);
}
The stack trace is this:
Castle.MicroKernel.ComponentActivator.ComponentActivatorException
was unhandled
Message=”ComponentActivator: could not
instantiate
Danel.Nursing.Scheduling.Actions.DataServices.NurseAbsenceDataService”
Source=”Castle.MicroKernel”
StackTrace:
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstance(CreationContext
context, Object[] arguments, Type[]
signature)
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext
context)
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext
context)
at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext
context)
at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Resolve(CreationContext
context)
at Castle.MicroKernel.Lifestyle.SingletonLifestyleManager.Resolve(CreationContext
context)
at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext
context)
at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveServiceDependency(CreationContext
context, ComponentModel model,
DependencyModel dependency)
at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext
context, ISubDependencyResolver
parentResolver, ComponentModel model,
DependencyModel dependency)
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateConstructorArguments(ConstructorCandidate
constructor, CreationContext context,
Type[]& signature)
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext
context)
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext
context)
at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext
context)
at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Resolve(CreationContext
context)
at Castle.MicroKernel.Lifestyle.SingletonLifestyleManager.Resolve(CreationContext
context)
at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext
context)
at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveServiceDependency(CreationContext
context, ComponentModel model,
DependencyModel dependency)
at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext
context, ISubDependencyResolver
parentResolver, ComponentModel model,
DependencyModel dependency)
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateConstructorArguments(ConstructorCandidate
constructor, CreationContext context,
Type[]& signature)
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext
context)
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext
context)
at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext
context)
at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Resolve(CreationContext
context)
at Castle.MicroKernel.Lifestyle.SingletonLifestyleManager.Resolve(CreationContext
context)
at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext
context)
at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveServiceDependency(CreationContext
context, ComponentModel model,
DependencyModel dependency)
at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext
context, ISubDependencyResolver
parentResolver, ComponentModel model,
DependencyModel dependency)
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateConstructorArguments(ConstructorCandidate
constructor, CreationContext context,
Type[]& signature)
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext
context)
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext
context)
at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext
context)
at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Resolve(CreationContext
context)
at Castle.MicroKernel.Lifestyle.SingletonLifestyleManager.Resolve(CreationContext
context)
at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext
context)
at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler
handler, Type service, IDictionary
additionalArguments)
at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler
handler, Type service)
at Castle.MicroKernel.DefaultKernel.get_Item(Type
service)
at Castle.Windsor.WindsorContainer.Resolve(Type
service)
at Castle.Windsor.WindsorContainer.ResolveT
at Danel.Nursing.Scheduling.ApplicationView..ctor(String[]
args) in
E:\Agile\Scheduling\Danel.Nursing.Scheduling\ApplicationView.cs:line
65
at Danel.Nursing.Scheduling.Program.Main(String[]
args) in
E:\Agile\Scheduling\Danel.Nursing.Scheduling\Program.cs:line
24
at System.AppDomain._nExecuteAssembly(Assembly
assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String
assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback
callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
System.ArgumentNullException
Message=”Value cannot be null.\r\nParameter name: types”
Source=”mscorlib”
ParamName=”types”
StackTrace:
at System.Type.GetConstructor(BindingFlags
bindingAttr, Binder binder, Type[]
types, ParameterModifier[] modifiers)
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.FastCreateInstance(Type
implType, Object[] arguments, Type[]
signature)
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstance(CreationContext
context, Object[] arguments, Type[]
signature)
InnerException:
It actually says that the type that I’m trying to initialize does not exist, I think.
This is the concreate type that it complains about:
namespace Danel.Nursing.Scheduling.Actions.DataServices
{
using System;
using Helpers;
using Rhino.Commons;
using Danel.Nursing.Model;
using NHibernate.Expressions;
using System.Collections.Generic;
using DateUtil = Danel.Nursing.Scheduling.Actions.Helpers.DateUtil;
using Danel.Nursing.Scheduling.Actions.DataServices.Interfaces;
public class NurseAbsenceDataService : AbstractDataService<NurseAbsence>, INurseAbsenceDataService
{
NurseAbsenceDataService(IRepository<NurseAbsence> repository)
: base(repository)
{
}
//...
}
}
The AbstractDataService only holds the IRepository for now.
Anyone got an idea why the exception is thrown?
EDIT:
The problem lays here:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Danel.Nursing.Scheduling.Actions.Interfaces;
using Rhino.Commons;
using System.Reflection;
using Castle.Windsor;
namespace Danel.Nursing.Scheduling.Actions.Helpers
{
public class DataServicesInitiator : IDataServicesInitiator
{
public void AddToIocContainer(ref WindsorContainer windsorContainer)
{
if (windsorContainer.Kernel.HasComponent(typeof(IRepository<>)) == false)
windsorContainer.AddComponent(typeof(ARRepository<>).FullName, typeof(IRepository<>), typeof(ARRepository<>));
foreach (Type type in Assembly.Load("Danel.Nursing.Scheduling.Actions").GetTypes())
{
if (type == null)
continue;
if (type.Namespace != "Danel.Nursing.Scheduling.Actions.DataServices")
continue;
if (type.IsAbstract || type.IsInterface)
continue;
if (windsorContainer.Kernel.HasComponent(type.FullName))
continue;
if (type.GetInterfaces().Length == 0)
windsorContainer.AddComponent(type.FullName, type);
else
windsorContainer.AddComponent(type.FullName, type.GetInterfaces()[0], type);
}
}
}
}
For some reason type is null although GetTypes return no null types.
What does the inner exception say? It looks like the constructor for the type threw an exception or it was unable to properly call the constructor for some other reason…
Update
You can get everything – ActiveRecord, Windsor with MicroKernel, DynamicProxy and NHibernate
by downloading ActiveRecord package. It’s all there.
If you don’t want to update you may take alternative approach – write a custom Activator for this component (inherit from the default one and override the method which exposes the bug.)
This should be the safest workaround.