2

I'm trying to change the container to DryIOC of a Xamarin.Forms + Prism app. Visual studio is compiling and starting the app without errors, but when the app starts it doesn't fire App.OnInitialized method keeping the app on a blank screen.

What did I do?

  1. Removed Prism.Unity, Unity and Microsoft related packages from the Android and Shared projects
  2. Added DryIoc.dll (v2.10.7) and Prism.DryIoc.Forms (v6.3.0.1) packages to Android and Shared projects
  3. Changed prism xmlns in App.xaml pointing to:

    xmlns:prism="clr-namespace:Prism.DryIoc;assembly=Prism.DryIoc.Forms"

  4. Changed the AndroidInitializer class in MainActivity.cs to:

    public class AndroidInitializer : IPlatformInitializer { public void RegisterTypes(IContainer container) {} }

I created a blank app using the Prism DryIoC template and it works fine. Also, I compared the App.xaml, App.xaml.cs and MainActivity.cs files with those in my project and everything is OK.

What else can I do?

Cleyton T.
  • 231
  • 3
  • 12
  • I don't think swapping out a few assemblies in the current solutions is going to cut it. You probably want to start with a blank app using Prism DryIoc, and start copying your code/assemblies into that. – R. Richards May 16 '17 at 21:38
  • Hi @R.Richards, thanks. I thought about this option too but why removing the old packages do not work? It doesn't make sense to me. Wouldn't it be the right thing to do? – Cleyton T. May 16 '17 at 21:45
  • Ideally, yes, that should work. I can't explain why it doesn't. Something (obviously) isn't quite right. Do you get any errors at all? I fear you could spend more time chasing this down rather than copying things over and getting it working. Sorry I can't be of more help. – R. Richards May 16 '17 at 21:57
  • Yes you right. I already wasted a good time investigating this. I'll create a new project. Thanks man – Cleyton T. May 16 '17 at 21:59

2 Answers2

6

If you're converting over you'll need to do the following:

1) Remove the following three packages - Prism.Unity.Forms - Unity - CommonServiceLocator

2) Update the xml namespace to clr-namespace:Prism.DryIoc;assembly=Prism.DryIoc.Forms in your App.xaml

3) Remove the Unity namespaces from your App.xaml.cs and replace them with Prism.DryIoc and DryIoc. Do the same in any IPlatformInitializer implementations, also changing IUnityContainer to IContainer

4) Update any service registrations since the signatures do not match between Unity and DryIoc.

5) Update any services or anything you specifically have that may directly use IUnityContainer to use IContainer.

6) Delete your obj and bin folders, clean and rebuild.

If you run into any trouble you can compare your project to either the Hamburger Menu or Tabbed Navigation samples.

UPDATE Starting in Prism 7.2 the XML Namespace that is recommended for use is simply http://prismlibrary.com this will replace any clr-namespace declaration that you may have had previously and will work regardless of whether you are using an official Prism package or one of the Extended versions of Prism.

Dan Siegel
  • 5,724
  • 2
  • 14
  • 28
  • Hi Dan! Pretty much the steps that I did, the only difference that I left the CommonServiceLocator. I remove it, double check it and replay all steps but same result: A blank screen. The App.OnInitialized method is not being called. – Cleyton T. May 16 '17 at 22:34
  • Also make sure you uninstall the app from your emulator before running it again. –  May 16 '17 at 22:34
  • Only reason that wouldn't work is an artifact in the build system. If you've done all of that, there isn't much more advice I could give you without seeing everything. – Dan Siegel May 16 '17 at 22:38
  • Yeah Dan. I'm noticing strange behaviors on VS 2017 v15.2, like intermittent errors on build. e.g. `Could not copy "obj\Debug\blabla.dll" to "bin\Debug\blabla.dll".` I'm going to create a new project with DryIoc template and transfer all my code to it. – Cleyton T. May 16 '17 at 22:57
  • I created a new project from DryIoc template, moved all my code and it worked! But now I got an error with Prism/DryIoc. I'll post an issue in the github – Cleyton T. May 17 '17 at 01:04
  • Worked for me. This answer is the most relevant one as it addresses the question - "Migrate from Unity to DryLoc". – Rahatur Dec 26 '19 at 14:52
2

What worked for me was creating a new project using Prism DryIoC template and moving all my code it.

Cleyton T.
  • 231
  • 3
  • 12