2
votes

I'm posting this question so I can document the solution as I found it very tricky and time consuming to solve.

I'm using Laurent Bugnion's excellent MVVM Light Toolkit in a Silverlight 4 project and I'm using his ViewModelLocator pattern with the Microsoft.Practices.ServiceLocation.ServiceLocator to load design time models for Blendability. Initially loading the Views up in Expression Blend 4 was working and the design time data binding was great. This stopped working at some point without any error message in Blend at all.

I used Visual Studio 2010 SP1 to attach to Blend.exe to debug the issue. The EntryPointNotFoundException (Entry point was not found) exception was being thrown at this line of code:

return ServiceLocator.Current.GetInstance<ExampleViewModel>();

Strangely enough, I was able to load the same View in the Visual Studio XAML Designer successfully with my design time data binding working correctly. I used another Visual Studio instance to attach the debugger to the Visual Studio instance hosting the XAML Designer and was able to confirm that the ServiceLocator call was executing successfully.

The exception detail (stack trace, InnerExcetion etc) did not give me any further clue to the problem and various Internet searches for the unhelpful error emssage failed to shed any further light.

I eventually got lucky by using the Visual Studio Immediate Window to execute part of the line of code that was causing the problem and got a much better error message:

?ServiceLocator.Current

The type 'Microsoft.Practices.ServiceLocation.ServiceLocator' exists in both 'Microsoft.Practices.ServiceLocation.dll' and 'Microsoft.Practices.ServiceLocation.dll'

Comparing the changeset to previously working code I noticed that I had added a reference to GalaSoft.MvvmLight.Extras.SL4 in a separate Unit Test Framework for Silverlight project (which references the UI project). This test project was referencing the assembly from C:\Program Files (x86)\Laurent Bugnion (GalaSoft)\Mvvm Light Toolkit\Binaries\Silverlight4 where as the UI project was referencing it from ..\packages\MvvmLightLibsPreview.4.0.0\lib\SL4. I had used the nuget package MvvmLightLibsPreview to add MVVM Light to the client project.

The Blend Results - Errors and Output Windows did not show any error message at any point. Obviously there is no real answers required unless there are some Blend trouble shooting techniques which would have helped my figure out the problem faster.

3
Very interesting. I don't use nuget because it's not quite there yet in terms of maturity and this example shows it. The only way for nuget to work successfully is for it to take over the whole reference adding mechanism for every project in your solution. Until that happens, it's too easy to choose the wrong package and hose something. It's coming along though -- they used to not have solution level packages and that's a step in the right direction.Mike Post
@mikepost I'm not sure this is a nuget problem as such. Nuget was used on the Client UI project initially and it was when I later added a Unit Test Silverlight Project that I manually referenced the different assemblies. If I had used Add-Package on this Unit test project as well, the problem wouldn't have occurred. An easily made user error but still user error. The frustrating part was the lack of good error messages. I also only put 2 and 2 together later and realised this same problem was causing issues with my unit tests but with a different obscure error message.Martin Hollingsworth

3 Answers

1
votes

I had almost the same issue though my problem did not go away until I uninstalled MVVM Light using the Windows 7 control panel. The NuGet MVVM Light references were still in the project but now I can see the design time data. It was broken before.

I followed the advice on the MVVM Light web site and attached the Blend preview for Visual Studio 2012 and received the error that you mentioned above (EntryPointNotFoundException). I had no idea even then that I should try to remove two different versions of MVVM Light that were conflicting with each other.

0
votes

AS you would expect, changing the test project's MVVM Light assembly references to use the same nuget package versions used by the client UI Project fixes the problem. I've no idea why Visual Studio did not have a problem with two versions of the Microsoft.Practices.ServiceLocation.dll being referenced in the same way as Blend.

0
votes

I ended up trying to copy over the entire contents of the package that would come from NuGet into

C:\Program Files (x86)\Laurent Bugnion (GalaSoft)\Mvvm Light Toolkit\Binaries

That did not solve the problem. Since uninstalling MVVM Light took away other things such as snippets, I decided to go back and troubleshoot some more. I was not successful and could only find a rough temporary solution.

I tried comparing projects that would work and projects that would not work by looking at the four DLL files:

GalaSoft.MvvmLight.Extras.WPF4 GalaSoft.MvvmLight.WPF4 Microsoft.Practices.ServiceLocation System.Windows.Interactivity

I don't see any differences in versions.

So, the work around for now is to start a new project using the MVVM Light WPF template in Visual Studio 2012, build it, then remove references to the four DLL's mentioned above. Then I install the package MVVM Light from NuGet and edit out the double entry of the view model locator in App.xaml and then the program works fine. At this point I can see the design data message on the Main window which says

"Welcome to MVVM Light [design]"