My WPF Application cannot locate resource 'Mainwindow.xaml' - wpf

I have been working on a WPF application using vb.net and I've recently run into a problem.
When I build my code, the build is successful but when it comes to running the code the System.IO.IOexception throws an exception "Cannot locate resource ViewModel/ViewModel/Mainwindow.xaml"
The .Xaml windows are located in a folder called ViewModel hence I don't know where the other ViewModel/ViewModel... path is coming from, isn't it supposed to be viewModel/MainWindow.Xaml?
I have tried all possible solutions including cleaning up the Project but it doesn't seem to work.
The only solution that seems to work is if I change the StartupUri from
StartupUri = "ViewModel\MainWindow.Xaml" TO StartupUri = "...\MainWindow.xaml" but I doubt if that is the right thing to do.

Change the StartupUri="MainWindow.xaml" to StartupUri="FolderName/MainWindow.xaml"
Solved my problem, when I moved my MainWindow to the View Folder

In my case I needed to use pack URI syntax to set SrartUpUri property of my App.xaml file to point to a new location of my MainWindow.xaml, as so:
<Application x:Class="TrafficLights.Controller.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="pack://application:,,,/View/MainWindow.xaml">
More on pack URIs here:
http://msdn.microsoft.com/en-us/library/aa970069(v=vs.110).aspx
Hope it helps. Good luck!

This happened to me few times - always when I moved MainWindow.xaml to different folder and forgot to update StartupUri in App.xaml.

Visual Studio has somehow renamed my MainWindow.xaml to MainWindow(1).xaml, so again I renamed it to MainWindow.xaml

I renamed the Mainwindow.xaml file to NameList.xaml and had not updated the App.xaml file. Once I did that StartupUri="NameList.xaml", it was fine.

Related

wpftoolkit chartin, namespace referencing in XAML

I am using the basic WPFToolkit - I have both DLL's embedded in my EXE. I followed this tutorial:http://www.digitallycreated.net/Blog/61/combining-multiple-assemblies-into-a-single-exe-for-a-wpf-application
Everything is working with the DLL not embedded. When embedded, while I can compile with no error, I get a parsing error pointing at the XAML referencing of the wpftoolkit dll.
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" x:Class="Swiftech_Imperium.MainWindow"
both DLL's are set to embedded resources, and both references are set to do not copy.
If I enable copy local for the system.windows.controls.datavisualization.toolkit.dll it works, but then I need the DLL at the root of the exe (I shouldn't need that since it's already embedded in the EXE - and I can't do this for this specific project..)
any idea what's wrong here?
thanks
Just because the .DLL reference is set to Embedded Resource doesn't mean the libraries will get resolved/loaded at runtime. You need to manually do that. I'm not sure if WPFToolKit can successfully do that, but to test it, you will want to to follow the answer found here.

Moving xaml file in solution explorer in WPF MVVM project

Im new to the MVVM Pattern, i think this question willbe rather easy for you guys.
I created a new wpf project so far and added 3 folders(model, view, view model). I dragged and dropped the mainwindow.xaml file into the view folder and added a button to the xaml so far. At Runtime i get an error cant find "mainwindow.xaml" reference or something like that.
I think i just have to set the path to that file somewhere but i dont know where.
thanks for your help.
Your App.xaml file will be looking for this file on application startup.
If you are using the MainWindow.xaml file in the same project, change the StartupUri in the App.xaml file to "View\MainWindow.xaml" and this should resolve the issue.

Pack URI syntax in User Control

I have a very simple project where are all files are within the same solution. Getting this weird issue when trying to reference resources in a user control specifically. The same pack uri syntax works perfectly well in MainWindow.xaml but when used in user control is giving an error.
Here is my files folder structure:
Here is my Mainwindow.xaml screenshot:
SummaryView.xaml (UserControl) screenshot:
Try writing out the name of the assembly explicitly:
"pack://application:,,,/FIBRE_Reporting;component/Resources/Brushes.xaml"

ExpressionBlend exception when UserControl contains my custom control

I can edit this UserControl just fine in visual studio but I get this strange exception in expression blend. Does anybody know what should I look for?
UPDATE
I wasn't able to figure how to debug/attach. I did everything as instructed by Mike but no breakpoints got hit. I did more investigation and found that most likely my issue related to themes/generic.xaml
My visual studio solution has project named Infrastructure.dll. Inside that project I have folder themes and inside I have file generic.xaml. Generic.xaml set to compile as resource. My control class lives in a same project.
I have another project named 'Module.dll' and that project references Infrastructure.dll
When I open view with my control (view is from Infrastructure.dll) it works in Visual Studio but gives this error in Blend.
I can drag/drop control in Blend and it would give same error. I tried to remove line where I apply template to control (template in generic.xaml) and it works.
Template is good, I created it using Blend and copied to generic.xaml myself.
When I create view INSIDE Infrastructure.dll and drop my control on that view - it works.
So, my conclusion is that Blend doesn't see template inside generic.xaml that lives in referenced project. How do I fix this?
Open your project in Blend (but do not yet open the problem file). Also open your solution in Visual Studio (order of opening is not important). From Visual Studio, select Debug -> Attach to process... and select Blend.exe. Make sure you're breaking on all exceptions. Once the debugger has finished attaching and loading everything, open the problem file in Blend. The debugger should (hopefully -- hard to tell from the exception details) stop at the problem area in your code.
Issue was definitely related to Blend's inability to read/locate generic.xaml
Visual studio doesn't have this issue btw. I found workaround for now - will gladly accept another answer if I can avoid doing that..
After I add resource reference to view - everything works in Blend. This means I have to add this XAML to all my views..
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Infrastructure.SL;component/Themes/generic.xaml"/>
</ResourceDictionary.MergedDictionaries>

Can't use WPF designer because can't find custom base window type in XAML, but code behind is fine

I am using a base Window class in a WPF project. In the code behind C# file the assembly to the base type is referenced and fine. In the XAML is looks like this:
<MyNamespace:WindowBase x:Class="MyNamespace.Applications.UserInterface.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:MyNamespace="clr-namespace:MyNamespace.Somewhere;assembly=MyNamespace.Common"
Title="MainWindow" Height="350" Width="525">
<Grid>
</Grid>
The solution compiles fine and I can run it. I just can't use the designer in VS 2010. It throws the following exception: The type'MyNameSpace:WindowBase' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
Well. they have been. I can't understand what this issue is. This particular base class is used in other projects just fine. I grabbed it for a new project and I can't use the designer. Very frustrating.
Found this problem just recently (this answer upgraded from a comment).
If you copy the dll from a network path, you must right click on the file in Windows Explorer, select Properties, then 'unblock'; there is a hidden NTFS stream associated with the file, and many files when you download from the 'net or copy from a network path, for security reasons.
Only the designer complains, yet the project builds and runs fine: weird isn't it?!
Whenever the designer is acting up against me - the first thing I do is clear the obj-folders in the project and rebuild. Sometimes they seem to go out of sync for some reason (usually when I'm drag-dropping a lot of files and renaming visual items).
I dont't know if its the same issue but in VS2008 I tried to make abstract UserControls but had to change this because the designer didnt't support any abstract base classes (however the solution was compilable and also worked as excpected).
Fixed. The library that contained my base class resided on a drive on the network that I did not have permissions to. That seemed to have no affect on VS 2008 as it worked, but VS 2010 apparently took exception to that when the designer tried to load it. Weird.

Resources