I Get an Exception with Cinh 2 and nhibernate 3

Feb 2, 2011 at 2:44 PM


My project has a references to nhibernate.dll v3.
When i call CinchBootStrapper.Initialise(new List<Assembly> { typeof(App).Assembly })
in my Application constructor , i receive this exception:

System.InvalidOperationException: PopupResolver is unable to ResolvePopupLookups based on current parameters ---&gt; System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Exception is throw by GetExport method invocate by PopupResolver class: 
IUIVisualizerService uiVisualizerService =   ViewModelRepository.Instance.Resolver.Container.GetExport<IUIVisualizerService>().Value;

When i dont use nhibernate.dll , everything works fine.

Coordinator
Feb 2, 2011 at 3:10 PM

Sorry to say I have absolutely no idea what that could be. But the work the Cinch bootstrapper is doing, is for convienance really, you could not call the boostrapper, and just add items to the IUIVisualizerService inside of it, by creating your own copy of the IUIVisualizerService where the code would be same as in CInch code base, but you would call it a new interface, so as not to confuse MEF when it resolves the service, and you would no longer be able to use the PopupNameToViewLookupKeyMetadataAttribute attributes on your popups as that is what the bootstrapper would be looking for, and as you would no longer be calling bootstrapper, there is no need for these on your views.

Then you would manually add the popups inside of your own IUIVisualizer implementation, something like this 

 

 

public WPFUIVisualizerService()
{
            _registeredWindows = new Dictionary<string, Type>();

            //register known windows
            Register("SomePopup", typeof(SomePopupWindow));
}

 

For the ViewResolver you can manually add items to it outside of using the bootstrapper like : 

ViewResolver.Register("SomeView", typeof(SomeViewWindow));

 

Bit of a faff I know, but thing is it works just fine for most users.

 

You know the basic idea behind the bootstrapper and workspaces and IUIVisualizer service right? I think if you do not get how that works, you will need to get to grips with that 1st.

 

The basic idea is that there are a couple of static dictionaries used, 

ViewResolver holds views that are created in response to WorkSpaceData string keys, and you can add stuff manually to this dictionary as shown above.

IUIVisualizer holds popup views that are created in response to IUIVisualizer Show() or ShowDialog() methods, and you can add stuff manually to this dictionary as shown above.

 

The bootstrapper is more of a helper than anything else, where it can go through your assembly looking for popups/views which are attributed where views attributed with 

ViewnameToViewLookupKeyMetadataAttribute will be automatically registered into the ViewResolver while views attributed up with PopupNameToViewLookupKeyMetadataAttribute will be automatically registered into the IUIVisualizer service. That is all the bootstrapper does, its for lazyiness really.

 

Feb 2, 2011 at 4:12 PM

I understant now with your help what bootstrapper do. 

But i think the problem is elsewhere. I   thought that bootstrapper help me with binding my view with viewmodel. Thank you much for explain that to me.

Now i dont use bootstrapper. And with nhibernate.dll binding doesnt work , and without it is working. No exception is thrown. I can send you a sample with a small project that demonstrate this.

Will you help me plz? Sorry with my mistakes with english language. 

Coordinator
Feb 2, 2011 at 4:24 PM

It would have to be a very small project (otherwise I will not have to time look at it), Also I can not promise anything at all my time is very limited, but you can send it to sacha[dot]barber[at]ttt[dot]co[dot]uk

Coordinator
Feb 2, 2011 at 4:24 PM

Please send as ZIP file (winzip file ONLY)

Feb 2, 2011 at 4:55 PM

You receive the project?

I try with WPF_Demo from source code. I add a reference to nhibernate.dll and the same think: doesnt working.

Coordinator
Feb 3, 2011 at 4:53 AM

I'll be back at work soon, so I'll see if I have anything then.

Coordinator
Feb 3, 2011 at 4:55 AM

You know one thing, why are you referencing NHibernate in the UI anyway?

 

That seems very odd to me, the ViewModels/UI should not know about NHibernate classes? The layer that talks to the database should know about NHibernate , but not the UI.

Coordinator
Feb 3, 2011 at 8:39 AM

Don't have anything yet

Feb 3, 2011 at 10:19 AM

I put nhibernate.dll in a another project library and references this by wpf layer.
The same thing is happening.  Its working at you?  i must develope a project and i
mush know if i can use this framework.

Coordinator
Feb 3, 2011 at 1:48 PM

What are you saying your tried nhibernate.dll  in another standard WPF project and you had issues, or you tried it within another CInch/Meffed based WPF app, and still had issues.

 

You know if you are just evaluating frameworks right now and Cinch is not working with NHibernate.dll, do not use Cinch and use another MVVM framework, I just don't have the time to look into this issue as fully as you seem to require.

 

I would be interested to know what it is though, still no project from you though, so I can't look at it.

Feb 3, 2011 at 2:22 PM

i send you the small project to sacha.barber@ttt.co.uk

Send me an email to geo_valy@yahoo.com so i can reply it.

Feb 3, 2011 at 2:32 PM

this is the exception when nhibernate.dll is refences by my project. Is thrown by mefedmvvm.wpf.dll.

class: MEFedMVVM.ViewModelLocator.MEFedMVVMExportProvider
method: IEnumerable<Export> GetExportsCore
code: var exports = _exportProvider.GetExports(definition, atomicComposition);

Loader exception:

{System.IO.FileNotFoundException: Could not load file or assembly 'Remotion.Data.Linq, Version=1.13.41.2, Culture=neutral, PublicKeyToken=cab60358ab4081ea' or one of its dependencies. The system cannot find the file specified.
File name: 'Remotion.Data.Linq, Version=1.13.41.2, Culture=neutral, PublicKeyToken=cab60358ab4081ea'

=== Pre-bind state information ===
LOG: User = SOFTINFO\valentinm
LOG: DisplayName = Remotion.Data.Linq, Version=1.13.41.2, Culture=neutral, PublicKeyToken=cab60358ab4081ea
 (Fully-specified)
LOG: Appbase = file:///C:/Users/valentinm.SOFTINFO/documents/visual studio 2010/Projects/IwLearningCourse/WpfIwLearning/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : NHibernate, Version=3.0.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\valentinm.SOFTINFO\documents\visual studio 2010\Projects\IwLearningCourse\WpfIwLearning\bin\Debug\WpfIwLearning.vshost.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Remotion.Data.Linq, Version=1.13.41.2, Culture=neutral, PublicKeyToken=cab60358ab4081ea
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
}

Feb 3, 2011 at 2:38 PM

So i found Remotion.Data.Linq.dll which is release with nhibernate 3 and include i my project.

Everithing is working now. Sorry for your time and thank you for your help. I will develop my project with cinh 2. Good day.

Coordinator
Feb 3, 2011 at 3:08 PM

Fair enough.