Cannot locate 'app.xaml', IOException until modifying app.xaml - c#

Basically I'm having the same issue as this (unanswered) question: IOException was unhandled - Cannot locate resource app.xaml
When I open my project in Visual Studio 2010 and start debugging, I get "IOException was unhandled: Cannot locate resource app.xaml". Rebuilding the solution DOES NOT work, I have to somehow modify my app.xaml file (adding an empty line, for example) in order to run my project successfully.
Additional details:
My solution consists of two projects: My main (WPF) application and a test project.
I have read about issues if the solution was converted from Visual Studio 2005. This is not my case. My project was originally created with Visual Studio 2010. Maybe (I don't remind exactly) it was sometime targetted at .Net Framework 3.5 or .Net Framework 4.0 Client Profile, but it currently is configured to work with .Net Framework 4.0
Both projects have different names, if that matters. The first is called MyApplicationName (assembly name and default namespace) and the second MyApplicationName.Test (assembly name and default namespace too)
Most classes in my main project are internal (including the View classes), but my App class is public
The main project exposes its internal components to the test project (using [assembly: InternalsVisibleTo("MyOtherProject")])
I'm using MVVM (with MVVM Light), but I'm not using a ViewModel 'resolver'/container/bootstrapper/MEF or related things. I just map my ViewModels to their respective views using DataTemplates and create my ViewModels manually (if that matters).
My App.xaml includes other three xaml resource files. I include my App.xaml here:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/StyleDictionary.xaml" />
<ResourceDictionary Source="Resources/CommonResources.xaml" />
<ResourceDictionary Source="Resources/ViewModelMappings.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
I override the OnStartup method from my App class to manually handle the startup logic, if that matters. I also wrote a static constructor there to initialize the DispatcherHelper from MVVM Light:
public partial class App : Application
{
static App()
{
GalaSoft.MvvmLight.Threading.DispatcherHelper.Initialize();
}
...
}

Things like this could happen when you change the target framework of a project. You could recreate the projects as new applications which target .Net 4 from the start, and add all your code files as existing items.
Another thing that comes to mind is the casing of the app.xaml file name. It might be case sensitive in some contexts and not case sensitive in others, so have you tried changing that? On my system, by default it is App.xaml. Since in the error message it is app.xaml, it might be worth while doing a case sensitive search through the project files with a text editor and changing all occurences of the name to App.xaml.

I don't know if this is a definitive solution, but it seems to be working so far:
Open your csproj file with Notepad
Search App.xaml and App.xaml.cs. Ensure every reference to this file has the same case. The files were called App.xaml and App.xaml.cs, so I left the references like that.
Previously I had something like this:
<Compile Include="app.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
So I modified it and now it is:
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
Another thing I did was look for BootstrapperPackage and remove the old versions of .Net Framework from there, though I don't think that's a good idea if your project uses libraries that depend on old versions of .Net. I'm not sure that was causing the problem too.

Related

VSIX WPF Wizard Instead of Forms

I'm working on an extension for Visual Studio and I'm currently looking at using WPF instead of Forms for the template wizard.
I've got it all working with Forms but I much prefer the look of and working with WPF, but I'm not sure if what I'm trying to do is possible - or how I should go about doing it properly.
My VSIX consists of your typical layout, it's a solution with 3 projects;
1. MyProjectTemplate (C# Project Template)
2. MyProjectVSX (C# VSIX Template)
3. MyWizardWPF (WPF App)
I'm also using MahApps.Metro to make it look a bit sleeker. Added (via NuGet) and referenced by both MyProjectVSX and MyWizardWPF.
And while it works - the WPF shows up when I go to create a template - it is completely and utterly missing any styles. It basically just looks like a Windows 95 application.
I'm assuming this is related to the App.xml and it being unable to locate it. But I'm at a complete loss at how to tie all of this together. I get a bunch of warnings that it was unable to find various style related things. For example;
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='MahApps.Brushes.IdealForeground'
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='MahApps.Brushes.ThemeForeground'
I've tried playing around with the ResourceDictionary URIs, copying the App.xml to my VSX project. Tried building it as a class library instead of an application but to no avail.
Is what I'm trying to achieve here feasible...?
Well I was able to reference MahApps.Metro. Seems like I was vastly over-looking it all. I'm still not sure if this is the right way to do it, however. But it works.
I referenced MahApps.Metro inside the Window.xaml itself instead of via the App.xaml, like so;
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="/MahApps.Metro;component/Styles/Fonts.xaml" />
<!-- Accent and AppTheme setting -->
<ResourceDictionary Source="/MahApps.Metro;component/Styles/Themes/Dark.Blue.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
This also works if I create a WPF User Control which will make the overall project a bit less bloated - but the designer will not be using MahApps.Metro styles. I have yet to find a fix for this.

WPF adding a third party ResourceDictionary to App.xaml?

This may well be a stupid question, but I cannot find an answer...
I am just getting started with WPF, and am trying to add a ResourceDictionary to my project.
this one here:
https://monotone.codeplex.com/
So I downloaded the zip file, and unzipped it to:
MyProjectDir/MonoTone
I have added the following to my App.xaml
<Application x:Class="TestWPF.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestWPF"
xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Monotone/Monotone.Colors.xaml" />
<ResourceDictionary Source="Monotone/Monotone.Brushes.xaml" />
<ResourceDictionary Source="Monotone/Monotone.MahApps.xaml" />
<ResourceDictionary Source="Monotone/Monotone.xaml" />
<ResourceDictionary Source="Monotone/Monotone.ExtendedWPFToolkit.xaml" />
<ResourceDictionary Source="Monotone/Monotone.ColorBox.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
as here:
https://monotone.codeplex.com/wikipage?title=Installing%20Monotone&referringTitle=Documentation
Now Intelsense is underlining the xaml paths, and cannot find the files.
I have added a reference to the dll. What am i missing?
Thank you.
First, try including the Monotone catalog in the solution by clicking on show all files icon in solution explorer.
Second, as shown in below screen, pinpoint the exact path as in the first line of example.
To explicitly answer your question: Visual Studio was complaining because you needed to add the Monotone files (from the release zip) to your project under a folder called "Monotone".
Janis S's answer already stated this.
Unfortunately, the Monotone project contains a few dependencies on other projects... Specifically, you'll notice that it references the ColorBox control, which can be found on CodePlex, and it also depends on some Xceed assemblies. Your project will not build without those.
A few examples of the references to external dependencies are:
xmlns:xtk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:nc="http://schemas.ncore.com/wpf/xaml/colorbox"
xmlns:conv="clr-namespace:Xceed.Wpf.Toolkit.Converters;assembly=Xceed.Wpf.Toolkit"
xmlns:Behaviours="clr-namespace:MahApps.Metro.Behaviours"
xmlns:mm="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:mmm="http://metro.mahapps.com/winfx/xaml/shared"
At this point you have three options
remove all references to the external assemblies.
OR figure out which assemblies are needed and add references to those as well.
OR find a different dark theme to use.
Option 3 is probably the best one at this point as CodePlex is shutting down soon and Monotone does not appear to be maintained. A quick Google search results in a few free WPF Dark Themes that are still functioning that could be used instead.
Edit
If you really want to use Monotone, go to their downloads page and grab the sample application. All of the missing DLLs are included in that download (you will need to include those in your project and add them as references).
I might be very late to the party, but to clarify things:
I am the creator of Monotone (which was a theme I used for an IDE I developed which is now obsolete). I don't mind if you pick another/better dark theme for your application, it's pretty old at this point.
Monotone is now 'maintained' on GitHub. Well, it's more or less stale at this point since I'm not into C# anymore. But if you (or anyone else) have a specific problem with it, feel free to submit an issue on GitHub or a pull request that solves it.
You only need to add the XAML-files for Monotone.Colors.xaml, Monotone.Brushes.xaml and Monotone.xaml to the ResourceDictionary.MergedDictionaries for the default WPF controls. Include in this order. If I remember correctly the files have to be set to EmbeddedResource. That's it.
Monotone.ExtendedWPFToolkit.xaml is only needed if you use (and want to theme) the ExtendedWPFToolkit controls. Sames goes for Monotone.MahApps.xaml and Monotone.ColorBox.xaml. So, these are optional. It's kept in separate files to avoid dependencies to libaries you might not use
You don't need the DLLs for styling the standard WPF controls
Because of the shutdown of CodePlex the Wiki-Pages are gone. I might dig into the code and recreate it on GitHub (or even better add it to the repo itself), that you have a helpful documentation.
As pointed out, the SampleApplication contains a working example which you can use as a template and/or to understand how it works

Root class of the solution

I am trying to build a network with all the solution classes as nodes - connected to their parents (classes using them) and children (classes they use). From there I want to get the "critical paths" from the root-class(es). By critical paths I mean the paths in the network that originates at the root(s).
I know you can set a specific project in a solution as the startup project. When the solution is built and run, what class in the startup project is the root or main class than is run first? - that would be my root class.
All projects in the solution are WPF projects.
In a wpf project,by default, the first class that is called is the App class.
The class looks like this:
App.xaml.cs
public partial class App : Application
{
}
App.xaml
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
As you can see there is StartUpUri in there which contains what window will show up first.
In general this is set for each project separately and it differs depending on the technology. It is easy accessible by Visual Studio, just go to the project configuration, there in Application tab you will see Startup Object, that can be selected from those that fit the requirements. See screenshot.
For Winforms this is persisted in the App.config as:
<StartupObject>OBJECT_NAME</StartupObject>
For WPF you will find it by default in App.xaml. However this could be customized in ApplicationDefinition section of the csproj file and other files could be potentially used. For Web or WCF it will be even more different as there is no real startup object, just default page.
As you can see there is no one simple answer; however for only WPF you should be able to get a fairly complete solution. Bear in mind that there are usually class libraries projects included as well.

Does XAML work with file links in Visual Studio?

I'm adding a new WPF project to an existing Visual Studio solution and would like to reuse a bunch of code (C# and xaml) from an existing project within the solution.
I've created the new project and added existing files as follows:
Right click project
Add -> Add Existing Item
Find the file to reuse, use the arrow next to "Add" and "Add as Link"
I now have a nice project set up with all the proper links. However, XAML chokes on these links. For example:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="Resources\Elements\Buttons\Buttons.xaml" />
<ResourceDictionary
Source="Resources\Elements\TextBox\TextBox.xaml" />
</ResourceDictionary.MergedDictionaries>
The files "Buttons.xaml" and "TextBox.xaml" exist as links in my new project. The project builds, but when I run, I get the following XamlParseException:
'Resources\Elements\Buttons\Buttons.xaml'
value cannot be assigned to property
'Source' of object
'System.Windows.ResourceDictionary'.
Cannot locate resource
'resources/elements/buttons/buttons.xaml'.
It seems like the XAML parser is requiring an actual copy of these XAML files to exist in my new project, instead of links.
This is exactly what I'm trying to avoid. I want my project to share these files so that any changes get transferred to the other project without hunting and copying.
Any insight is appreciated!
Linking to an external XAML file does not create a file where the link exists in a project structure, as you have noticed.
My advice is to use relative links in the MergedDictionaries references. If the XAML to reuse in another project is called Common, the Source property of the first nested ResourceDictionary could be:
..\Common\Resources\Elements\TextBox\TextBox.xaml
which is actually the path that you used to add the existing item.

What does MissingManifestResourceException mean and how to fix it?

The situation:
I have a class library, called RT.Servers, containing a few resources (of type byte[], but I don't think that's important)
The same class library contains a method which returns one of those resources
I have a simple program (with a reference to that library) that only calls that single method
I get a MissingManifestResourceException with the following message:
Could not find any resources
appropriate for the specified culture
or the neutral culture. Make sure
"Servers.Resources.resources" was
correctly embedded or linked into
assembly "RT.Servers" at compile time,
or that all the satellite assemblies
required are loadable and fully
signed.
I have never played around with cultures, or with assembly signing, so I don't know what's going on here. Also, this works in another project which uses the same library. Any ideas?
All I needed to do to fix this problem was to right-click the Resources.resx file in the Solution Explorer and click Run Custom Tool. This re-generates the auto-generated Resources.Designer.cs file.
If the .resx file was added to the project manually, the Custom Tool property of the file must be set to "ResXFileCodeGenerator".
The problem is due to a mismatch of namespaces, which occurs if you change the "default namespace" of the assembly in the project settings. (I changed it from (previously) "Servers" to (now) "RT.Servers".)
In the auto-generated code in Resources.Designer.cs, there is the following code:
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Servers.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
The literal string "Servers.Resources" had to be changed to "RT.Servers.Resources". I did this manually, but running the custom tool would have equally well done it.
I just came across this problem today, and I found this Microsoft Help and Support page that actually did work around the problem.
I had a couple delegates at the top of my file, in the global namespace, and all of a sudden I was getting a MissingManifestResourceException when running the program, on this line:
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
Then I moved the delegates into the namespace, got the same error. Finally I put the delegates in the only class in that file, and the error went away, but I didn't want the delegates in that class or namespace.
Then I came across that link above, which said
To resolve this problem, move all of the other class definitions so that they appear after the form's class definition.
I put the delegates (which I would not consider "class definitions") at the bottom of that file, outside of the local namespace, and the program didn't get the MissingManifestResourceException anymore. What an irritating error. But, that seems like a more robust solution than modifying the auto-generated code :)
I've run into a similar issue and, although I know it isn't the cause the OP had, I'll post it here so that if someone else runs across this problem in the future, an answer will be available.
If you add a class before the designer class you will get a MissingManifestResourceException exception at runtime (no compile time error or warning) because
Visual Studio requires that designers use the first class in the file.
For (slightly) more information see this post.
I had the same problem, but using the Run Custom Tool command as suggested by Timwi did not help in my case.
However it lead me into the right direction, because I ended up in the Properties of the .resx file. Here I noticed a difference to another .resx file that caused no problems.
In my case I had to change the property "Build Action" from "Resource" to "Embedded Resource".
My best guess for the reason is, that I had the .resx in a library that was used from another application. My application did not have its own .resx file, so it had to use the one from the library - which is only available when it's embedded in the library and not "stand alone".
When I run in a similar issue, in Vs 2012, it turned out that the "Custom Tool Namespace" property of the resx file was wrong (in my case, actually, it was unset, so the generated code yeld this exception at runtime).
My final set of properties for the resx file was something like this:
Build action: Embedded Resource
Copy to Output Directory: Do not copy
Custom Tool: ResXFileCodeGenerator
Custom Tool Namespace: My.Project.S.Proper.Namespace
I ran into a different cause of this problem, which was unrelated to resx files. I had a class library where AssemblyInfo.cs contained the following:
[assembly: ThemeInfo(
ResourceDictionaryLocation.SourceAssembly,
ResourceDictionaryLocation.SourceAssembly)]
The assembly did not contain any WPF code, theme or Resource dictionaries. I got rid of the exception by removing the ThemeInfo attribute.
I did not get an actual exception, only
A first chance exception of type 'System.Resources.MissingManifestResourceException'.
Viewing exception details, the system was requesting MyAssembly.g.resources
Hope this might be of help to someone else.
Also see: MissingManifestResourceException when running tests after building with MSBuild (.mresource has path in manifest)
I repeat the answer here just for completeness:
It appears adding LogicalName to the project file fixes it:
<LogicalName>$(RootNamespace).Properties.Resources.resources</LogicalName>
i.e. so the embedded resource entry in the project file looks like this:
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<LogicalName>$(RootNamespace).Properties.Resources.resources</LogicalName>
</EmbeddedResource>
</ItemGroup>
This is detailed in: http://blogs.msdn.com/b/msbuild/archive/2007/10/19/manifest-resource-names-changed-for-resources-files.aspx
Note that we are using a .resx file, but the bug still appears to occur.
Update: The problem with resources (incl. XAML) appears to be related to output paths and the use of forward or backward slashes as detailed in:
Why does modifying project output directories cause: IOException was unhandled "Cannot locate resource 'app.xaml'."
Not sure it will help people but this one worked for me :
So the issue I had was that I was getting the following message:
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "My.Resources.Resources.resources" was correctly embedded or linked into assembly "X" at compile time, or that all the satellite assemblies required are loadable and fully signed"
I was trying to get the resources that were embedded in my project from another class library.
What I did to fix the problem was to set the Access Modifier in the tab Project->Properties->Resources from "Internal" (accessible only within the same class library) to "Public" (accessible from another class library)
Then run and voilĂ , no more error for me...
The solution given by BlaM worked for me too.
I am a VS 2013 User. After going through many fixes but no luck, I tried this:
Right-click the resource file, one-by-one, in case of multiple-files.
Make sure, the property "Build Action" is set to "Embedded Resource".
That's it! :)
I had the same issue, but in my case i places a class in a usercontrol which is related to the usercontrol like this
Public Class MyUserControlObject
end Class
Public Class MyUserCOntrol
end Class
The solution was to move the MyUserControlObject to the end of the Usercontrol class, like this
Public Class MyUserCOntrol
end Class
Public Class MyUserControlObject
end Class
I hope this helps
I was getting the MissingManifestResourceException error after I ported my project from VS2005 to VS2010. I didn't have any other classes defined in the file that contains my Form class. And I also had my resx Resource File Name set correctly. Didn't work.
So I deleted the resx files and regenerated them. All good now.
Recently ran into the same problem, struggled for a bit, found this topic but no answers were correct for me.
My issue was that when I removed main window from my WPF project (it does not have a main window), I forgot to remove StartupUri from App.xaml. I guess this exception can happen if you have a mistake in StartupUri, so in case if anybody is struggling with this - check your StartupUri in App.xaml.
Recently stumbled upon this issue, in my case I did a few things:
Make sure the namespaces are consistent in the Designer.cs file of the resx file
Make sure the default namespace of the Assembly(right click the project and choose Properties) is set the same to the namespace the resources file is in.
Once I did step 2, the exception went away.
I had this problem when I added another class in the file just before the class which derived from Form. Adding it after fixed the problem.
Also the same error may occur when you put a new class into the source code of a designer created form's class.
This new class may be removed, and placed in a different cs file.
(At least in my case this was the problem...)
Because I am pre-compiling my web application (using VS2012 publish feature). I was getting the error above. I tried all the suggestions, but weirdly changing 'Build Action' to 'Content' did the trick!
In my case, I have a web api with resources and I create a nuget package from that. When I use this nuget in other projects, I realise that when I request a api with resources, I am getting MissingManifestResourceException after a bit reasearch, I learn nuget packager is not packing resources automatically. If you want to use resources files, you have to do that manually. So you need to add below lines to your .nuspec file:
(Visit https://github.com/NuGet/Home/issues/1482)
<package>
<metadata>
</metadata>
<files>
<file src="bin\Debug\en\MyAssembly.resource.dll" target="lib\net40\en\MyAssembly.resource.dll" />
<file src="bin\Debug\es\MyAssembly.resource.dll" target="lib\net40\es\MyAssembly.resource.dll" />
</files>
</package>
But, before adding files, you need to be sure which version of .net you are using.
I had the with a newly created F# project.
The solution was to uncheck "Use standard resource names" in the project properties -> Application -> Resources / Specify how application resources will be managed.
If you do not see the checkbox then update your Visual Studio! I have 15.6.7 installed. In 15.3.2 this checkbox is not there.
Just to mention. If you use a constant or literal, make sure it refers to a resource of the form ProjectName.Resources, and does not cpntain Resources.resx.
It could save you an hour or two .
I've encountered this issue with managed C++ project based on WinForms after renaming global namespace (not manually, but with Rename tool of VS2017).
The solution is simple, but isn't mentioned elsewhere.
You have to change RootNamespace entry in vcxproj-file to match the C++ namespace.
In my case it was a typo in the Xaml of a window opened from Winforms Form:
Incorrect: <Image Source="/Resources/WorkGreen.gif"/>
Correct: <Image Source="../Resources/WorkGreen.gif"/>
It may help someone
In my case I have changed my project namespace and hence my solution was throwing "missingmanifestresourceexception" exception. Instead of right clicking the .resx file in the solution explorer and clicking on "Run Custom Tool" option, I have replaced the
rootnamespace to new namespace in .csproj file(RootNamespace) and rebuilded the solution again. All Resources.Designer.cs files namespaces got automatically changed with new namespace.
I hope my answer will help someone.
If you're getting this while generating a C# project using CMake, the solution I found may help you.
Your CMakeLists.txt file needs
set_property(TARGET yourTargetName PROPERTY VS_GLOBAL_RootNamespace yourRootNamespace)
Substitute your own values for yourTargetName and yourRootNamespace, obviously.
Then the resources will get embedded in your assembly!
One more reason to get this error is- '.resx' file excluded from project.
In my case, '.resx' file was excluded from project.
Select 'show all files' option in solution explorer.
Right click on '.resx' file(s) and click include in project.
Rebuild the project/solution.
I read all the answers and nothing worked for me. Most likely my situation is different, but same error. My issue was that I had two projects. Second project had a lot of forms added to it from the first one as "Add as link".
For WinForms, there are 3 required files: the code, the designer, and the resource files. If you add all 3 files at the same time as "Add as link", Visual Studio does not link them together as same form. It will compile, and run, but it will blow up with the same MissingManifestResourceException error.
Fix: You have to do them individually, in order: code file --> designer file --> resource file. Then they are grouped and no more error, at least for me.
From the Microsoft support page:
This problem occurs if you use a localized resource that exists in a satellite assembly that you created by using a .resources file that has an inappropriate file name. This problem typically occurs if you manually create a satellite assembly.
To work around this problem, specify the file name of the .resources file when you run Resgen.exe. While you specify the file name of the .resources file, make sure that the file name starts with the namespace name of your application. For example, run the following command at the Microsoft Visual Studio .NET command prompt to create a .resources file that has the namespace name of your application at the beginning of the file name:
Resgen strings.CultureIdentifier.resx
MyApp.strings.CultureIdentifier.resources

Categories

Resources