Спасибо за ответ, Крис,
Я также получаю сообщение об ошибке при создании новых интеллектуальных деталей с настройкой EventPublication.
ОСНОВНАЯ ФОРМА
RootWorkItem.SmartParts.AddNew(Of ViewLogon)()
<EventSubscription(EventNames.Navigate, ThreadOption.UserInterface)> _
Public Sub NavigateSmartPart(ByVal sender As Object, ByVal e As GenericEventArgs(Of String))
workspace.Show(RootWorkItem.SmartParts.Get(e.Value))
End Sub
NEWУМНАЯ ЧАСТЬ
<EventPublication(EventNames.Navigate)> _
Public Event NavigateToSmartPart As EventHandler(Of GenericEventArgs(Of String))
Выдает ошибку вызова цели (внутреннее исключение NullReferenceException) в приведенном ниже методе в строке else if (ctors.Count () == 1).
internal static object CreateObject(Type t, WorkItem root)
{
object instance = null;
// first check the cache
if(m_constructorCache.ContainsKey(t))
{
return CreateObjectFromCache(t, root);
}
ConstructorInfo ci;
if (t.IsInterface)
{
throw new IOCException(string.Format("Cannot create an instance of an interface class ({0}). Check your registration code.", t.Name));
}
// see if there is an injection ctor
var ctors = (from c in t.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
where c.IsPublic == true
&& c.GetCustomAttributes(typeof(InjectionConstructorAttribute), true).Count() > 0
select c);
if (ctors.Count() == 0)
{
// no injection ctor, get the default, parameterless ctor
var parameterlessCtors = (from c in t.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
where c.GetParameters().Length == 0
select c);
if (parameterlessCtors.Count() == 0)
{
throw new ArgumentException(string.Format("Type '{0}' has no public parameterless constructor or injection constructor.\r\nAre you missing the InjectionConstructor attribute?", t));
}
// create the object
ci = parameterlessCtors.First();
try
{
instance = ci.Invoke(null);
m_constructorCache.Add(t, new InjectionConstructor { CI = ci });
}
catch (TargetInvocationException ex)
{
throw ex.InnerException;
}
}
else if (ctors.Count() == 1)
{
// call the injection ctor
ci = ctors.First();
ParameterInfo[] paramList = ci.GetParameters();
object[] inputs = GetParameterObjectsForParameterList(paramList, root, t.Name);
try
{
instance = ci.Invoke(inputs);
m_constructorCache.Add(t, new InjectionConstructor { CI = ci, ParameterList = paramList });
}
catch (TargetInvocationException ex)
{
throw ex.InnerException;
}
}
else
{
throw new ArgumentException(string.Format("Type '{0}' has {1} defined injection constructors. Only one is allowed", t.Name, ctors.Count()));
}
// NOTE: we don't do injections here, as if the created object has a dependency that requires this instance it would fail becasue this instance is not yet in the item list.
return instance;
}
Стек вызовов
at OpenNETCF.IoC.ObjectFactory.AddCollectionEventHandlers[TKey,TItem](Object instance, IEnumerable`1 collection, PublicationDescriptor[] sourceEvents, SubscriptionDescriptor[] eventSinks)
at OpenNETCF.IoC.ObjectFactory.AddEventHandlers(Object instance, WorkItem root, Boolean walkUpToRoot)
at OpenNETCF.IoC.ObjectFactory.AddEventHandlers(Object instance, WorkItem root)
at OpenNETCF.IoC.ObjectFactory.DoInjections(Object instance, WorkItem root)
at OpenNETCF.IoC.ManagedObjectCollection`1.Add(ISmartPart item, String id, Boolean expectNullId)
at OpenNETCF.IoC.ManagedObjectCollection`1.AddNew(Type typeToBuild, String id, Boolean expectNullId, Boolean wrapDisposables)
at OpenNETCF.IoC.ManagedObjectCollection`1.AddNew(Type typeToBuild)
at OpenNETCF.IoC.ManagedObjectCollection`1.AddNew[TTypeToBuild]()
at GoodsInInspection.MainContainer..ctor()
at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo rtci, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
at OpenNETCF.IoC.ObjectFactory.CreateObject(Type t, WorkItem root)
at OpenNETCF.IoC.ManagedObjectCollection`1.AddNew(Type typeToBuild, String id, Boolean expectNullId, Boolean wrapDisposables)
at OpenNETCF.IoC.ManagedObjectCollection`1.AddNew(Type typeToBuild)
at OpenNETCF.IoC.ManagedObjectCollection`1.AddNew[TTypeToBuild]()
at OpenNETCF.IoC.UI.SmartClientApplication`1.Start(IModuleInfoStore store)
at OpenNETCF.IoC.UI.SmartClientApplication`1.Start()
at GoodsInInspection.Startup.Main()
Если я удаляю атрибут EventPublication из события, умная часть создается успешно.