Can't resolve a service in the code behind

Topics: Feature requests
Feb 26, 2014 at 3:37 PM
Version 3.8.1
I have a service that is registered in my app.xmal.cs. When I try and access this services in the code behind of a Catel.Windows.Controls.UserControl, I get the error "the type 'x service' is not registered, not even in an external container". I don't know why I am getting this error.

App.xaml.cs - OnStartup method
            ServiceLocator.Default.RegisterType<IGraphicsService, GraphicsService>();
UserControl behind code
        private static readonly IGraphicsService GraphicsService = 

        public DockView()

            GraphicsService.SetObject(this.Graph, Enums.GraphObject.Main);
            GraphicsService.SetObject(this.IntermediateGraph, Enums.GraphObject.Intermediate);
Thanks in advance
Feb 26, 2014 at 4:04 PM
Make sure that you call the RegisterType before the MainWindow is created, which is probably the case here.
Feb 26, 2014 at 4:42 PM
I made sure that the MainWindow is created last, but still get the same error message.
Feb 26, 2014 at 4:50 PM
Please create a repro at the official issue tracker:
Feb 26, 2014 at 5:16 PM
It appears that even though the error message is showing up in the IDE, the service is being found correctly. Weird, seems to be an issue in the IDE not the in the code. Compiles and runs fine.
Feb 26, 2014 at 6:41 PM
That's because the designer is actually executing the code (and the services are not registered at design time). What you can do is initialize in the static constructor and before that, check Catel.Environment.IsInDesignMode.
Marked as answer by paco1863 on 2/26/2014 at 11:27 AM
Feb 26, 2014 at 7:28 PM