0
votes

I'm using the catel 4 pre-release, just trying to change my user control into a catel usercontrol, but for some reason catel is unable to pass the catel base constructor and throw this TypeNotRegisteredException.. can someone please tell me what I'm missing or doing wrong by locking at the call stack ?

    Catel.Core!Catel.IoC.TypeNotRegisteredException.TypeNotRegisteredException(System.Type requestedType = {System.RuntimeType}) Line 22    C#
Catel.Core!Catel.IoC.ServiceLocator.ThrowTypeNotRegisteredException(System.Type type = {System.RuntimeType}) Line 849 + 0x19 bytes  C#
Catel.Core!Catel.IoC.ServiceLocator.CreateServiceInstance(Catel.IoC.ServiceLocatorRegistration registration = {System.RuntimeType} => {System.RuntimeType} (Singleton)) Line 805    C#
Catel.Core!Catel.IoC.ServiceLocator.RegisterType.AnonymousMethod__10(Catel.IoC.ServiceLocatorRegistration x = {System.RuntimeType} => {System.RuntimeType} (Singleton)) Line 729 + 0x1c bytes   C#
Catel.Core!Catel.IoC.ServiceLocator.ResolveTypeFromKnownContainer(System.Type serviceType = {System.RuntimeType}, object tag = null) Line 775 + 0x23 bytes  C#
Catel.Core!Catel.IoC.ServiceLocator.ResolveType(System.Type serviceType = {System.RuntimeType}, object tag = null) Line 444 + 0x13 bytes    C#
Catel.Core!Catel.IoC.CatelDependencyResolver.Resolve(System.Type type = {System.RuntimeType}, object tag = null) Line 82 + 0x18 bytes   C#
Catel.Core!Catel.IoC.DependencyResolverExtensions.Resolve<Catel.MVVM.IViewModelFactory>(Catel.IoC.IDependencyResolver dependencyResolver = {Catel.IoC.CatelDependencyResolver}, object tag = null) Line 43 + 0x59 bytes C#
Catel.MVVM!Catel.MVVM.Providers.LogicBase.LogicBase() Line 121 + 0x10 bytes C#
[Managed to Native Transition]  
Catel.MVVM!Catel.MVVM.Providers.UserControlLogic.UserControlLogic(Catel.MVVM.Views.IView targetView = {MyApp.Views.MainPage}, System.Type viewModelType = null, Catel.MVVM.IViewModel viewModel = null) Line 91 C#
Catel.MVVM!Catel.Windows.Controls.UserControl.UserControl(Catel.MVVM.IViewModel viewModel = null) Line 77 + 0x26 bytes  C#
Catel.MVVM!Catel.Windows.Controls.UserControl.UserControl() Line 64 C#
MyApp!MyApp.Views.MainPage.MainPage() Line 23 + 0x9 bytes   C#

(I'm keeping the debug session open so I can provide any other details or params needed)

Thanks in advance

p.s. i have one more question if I may : what is the git branch name of the catel 4 pre-release beta that I pulled from nuget..(I can't find any name that resemble to that version, master is 3.9 and develop code seem a bit not aligned to the pdb pulled .. More Here about I set the debug to work for me)

new

@geert

The requestedType is Catel.MVVM.IViewModelFactory . (I can't seem to make anything out of that.) going back in the stack to the frame of CreateServiceInstance

 private object CreateServiceInstance(ServiceLocatorRegistration registration)
{
    object instance = TypeFactory.CreateInstance(registration.ImplementingType);//ImplementingType = {MyApp.CustomViewModelFactory}       
    if (instance == null) //instance is null in this case      
    {
       ThrowTypeNotRegisteredException(registration.DeclaringType);
    }
... 

as written above (in-line) the TypeFactory.CreateInstance gets called with ImplementingType = {MyApp.CustomViewModelFactory} but returns null (instance)..

I'm calling

serviceLocator.RegisterType< IViewModelFactory, CustomViewModelFactory>();
in my application_startup, and here is my implementation.. but I can't seem to make something out of all of this, what I am doing wrong? please help (could this be a bug ?)
   public class CustomViewModelFactory : ViewModelFactory
{
    private readonly ServiceProviderBase _sp;
    CustomViewModelFactory(ITypeFactory typeFactory):base(typeFactory)
    {
        _sp = ServiceProviderBase.Instance;
    }

    public override IViewModel CreateViewModel(Type viewModelType, object dataContext)
    {
        // add here any ViewModel that need some special init params
        if (viewModelType == typeof(MySpecialViewModel))
        {
            // Use custom constructor with dependency injection
            return new MySpecialViewModel(_sp.PageConductor, _sp.MySpecialDataService);
        }
        // Fall back to default behavior
        return base.CreateViewModel(viewModelType, dataContext);
    }
}

}

p.s.
I have : LogManager.AddDebugListener(); ( + LogManager.IsDebugEnabled = true;) but I don't see any logging of catel in my output window (vs2012+vs2010)

another thing.. "stepping into" from UserControl.. into UserControlLogic:base..- just jumps ""directly"" to that exception..but the call stack is what written above (am I missing too much sleeping hours %-)

1

1 Answers

0
votes

As You can see it throws a TypeNotRegisteredException. This exception has a property that explains what type is missing. All errors caused by cartel contain a logical explanation why it is throwing.

Catel follows GitFlow, so the nightly builds are built using the develop branch.