Reputation: 4792
I'm using WPF with .NET 4.5.2 on Visual Studio 2012 and getting a FileNotFoundException in the XAML view when editing my View:
The application compiles and runs fine otherwise. The exception manifests as a blue underline only.
I debugged XDesProc.exe and found this to be the source of the exception. The reason being that its working directory is C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE
so its looking for the config in the wrong place.
It occured to me that this might be a problem of design in the application. The exception is being thrown from in MainWindowViewModel.cs on this line:
RemotingConfiguration.Configure("ZZZZZ.exe.config", false);
I believe this line is being reached when the XAML UI Designer reaches this section of my View.xaml:
<Window.DataContext>
<vm:MainWindowViewModel/>
</Window.DataContext>
Which is where I'm instantiating my ViewModel and assigning it to the DataContext.
I think I need to move RemotingConfiguration.Configure()
outside of my ViewModel constructor but I don't know where to put it. I believe this to be the solution to my problem.
Thanks in advance!
Upvotes: 1
Views: 197
Reputation: 31656
In design mode controls and instances which are specified in the xaml are instantiated. Within your VM (or other areas) there may be code which should not be attempted during design mode.
Its best to segregate out those sections by specifying whether or not to attempt it if it is design mode such as
if (!DesignerProperties.GetIsInDesignMode(this)) { ... } // if not in design mode.
Since the VM is the issue, here are the options.
Name
attribute on the VM in the Xaml. INotifyPropertyChanged
) on the VM named IsInDesign
.IsInDesign
to the named VM.IsInDesign
and stop any loading/reading of files depending on its value.Upvotes: 1