How to move MVVM items to a DLL

0

I have a project (C#, Visual Studio 2010, MVVM Light) which required some elements to be extracted to a DLL.

In the case of data objects and what not, I was able to do this perfectly fine. The problem arose when I wanted to also put my GenericViewModelBase class into the DLL - this is because said class uses classes from the MVVM Light library.

So at this stage I need MVVM Light references in both my DLL and the project itself (that uses the DLL as a reference). But when I do that, and my main project has classes which are based on GenericViewModelBase from the DLL, I get an error in the ViewModelLocator class (that comes with MVVM Light). It's happening when I'm attempting to get the list of objects which are based on GenericViewModelBase.

That looks like this:

public LanguageItemListViewModel LanguageItemListViewModel
    {
        get
        {
            return ServiceLocator.Current.GetInstance<LanguageItemListViewModel>();

        }
    }

This works normally and works if I don't try to put the MVVM Light stuff in the DLL.

The inner exception given is this:

Could not load file or assembly 'GalaSoft.MvvmLight, Version=5.3.0.29702, Culture=neutral, PublicKeyToken=0e453835af4ee6ce' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"GalaSoft.MvvmLight, Version=5.3.0.29702, Culture=neutral, PublicKeyToken=0e453835af4ee6ce

I'm quite new to DLLs so I don't really know the solution or even the approach here. So, in short: project needs MVVM Light references. I want stuff in DLL. DLL stuff needs MVVM Light references. Project and DLL now have MVVM Light references. Error.

One thought I had was to remove the MVVM Light stuff from the project and then switch any using statements so that they references the DLL. So, for example, this:

using GalaSoft.MvvmLight;

Would become this:

using WPF_MVVM_GenericBaseDLL.GalaSoft.MvvmLight;

But it just tells me that Galasoft does not exist in WPF_MVVM_GenericBaseDLL (it is there however, in the references list in the DLL).

I hope that's not too confusing and I also hope that someone else can offer some solutions to my problem. Do I need the MVVM Light DLLs in both or ...what?

Thanks!

c#
dll
mvvm-light
asked on Stack Overflow Feb 8, 2019 by TheFaithfulLearner • edited Feb 9, 2019 by TheFaithfulLearner

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0