WPF App StartupUri is not found when using linked source files - c#

I have a WPF solution which produces two executables. Both projects use the same startup form.
In my newer project I access all the form sources using linked source files within a folder called "Forms" (which also has the same name on the original project).
Both projects have an App.xaml containing
<Application ...
StartupUri="Forms/frmMenu.xaml"
Startup="App_Startup"/>
The following IOException is raised at runtime (but only for the new project):
System.IO.IOException was unhandled
HResult=-2146232800
Message=Cannot locate resource 'forms/frmmenu.xaml'.
Source=PresentationFramework
Is this a WPF bug?
n.b. The actual path is .../Forms/frmMenu.xaml is the lowercase an issue?

Thankyou CodingYoshi.
It turns out that the inappropriately named StartupUri is not a Uri it is a file path. So the value should have been:
StartupUri="Forms\frmMenu.xaml"
Interestingly, the original project used
StartupUri="Forms/frmMenu.xaml" and worked fine.
When I switched the original to use StartupUri="Forms\frmMenu.xaml" it continued to work.
I guess the backslash is just for linked files.

Related

Parser Error Message: Could not load type 'sometype'

I am experiencing an error that I am unable to resolve for some time now. I was wondering if someone can help identify the cause of this error? I am completely new to asp / asax. After some research, I think that the error I am getting is due to the web application trying to use outdated code. I was thinking to rebuild the c# file using Visual Studio and/or the entire project. However, I am completely new to C# and asp, and was wondering can give me some suggestions if this may fix the problem and/or if there is an possible alternate solution.
Error message
Parser Error Message: Could not load type 'Inventory1.Global'.
Source Error: <%# Application Codebehind="Global.asax.cs" Inherits="Inventory1.Global" %>
Entire Global.asax contents:
<%# Application Codebehind="Global.asax.cs" Inherits="Inventory1.Global" %>
Try replacing CodeBehind with CodeFile
Could not load type
means that a type could not be loaded. (In this case, "type" refers to Inventory1.Global). Types are located in compiled DLLs. So, either the DLL isn't available, is out of date, or doesn't contain a public type with the given name.
Some possible causes are:
You have no type declared with the given name. For your example, you should have the following:
namespace Inventory1 {
public class Global {
...
}
}
Note: avoid names like Inventory1. They imply that there is an Inventory2, Inventory3, etc., which is bad practice as they're abmiguous and not very descriptive. Also, Global is pretty vague, and may introduce confusion with the global namespace.
Make sure your cases match (Inventory1, not INVENTORY1.)
You haven't compiled the project. In VS, rebuild the solution.
The assembly that declares the class has a compilation error, so the relevant DLL is either missing or out of date. Make sure you've resolved all errors.
The class is not marked as public.
If I had to guess, I'd put my money on a compilation error. Unlike PHP and other interpreted languages, C# have to be successfully compiled before they can be used.
I had this error , just needed to rebuild the project
I faced this issue and i got the solution from here and i would like to share it.
SOLUTION
Empty the bin folder. Build all the dependent class libraries and refer them in the main project and build the complete solution.
I did this and it worked like a charm for me !!
After scouring around for what could have caused this I found a few things that I needed to do to get my project running...
(Note: You may not need to do all of these - it is a case-by-case thing)
If you did any changes from IIS Express to Local IIS you may need to change the build configuration from bin/debug to bin. (Right click on solution >> Properties >> Build >> Output)
If you have a URL rewrite then you will need to install URL rewrite on your Local IIS.
Navigate to your applicationhosts.config file (usually it's some place like C:\Users\username\Documents\IISExpress\config) and rename the file to applicationhostsOLD.config.
Clean and rebuild your project. You may need to go manually empty out the bin.
Now you should be good to go.
Since it was only happening with IISexpress, changing output from bin\Debug\ to bin\ solved it for me. Changing tag CodeBehind to CodeFile only created even more problems.
This happened with me on my local machine. The issue was incorrect IISExpres config.
If you are getting this issue on your local environment (Visual Studio debug runs), check the IIS Express config file. Make sure your local site/application path is pointing to the correct location.
The configuration file is called applicationhost.config. It's stored here:
My Documents > IIS Express > config . Usually (not always) one of these paths will work:
%userprofile%\documents\iisexpress\config\applicationhost.config
%userprofile%\my documents\iisexpress\config\applicationhost.config
It can't find the necessary file in dll assembly.
Rebuild the project, Rebuild the solution and then try it again.
I added a new build profile and that defaulted to output of
/bin/[new profile name] and when i was running debugger it was trying to look to just /bin
It's likely that you renamed something. Check the Global.asax.cs file for the class declaration and make sure that the namespace and class name match exactly what's in the asax file. This includes case! Can you copy/paste the namespace and class declaration of the .cs file into a post here so that we can compare?
Parser Error Message: Could not load type __
After doing everything suggested in the comments above, with no luck, refreshing (uploading) the contents of /bin to the server worked. The files uploaded to bin are the: dll, pdb and xml. Don't know which one did it.
The problem I had here was induced by renaming a file (_.aspx) in Solution Explorer.
Rebuilding/re-publishing my project/solution to the server did nothing to help me, and I doubt that will help that many out of this predicament. For me, I did a few things to troubleshoot this that eventually got me out of this "hole".
I had been trying to use a binding on the web site, but this wasn't working. I tried calling the site with http://localhost/Report.aspx (this was my homepage, which I opted to not call Default.aspx - I was going to update the "Default Documents" section with the name later) when I got the Parser Error the OP saw. So I tried some things:
I stopped the old project's website and built another, simple web project, that had "hello" and a label on the page and nothing else. I had a line in the Page_Load to populate the label's Text property with "world!", just to make sure that part was working. I created a new website on port 80 and transferred the published contents of my site to the server. So even though I had .NET 4.5 installed on the server (and had ran the aspnet_regiis -i command from the 4.0 directory) and the App Pool in IIS that I was using for this new project was set to 4.0, the browser complained about the web.config having a targetFramework=4.5.2 in it, which is Visual Studio 2015's default framework. So I installed .NET 4.6 (NDP46-KB3045557-x86-x64-AllOS-ENU.exe), restarted the server, and then my simple site worked. So then I deleted this site - all I wanted to do was prove my installation steps were accurate and the server could run a site.
So then I went back to my original project/site - I deleted and re-created the web site. I put the Application Pool to the one I had originally created for this, which I ensured was running .NET 4.0. Once I did this, I navigated to my site and everything worked when using http://localhost/Report.aspx. So it seems to me what causes this is what version of the .NET Framework you are using.
I tried all the solutions listed above and none of them worked. I finally created a new web page (webform) and copy blocked all the code (cs and aspx files) into it from the old one, deleted the old cs and aspx file, recompiled, and now I'm back in business. I know it makes no sense. It should not have mattered, but it worked.
Please try to open your project as Project/Solution, most probably it will resolve the error. This type of error Could not load type.... occurs when we try to open project as website.
I have tried to open my project as solution and it resolved my problem.
Please check namespace and class name at all places, In one case, One team member changed namespace and I was using old namespace in .aspx file. It was causing issue. I updated namespace and it got working.
I was fixing my namespaces in our Base Project, and I started seeing this error on another project that references it after that. I had to remove the reference to the Base Project and re-add it and then it started working again.
I just got this error today. It turns out that it was because I reverted by mistake the project file to an older version that didn't include the page anymore.
I had the same issue after renaming an aspx page Visual studio renamed it but dropped the namespace. Make sure the Inherits property contains the fully Qualified name including the namespace.
If you just added the new aspx File, rebuild the project it is located in. The problem comes from your Code Behind file that isn't compiled at the moment, therefore you want to access a newer page that doesn't exist in your current compiled project dll
I had this problem on the remote server, but not on my local server. After trying everything and nothing working, I finally resolved it. My domain name was pointing to a directory under another domain. I had originally built the website independently in Visual Studio as its own project. No matter what I did, it wasn't working anymore. So I moved it to a folder inside of the project for the main domain name and uploaded it as part of the main project.
For example, I have say domain name AAA.com with a website of its own. And then I also have BBB.com that points to a directory under AAA.com's main directory. Originally I had separate VS projects for AAA.com and BBB.com, but that wasn't working anymore. So I had to move all of BBB.com's files to the AAA.com project and set it up exactly like it appears on the remote server. For some reason, that worked.
Try This It will Definitely work :-
Parse Error:
May be you Class name is not matched with the webform name

Winforms Designer, C# Project with VC++ references, working directory issues

I'm working in a solution with ~100 project (of mixed C# Winforms, VC++ Winforms, and Unmanaged C).
I have a project, named 'DatafiltersControls' (C#), which has a references to a project named 'DatafiltersTypes' (VC++), shown below is the xml entry for the specific reference.
<ProjectReference Include="..\DatafiltersTypes\DatafiltersTypes.vcxproj">
<Project>{360679FF-815C-4B39-8E5A-62C0D2A6DB31}</Project>
<Name>DatafiltersTypes</Name>
<Private>False</Private>
</ProjectReference>
Now, the problem: "The designer will only load my controls under certain circumstances". After doing a lot of research, i've broken it down to my development environment, and the way I open my solution. My build environment is created from inside a dos window, which will subst a new drive (P:), mapped to a directory.
After my directory is created:
If my prompt is has "p:\common" as the current working directory, and type common.sln, all designers work great with no issue. This was the current working directory when I initially set that reference in the first place.
If I doubleclick on common.sln from explorer, and then try to open a 'complicated' form, I get the following error: Could not load file or assembly 'DatafiltersTypes, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified
If my prompt has "p:\" or any other directory as the CWD, and then invoke "p:\common\common.sln", the designer breaks on complex forms (same as above)
I believe the specific problem is this: my references where added relatively, based on the CWD when visual studio was opened. From that point on, the designer breaks on any 'complicated' form, because the search path is based on the cwd.
If needed, I can define 'complicated', I have the exact circumstances. My ideal solution would to allow my references to be based on the root of the drive (its a constraint developers at my company already have anyways). For instance, instead of
....\build\output\datafilterstypes.dll, I want \build\output\datafilterstypes.dll as my reference.
Its important to note that: Everything compiles just fine regardless of my working directory when I load devenv, its just the designer.
Thanks in advance.
Edit: To add, I have the same issues if the
The problem is the designer cannot load C++ dll's that aren't pure. Convert any project that will directly, or indirectly, a C++ dll to be pure.

WPF IOException Cannot locate resource

I have a WPF application.
The page that opens when the app runs in MainWindow.xaml, as set in the StartupUri attribute of the App.xaml file. This page opens fine.
However, if I try to open any other windows using the Show or ShowDialog method I get an IOException in the InitializeComponent method saying "Cannot locate resource 'Window1.xaml'" (or whatever the file is called). This happens with every single window I create. I've searched online but all the solutions seem to say "make sure the StartupUri attribute of the App.xaml is correct" and mine is, hence MainWindow opening.
Any idea what's going on?
The above did not work for me but what did work was as follows. Open up the App.xaml
<Application x:Class="dotDiff2013.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>
You then need to change the start-up URI to the fully qualified one. In my case I had moved my MainWindow.xaml to a folder called 'Main', so changing the above URI to
StartupUri="Main/MainWindow.xaml"
Solved my issue.
I had this problem when the "AssemblyName" and the "Default Namespace" on the project settings had the same value. Changing the AssemblyName to something else solved the problem.
If you open up the code-behind for the Window1.xaml file (i.e. Window1.xaml.cs), you can right click on the InitializeComponent method call and select "Goto Definition". There will be code like the following:
/// <summary>
/// InitializeComponent
/// </summary>
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
public void InitializeComponent() {
if (_contentLoaded) {
return;
}
_contentLoaded = true;
System.Uri resourceLocater = new System.Uri("/TestApp;component/mainwindow.xaml", System.UriKind.Relative);
#line 1 "..\..\..\MainWindow.xaml"
System.Windows.Application.LoadComponent(this, resourceLocater);
#line default
#line hidden
}
If the Uri in the code above is not correct, then you would receive that error you got.
In addition, if the Build Action of the XAML file is not set to "Page", then you would also have that problem. To check this, you can select the file in the Solution Explorer and press F4.
Finally, if something is renaming the XAML file as part of your build process (such as obfuscation), then again you would receive that error.
Other than that, I would try a "Clean Solution" and "Rebuild Solution" to ensure the file with the InitializeComponent definition is rebuilt.
I had the same issue. The reason for me because I moved the MainWindow.xaml without adjusting the the App.xaml. If you move your MainWindow.xaml for example into a folder called "UI" you have to adjust following line in the App.xaml
StartupUri="UI/Mainwindow.xaml"
<Application x:Class="RuleSetEditor.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="/Forms/RuleEditor.xaml">
<Application.Resources>
</Application.Resources>
</Application>
here /Forms/ is my folder structure in my project. Make sure this is mentioned in app.xaml
My issue was quite trivial:
The Build Action of my file was set to "None".
If you don't set it to "Resource" this will be the exception.
This IOException can be caused by assembly name ambiguity. For example, I named an assembly myproduct.dll, then added a reference to it in the WPF app myproduct.exe. This gave the IOException for mainwindow.xaml.
If this helps anyone, I was facing this problem without any obvious problem in the resource path. One thing was that I was using this in a WPF Control Library which was then referenced by the main application assembly.
I simply changed my simple URLs (i.e. file names) to pack:// URIs as everything started to work correctly. Like this:
Source="pack://application:,,,/MyLib;component/SettingsPage.xaml"
instead of:
Source="SettingsPage.xaml"
Check in App.xaml the StartupUri tag (if you moved the MainWindow).
Also if you happen to override OnStartup(StartupEventArgs e) in your app.xaml.cs you must also have to remove the line StartUri="mainwindow.xaml" from app.xaml.
Otherwise, you will get "Cannot locate resource 'MainWindow1.xaml'" as well in this case.
Even I had the same problem, first I went on digging up the issue still it was pointing to InitializeComponent(); I finally found out that I updated Resources.resx file contents, but in my application folder I did not updated it.
So later copied the new resx file and tried it. Now it works fine.
Just anyone in case come with this issue look at this once.
To resolve this issue please go to App.Xaml and change the StsrtUpUri which you want to run when the application run.
Change the startup Uri
And if the Xaml is inside any Folder you can add as follow
StartupUri="View/MyView.xaml"
Make sure you haven't accidentally moved the file MainWindow.xaml
Mine had somehow got dragged into Views by mistake - oops
Find the file app.g.cs and edit it in Notepad, in Visual Studio it will ask you to reload the file, click OK and voila​
Same issue but yet another solution:
For me my assembly name and default namespace were the same but different from the project name. I actually updated the default namespace and assembly name to match the new project name and it fixed it.
I noticed this problem after I localised my application. I ended up with a satellite resource which I did not include in my installer script. So while it worked in Visual Studio, building the installer separately caused this problem.
Including the satellite dll did the trick.
You may have renamed your namespace globally (entire project/solution etc.) or locally, but your solution obj\Debug folder some content (xaml classes, ending w/ [original_xaml_file_name].g.i.cs) did not take your changes. Next time make sure select "Entire Solution ( Including External Items )" if this was your case.
Simply go to Build and Then "Rebuild" and "Clean"

Embed multiple icons in WPF EXE

I have a WPF assembly in which I would like to embed five icons for different filetypes associated with my application.
How can I embed these icons into my EXE?
#smoore #Groky #ChrisF, thank you.
Unfortunately, this is not what I asked. I see that my question was quite vague 0_­°. Let me rephrase the question:
I have icons, say Application.ico, Document.ico, etc. as resources in my WPF projects. I access these icons in most cases with the following:
<Image Source="/MyAssembly;component/Resources/Icons/Application.ico" />
That works every single time. I know that.
What my question is about is how can I use the same icons from Windows Explorer for file associations in the registry. I want to be able to access the icons with a path like:
C:\Program Files\MyApp\MyApp.exe,1
Like in how icons are associated with filetypes in HKEY_CLASSES_ROOT.
AFAIK, I should use a resource file (.rc), compile and merge it with my EXE. Something along the lines of:
101 RT_ICON Application.ico
102 RT_ICON Document.ico
// etc...
Is this the right way in WPF? Is there an alternative, especially since this method seems to lead to the erasure of the assembly version from my AssemblyInfo.cs. I am still prepared to have to write the versioning info in the resource instead of the assembly's info.
I have found one solution! It's not perfect but it does what I want! As I used very long Scandinavian nights to find the solution, I feel that I have to share it here.
Here's what I did:
1) Wrote a dumb console C# app.
class ResTest {
static void Main() {
System.Console.WriteLine("Hello World!");
}
}
2) Did a simple csc restest.cs to test that my code worked.
3) Opened Notepad and wrote the following in a file I dubbed App.rc.
101 ICON "Application.ico"
102 ICON "Document.ico"
103 ICON "Help.ico"
4) Ran rc /v App.rc, the Resource Compiler. A new file, App.res had appeared.
5) Reran csc but this time:
csc /win32res:App.res restest.cs
6) restest.exe had now the icon with the ID of 101 and I could find the two other icons in Axialis IconWorkshop.
Now, I noticed that my assembly information (version, product name, blah blah blah) had disappeared. I googled VS_VERSION_INFO and came about MSDN's article about the VERSIONINFO structure which in RC files defines the attributes I need.
I would have preferred a more 'automated' method, but I must do what I can using the C# Express and the Windows Vista SDK.
-- Hope that you can use this...
Create App.rc:
101 ICON "Application.ico"
102 ICON "Document.ico"
103 ICON "Help.ico"
Compile:
rc App.rc
Add App.res to your project (leave None as your Build Action).
Build.
All done!
I've just created a simple tool to do exactly this without having to mess with .res files. (If you manage your own .res files you won't get a manifest and version resource created automatically). It is a tiny utility which you can use as part of your Post-Build event and lets you add all icon files in a particular folder to your assembly. If we assume that you have a icons folder under your main project folder you can add the following post-build event:
C:\path\to\InsertIcons.exe $(TargetPath) $(ProjectDir)icons
A further description and a download can be found at http://einaregilsson.com/add-multiple-icons-to-a-dotnet-application/
Project Properties -> Resources -> Add Resource -> Add New Icon/Add Existing File (depending on whether or not you've already made the icon)
In addition to adding the files to your project resources, you can add the files to your project and set their Build Action to resource.
You can then refer to the files from XAML using the Source property. For example a file Icon.png in a directory "Resources" would be loaded using:
<Image Source="/Resources/Icon.png"/>
And to load the file from code you would use:
new BitmapImage(new Uri(#"pack://application:,,,/Resources/Icon.png"))

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