1

Closed

Type not found in cache error

description

I am running into the below error the first time my ViewModel is being instantiated by the SimpleIoC. I believe I have setup the container as it should be, but for some reason, I am still getting the below error. Any ideas or assistance would be very much appreciated.
Microsoft.Practices.ServiceLocation.ActivationException was unhandled by user code
  HResult=-2146233088
  Message=Type not found in cache: Windows.UI.Xaml.Controls.Frame.
  Source=GalaSoft.MvvmLight.Extras
  StackTrace:
       at GalaSoft.MvvmLight.Ioc.SimpleIoc.DoGetService(Type serviceType, String key) in c:\Users\Public\Downloads\CodePlex\MVVMLight\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Extras (NET35)\Ioc\SimpleIoc.cs:line 532
       at GalaSoft.MvvmLight.Ioc.SimpleIoc.GetService(Type serviceType) in c:\Users\Public\Downloads\CodePlex\MVVMLight\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Extras (NET35)\Ioc\SimpleIoc.cs:line 768
       at GalaSoft.MvvmLight.Ioc.SimpleIoc.MakeInstance[TClass]() in c:\Users\Public\Downloads\CodePlex\MVVMLight\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Extras (NET35)\Ioc\SimpleIoc.cs:line 708
  InnerException: 
Here are pieces of my code related to this:

ViewModelLocator.cs (Located in my Win8 project)
public class ViewModelLocator
    {
        /// <summary>
        /// Initializes a new instance of the ViewModelLocator class.
        /// </summary>
        public ViewModelLocator()
        {
            ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

            if (ViewModelBase.IsInDesignModeStatic)
            {
                // Create design time view services and models
                //SimpleIoc.Default.Register<IDataService, DesignDataService>();
            }
            else
            {
                // Create run time view services and models
                //SimpleIoc.Default.Register<IDataService, DataService>();
                SimpleIoc.Default.Register<INavigationService, NavigationService>();
                SimpleIoc.Default.Register<IParseService, ParseService>();
                SimpleIoc.Default.Register<IServiceHandler, ServiceHandler>();
            }

            SimpleIoc.Default.Register<MainViewModel>();
            SimpleIoc.Default.Register<ActionViewModel>();
        }

        public MainViewModel MainVM
        {
            get
            {
                return ServiceLocator.Current.GetInstance<MainViewModel>();
            }
        }

        public ActionViewModel ActionVM
        {
            get
            {
                return ServiceLocator.Current.GetInstance<ActionViewModel>();
            }
        }
        
        public static void Cleanup()
        {
            // TODO Clear the ViewModels
        }
    }
MainViewModel.cs Constructor
public class MainViewModel : ViewModelBase
    {
        #region Variables

        private readonly INavigationService _navigationService;
        private readonly IParseService _parseService;

        #endregion

        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(INavigationService navigationService, IParseService parseService)
        {
            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
            }
            else
            {
                _navigationService = navigationService;
                _parseService = parseService;
                BuildCommonData();
            }
        }
...
Closed Jun 25, 2013 at 5:19 PM by lbugnion
Closing this as "not an issue"

comments

congrats wrote Jun 25, 2013 at 1:26 PM

Hi,

From you provided error prompt, seems your code tries to do following task:
ServiceLocator.Current.GetInstance<Windows.UI.Xaml.Controls.Frame>();
but actually you never registed a Frame based class to the ioc container.

Hope it helps.

dolowoyo wrote Jun 25, 2013 at 3:15 PM

Hey there. Thanks for the response.

It turns out it was something else. I had the Frame object designed in my Navigation Service interface, which was in my Portable Class Library.

I just changed up my navigation svc methods a bit, and it helped resolve my issue.