MVVM Light in a Windows Store App + Portable Class Library environment doesn't compile

Feb 28, 2013 at 3:54 PM
Edited Feb 28, 2013 at 4:32 PM
Hello,

I'm just about to get started with a Windows Store App, which is intended to use a Portable Class Library for it's ViewModels + Models.
After reading through a few tutorials I'm pretty sure I want to use MVVM Light as glue between my Windows Store App UI and my business logic.

Unfortunately I ran into a problem which is bothering me for days now - I'll try to explain it as good as possible:

I've got, as already stated, 2 projects:

1) The Windows Store App
2) The Portable Class Library

I've installed 'MvvmLight' (+ 'MvvmLightLibs') using NuGet in my Windows Store App project and 'Portable.MvvmLightLights' to my PCL project.

After doing that I moved the ViewModelLocator to a different folder (and namespace) in my Windows Store App. The MainViewModel also has been moved to my PCL, therefore I added a reference to the ViewModel's-Namespace in the ViewModelLocator.

However, now comes the real problem: When I try to compile the whole solution Visual Studio complains about the following:

Error 3 The type 'GalaSoft.MvvmLight.ViewModelBase' is defined in an assembly that is not referenced. You must add a reference to assembly 'GalaSoft.MvvmLight, Version=4.1.26.28028, Culture=neutral, PublicKeyToken=null'. <Path to Windows Store App>\Common\ViewModelLocator.cs 49

Adding a reference to the Portable.MvvmLight lib in the Store App causes ambiguous references, therefore more conflicts.

Am I right that the normal MVVM Light library is too new, which confuses VS when trying to find the ViewModelBase in the older Lib where the PCL-Version is based off?

[EDIT]
Store App Version: 4.1.27.22661
vs
PCL Version: 4.1.26.28028


Looking forward to your help.
Thanks for your awesome work you've done so far :)

Best regards,
Kai Eichinger
Mar 6, 2013 at 7:43 PM
Hi,

I have the same problem here as i would to share ViewModel inside a Portable Class Library and use it from a Win8 Store App and Windows Phone 8 application.

Did you get a solution for that ?

By the way, i have the same versions (4.1.27 for win8 & 4.1.26 for the portable)

Dominic
Mar 6, 2013 at 7:45 PM
Hi,

I have the same problem here as i would to share ViewModel inside a Portable Class Library and use it from a Win8 Store App and Windows Phone 8 application.

Did you get a solution for that ?

By the way, i have the same versions (4.1.27 for win8 & 4.1.26 for the portable)

Dominic
Mar 6, 2013 at 9:04 PM
Hey,

well, I've got a temporary workaround which seems to work for me. I removed the MVVM PCL version and added a reference to the normal MVVM Windows 8 DLLs ( GalaSoft.MvvmLight.Win8 and GalaSoft.MvvmLight.Extra.Win8). However, I'm not sure if everything's working if you use all features, though I'm kinda new to MVVM Light and didn't had the time to continue to work on my project.

Anyways, I can compile the whole solution without any problems if I add the reference to the normal Win8 version.

Cheers~
Mar 7, 2013 at 3:35 AM
I'm also attempting to use MVVM in a PCL to share between a Metro and windows phone application.

I created a blank solution then added a Pcl and a Metro app. Then used Nuget to add the MVVM Light PCL libs to the PCL project and the normal MVVM light nuget libraries to the win8 project. I get this error:

Error 2 Could not load file or assembly 'Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The assembly version has a public key token that does not match that of the request. (Exception from HRESULT: 0x80132001) C:\Users\Jeff\Documents\Visual Studio 2012\Projects\RightWeight\MvvmLightTest.Win8\App.xaml 14 13 MvvmLightTest.Win8

I've tried this with blank win8 project and manually nugetting in the libraries, and mvvm light win8 project.

The runtime version of the Microsoft.Practices.ServiceLocation is v4.0.30319 in the PCL.
Mar 11, 2013 at 2:47 AM
Same issue here, the pcl version says it's 4.1.27.1 when you select in nugget, but the binaries are version 4.1.26 that are actually installed.

Any help anyone?
Coordinator
Mar 12, 2013 at 2:09 PM
Hi,

Finally I can access the discussions again!

In order to use MVVM Light PCL, you need to use them across the board, or else the references don't match. So if you add a PCL with MVVM Light, you must then, in your app, unreferenced the MVVM Light assemblies and instead reference the PCL ones.

Hope it makes sense!

Cheers
Laurent
Mar 12, 2013 at 3:56 PM
Thanks for the reply !

I'm trying to move back the ViewModels into the PCL after removing the MVVM Light assemblies... do we need to move also the Vier

Do we have to also move the ViewModelLocator into the PCL or we have to keep in the app ?

Dominic
Coordinator
Mar 12, 2013 at 5:37 PM
Hi,

Typically I put some of the ViewModels in the PCL, some others in the app. I put the ViewModelLocator in the PCL.

Cheers
Laurent
Jun 10, 2013 at 11:36 AM
Edited Jun 10, 2013 at 11:38 AM
Hello Laurent,
i am developing win8 store app using mvvm light, i give references to GalaSoft assemblies in both View ( ProjectType- win8 app)and ViewModel (PCL) projects. When i build my app it give me 3136 errors regarding winmd. so i remove GalaSoft.MvvmLight.Win8 from app and left it only in PCL, now i am getting this error in View project.

The type 'GalaSoft.MvvmLight.ViewModelBase' is defined in an assembly that is not referenced. You must add a reference to assembly 'GalaSoft.MvvmLight.Win8, Version=4.1.24.17494, Culture=neutral, PublicKeyToken=7f0ea4153a3589fc'

What should i do to get work done now ?
Thanks in Advance.
Coordinator
Jun 10, 2013 at 1:20 PM
Hi,

You need to add a reference to the PCL MVVM Light assembly within your app too.

Cheers
Laurent
Jun 11, 2013 at 7:02 AM
Hi,

Thanks for a quick reply, i did what you say but now i am getting

Error2 Cannot resolve Assembly or Windows Metadata file 'GalaSoft.MvvmLight.Win8.dll'
Error 3 Type universe cannot resolve assembly: GalaSoft.MvvmLight.Win8, Version=4.0.23.35608, Culture=neutral, PublicKeyToken=7f0ea4153a3589fc.


i believe this is due to use of win8nl.dll for EventToCommandBehavior in app, i check your source code you also refer
<Reference Include="GalaSoft.MvvmLight.Win8">
  <HintPath>..\packages\MvvmLightLibs.4.1.27.0\lib\netcore45\GalaSoft.MvvmLight.Win8.dll</HintPath>
</Reference>
So please guide what should i do ? Do i need GalaSoft.MvvmLight.Win8.dll in app or MVVM libraries will do all the work, as when ever i refer GalaSoft.MvvmLight.Win8.dll it gives me 3136 errors regarding winmd?