Google Analytics

Showing posts with label Unity. Show all posts
Showing posts with label Unity. Show all posts

Thursday, February 23, 2012

Prism Module Loading "Incorrect Format"

We ran across this this morning where a colleague was trying to load a module she had built from a DirectoryModuleCatalog into the shell of our Prism application. She was getting an error that the module could not be loaded, an error which included "An attempt was made to load a program with an incorrect format." We stripped the module down to the bare bones, but still were getting the error. In fact, when we tried debugging, the debugger never even got into the constructor of the module. 


A little research suggested that maybe the Unity dlls being referenced were different, which wouldn't surprise me since VisualStudio seems to go out and add whatever dll might be registered that it thinks fits the bill when you load up a project that another developer had started. After checking and re-checking the references for both the shell and module projects, we determined that probably wasn't it.


Then I found a bit about the build configuration. Her plugin was being built with an X86 target platform and the shell was being built for 'Any CPU' on her x64 machine. Voila. She went into Properties > Build for the Module project and changed the target to x64 (interestingly Any CPU was not available, which is maybe another issue), and the module loads into the shell as expected.

Thursday, December 15, 2011

I am adding the module now to the shell. I'm looking at the UI Composition QuickStart in the guidance to get an idea of how to start. I want to have a main region and within that a tab region that I can add a tab to. Started by adding TabControl and TabItem template to the shell. Had to work out the fact that I didn't need the Silverlight adapter and other related markup. Added the module project as a simple class library and added the Views directory to it. Added the UserManagementModule class as a normal class. It implements IModule and its constructor takes a UnityContainer and RegionManager interfaces. In the Initialize() method we Register the UserManagement view with the tabRegion on the shell. So... we need to add the UserManagement View. We add that to the Views directory as a UserControl. I also just added a textBlock in the view to indicate that it is loaded. I had to explicitly override ConfigureModuleCatalog in the Bootstrapper and add the UserManagementModule to the catalog for now. Like I said before, I want to use the directory discovery method to get the modules, but we are taking baby steps here. So when I run this now an odd thing happens: I get a shell with two tabs. The first has no content. I think that it has to do with the fact that I am doing view injection rather than the view discovery of the QuickStart for the main region and I am getting the two methods crossed. The second tab has my content. It doesn't have the name on the tab, which is supposed to be bound to the View's ViewName property. Took me a few minutes to realize that I need to put that in the ViewModel object for the view. (Duh! Isn't that how all this is supposed to work in the first place?) So Next I will be adding the ViewModel for the UserManagement view, adding the ViewName property of that, and seeing if it gets displayed in my tab. The UserManagementModel gets added as a plain class that implements INotifyPropertyChanged, so it has a PropertyChanged event. The model is injected in the constructor of the view. Then we set the dataContext of the view to the model. This is a change from the MVP architecture we have used in the past where an interface to the view was injected into the constructor of a presenter and the view basically had no knowledge of its presenter. With MVVM the view will actively subscribe to events from the model and bind to its collections and commands. I'm wondering at this point if I should create an interface for the ViewModel, but I don't see why at the moment so leaving as is. WPF TabControl done differently than the Silverlight example in QuickStart, and that is what was giving me the two tabs and not correctly showing the view name on the tab as I wanted. I had to bind to Content.DataContext.ViewName rather than just ViewName as described in the QuickStart or DataContext.ViewName as some examples on the internets showed. Now I need to activate the tab. Hook up some dataService and bind users to a listControl. Add a second tab and probably localize region names.