0

I have a Visual Studio project in Dropbox, I have been working on this project from two different computers (NOT at the same time) but for some reason, it just stopped working on one computer, I can open it in one but when I try to open it from the other computer I see an error.

FYI - One computer is running Windows 7 and the Other one is running Windows 10 but both are running Visual Studio 2015. Also, I'm using MVVM Light in this solution.

Error:

TypeInitializationException was unhandled by user code

An exception of type 'System.TypeInitializationException' occurred in MyApp.exe but was not handled in user code

Additional information: The type initializer for 'MyApp.ViewModel.MainViewModel' threw an exception.

I tried cleaning the solution but nothing, no luck.

Any idea why it would stop working on one computer but not the other if it's the same solution?

EDIT: Added code.

namespace MyApp.ViewModel
{
    public class ViewModelLocator
    {
        private static MainViewModel _main;

        public ViewModelLocator()
        {
            _main = new MainViewModel();
        }

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public MainViewModel Main
        {
            get
            {
                return _main;
            }
        }
        public static void Cleanup()
        {
        }
    }

}

Constructor fo MainViewModel

    public MainViewModel()
    {
        CurrentViewModel = MainViewModel._findrViewModel;
        FindrViewCommand = new RelayCommand(() => ExecuteFindrViewCommand());
        CalculatorViewCommand = new RelayCommand(() => ExecuteCalculatorViewCommand());
        ProductionTimesViewCommand = new RelayCommand(() => ExecuteProductionTimesViewCommand());
    }
Community
  • 1
  • 1
fs_tigre
  • 10,650
  • 13
  • 73
  • 146
  • 3
    This looks like an infamous WPF issue. What is in the constructor for MainViewModel? Also, i suggest you learn how to use `git`. there are plenty free services to host projects in a proper source control so you don't have to mess around with dropbox... – zaitsman Nov 02 '17 at 22:46
  • @zaitsman The error actually points to the constructor of the MainViewModel `public ViewModelLocator() { _main = new MainViewModel(); }` – fs_tigre Nov 02 '17 at 22:50
  • 1
    Of course. Can you show the `constructor` code of `MainViewModel`? – zaitsman Nov 02 '17 at 22:51
  • This is it `public ViewModelLocator() { _main = new MainViewModel(); }` – fs_tigre Nov 02 '17 at 22:52
  • No, this is how you CALL the constructor. The constructor code is inside the `MainViewModel.cs` file. – zaitsman Nov 02 '17 at 22:54
  • I posted the entire code for the `ViewModelLocator` class. Sorry, the error points to the constructor of the `ViewModelLocator`. I also posted the code in constructor of MainViewModel. – fs_tigre Nov 02 '17 at 22:59
  • 1
    Well, now you need to find out which line in the `MainViewModel` constructor breaks. At design time it is done like so: starting at line 1, comment out the line, rebuild the solution and reload the designer. My money is on `CurrentViewModel = MainViewModel._findrViewModel;` – zaitsman Nov 02 '17 at 23:02
  • @zaitsman Commented out each of the four lines in the constructor of the MainViewModel and still got the error. I also commented out the line in the constructor of the `ViewModelLocator` and then I build without errors but as expected none of the functions in the app work. `public ViewModelLocator() { _main = new MainViewModel(); }` – fs_tigre Nov 03 '17 at 00:31
  • Try these: https://stackoverflow.com/questions/58425/wpf-application-fails-on-startup-with-typeinitializationexception? – zaitsman Nov 03 '17 at 00:32
  • `App.config` file seems to be ok, I created a new project and compared both and they are the same. – fs_tigre Nov 03 '17 at 00:53

0 Answers0