grumpydev/TinyIoC

System.IO.FileNotFoundException with UWP and TinyIoC 1.3.0

kkohler2 opened this issue · 6 comments

  1. Create new Xamarin project - UWP
  2. Add TinyIoC 1.3.0 to all projects in solution
  3. Add TinyIoCContainer to App.xaml.cs:
    using TinyIoC;
    using Xamarin.Forms;
    using XFDependencyInjectionTest.Models;
    using XFDependencyInjectionTest.Services;
    using XFDependencyInjectionTest.Views;

namespace XFDependencyInjectionTest
{
public partial class App : Application
{
public static TinyIoCContainer tinyIoCContainer;

    public App()
    {
        InitializeComponent();
        tinyIoCContainer = new TinyIoCContainer();
        tinyIoCContainer.Register<IDataStore<Item>, MockDataStore>();
        DependencyService.Register<MockDataStore>();
        MainPage = new MainPage();
    }
}

}

  1. Inject object into constructor of viewmodel:
    public class AboutViewModel : BaseViewModel
    {
    public AboutViewModel(IDataStore dataStore) : base(dataStore)
    {
    Title = "About";
    OpenWebCommand = new Command(async () => await Browser.OpenAsync("https://xamarin.com"));
    }

  2. Build/run UWP project.

Error: : 'Could not load file or assembly 'XLabs.Ioc.TinyIOC, Version=2.0.5782.12282, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.'

Bin directory contains XLabs.Ioc.dll and XLabs.Ioc.TinyIOC.WP8.dll. Version numbers for DLLs do not match version in error.

You'll need to define compiler directives, did you do this? Also, we don't set the assembly version anywhere so I'd try and track that down. Are there any build errors or warnings?

Same project doesn't work on Android either.

Can you please answer my previous questions.

I'm closing this until my previous questions are answered.

I know this is closed, but I am getting a similar problem.
I am working on an existing Xamarin project and wanted to add TinyIoC.

The steps I have taken:

  1. Existing project builds and runs (UWP)
  2. Add XLabs.IoC.TinyIoC (2.0.5782) to Xamarin Forms & three UI Projects.
  3. UWP project still builds and runs.
  4. Add single line var ioc = TinyIoCContainer.Current; to App.xaml.cs.

When trying to run the UWP app I get the message:

Could not load file or assembly 'XLabs.Ioc.TinyIOC, Version=2.0.5782.12282, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

I have not defined a compiler directive. I am not sure what that means, and I can't find any reference to that in the documentation.

The package that you picked up was built with early mobile platforms in mind and not UWP. If you look at its content it supplies PCL target frameworks that a UWP build might ignore (this is a guess).

Unless you need that specific old build I would look either for a different package (I don't have recent experience with this) or embed the tiny IOC source yourself (what I've been doing for some time).