XNA + Silverlight file not found - c#

This is embarrassing. It is a file not found problem with my XNA + Silverlight project.
I'm modifying the "My Little Teapot" XNA + Silverlight sample for Windows Phone 7, at http://msdn.microsoft.com/en-us/library/ff431744%28v=vs.92%29.aspx and am getting a File Not Found error in OnNavigatedTo() when I merely try to load a texture:
myTex = content.Load("tex1");
(You'll notice this isn't the usual file not found question where the coder is trying to load "tex1.png" instead of "tex1".)
My solution has the same project as in the sample, "sdkMyLittleTeapotCS", and a content project I added, "my content". I added "tex1.png" to the "my content" project, and its asset name is indeed "tex1". Its build action is set to "Compile", and I've tried setting the "Copy to Output Directory" settings to "Do not copy" (which is what works in my normal XNA projects) and also to "Copy if newer".
In all cases I get an exception with a file not found. What is this idiot doing wrong? Thanks in advance!

Shouldn't the build action be set to Content instead of Compile?

Shouldn't your code read :
myTex = content.Load<Texture2D>("tex1");

Remove the offending texture from your content project but do not delete it from disk. Then, drag it from an Explorer window back to your content project and make sure the name remains "tex1" - this will force the content project to recreate the associations to the texture - which those associations appear to be bad in their current form.

Probably you have the tex1 file in a subfolder. In this case you must provide the full path:
myTex = content.Load<Texture2D>("foldername/tex1");

Related

How to modify the `Original filename` property of a file [duplicate]

My understanding (which may well be faulty) is that it is easy to set the OriginalFilename property for a C++ DLL or EXE by including a VERSIONINFO resource file in the Visual Studio build.
But I can't find any way of setting OriginalFilename for a C# build. It is apparently always set to the name of the output file being built.
I'd really like to be able to specify this if possible. Any ideas? Thanks.
OK, no answers, and now I've found a workaround.
This article here at StackOverflow was very helpful:
How do I set the version information for an existing .exe, .dll?
Which led me to this resource manipulation project written in C#:
http://resourcelib.codeplex.com/
So what I'm going to do is to modify the DLLs after they've been built.
Edit (March 2015): This is an old posting, but I can see there is still some interest in it. The "ResourceLib C# File Resource Management Library" open source project has moved since four years ago, and is now here: https://github.com/dblock/resourcelib
Yes it is possible to set it,
-> right-click on the project or assembly name in visual studio -> select properties -> select Application tab -> change the assembly name as you want.
Please refer the link to view property window, in which assembly name option is there
After changing the name compile the project,(to verify the change) right click your compiled DLL file and select properties and click on 'Details' tab, in which you can see the 'original filename' is now changed.
Sadly, no.
You can read what it is with System.Diagnostics.FileVersionInfo.OriginalFilename, but the value is filled by the Project / Output Filename not from any Assembly Attribute.
Running your patch program to change it after a build runs the risk of breaking any digital signature applied during the build. You may need to build without signing, patch the attributes, then sign it in a separate step.

How To Fix Icon For InstallShield

I used to be able to create a setup project in Visual Studio, but now Microsoft has "improved" it and I'm wasting hours trying to get a simple project to someone else in my company. They need to upgrade their version of .NET or I wouldn't even use a setup. So after going through the pain of downloading their "improved" InstallShield and going through the pain of watching a video and setting all the parameters I tried to build the Setup project and it says the icon isn't valid. "Screw the icon. Let me deploy my project." The actual error message is "Cannot extract icon with index 0 from file ..." It doesn't matter to me if this uses a standard icon or no icon, I just want the user to be able to test this project.
So, what is the easiest way to get this setup project in the hands of my user?
I solved this problem by adding a new icon to the project and re-compiling. You can do this by right-clicking on the project and selecting Add -> New Item -> Icon File. Then assign that icon file under the Project -> Properties menu item.
Simple Solution:
At the time of Installation Wizard, while missing the reselection of
the Image / Icon for shortcut after we have browsed the resource path.
Missing this causes this index error (please refer screenshot). after
re-selection rebuild is required this solves problem.
Simple way to fix this error :
Right click on your project- go to properties-application tab-in application tab set icon to your project in Icon & Manifest option

Could not load content1.png asset as non content file

When trying to import an image into my 'game' I get a error message. The one displayed in the title. it is called content1.png and is in the Content folder. I have
public override void LoadContent()
{
base.LoadContent();
path = "Content/content1.png";
splash1 = content.Load<Texture2D>(path);
}
and it doesn't load it.
I have no idea what to do here.
It's seems like the content.Load<Texture2D> method tries to open the file from your File-System and it is not founded there, do the following to solve it:
In Visual Studio -> Right-Click on the content1.png file -> Select Properties ->
Set the Build-Action to "Content" in the properties window for
content1.png.
Set the Copy to Output Directory to -> Always
While the accepted solution didn't work for me, I finally figured out that it was the relative path of the asset that was creating problems, so changing
Content.Load<Texture2D>("Graphics\\MyAsset.png")
to
Content.Load<Texture2D>("..\\Graphics\\MyAsset.png")
did the trick for me.
In MonoGame 3.5.1 you must use MonoGame pipeline tool for your resources, and include builded *.mgcb file to your content folder in project. See sample project Platformer2d.
MonoGame pipeline tool
http://www.monogame.net/2016/03/17/monogame-3-5/
Samples https://github.com/MonoGame/MonoGame.Samples

Can't get content to load using Monogame with VS2012

My code is
new GameFont(Content.Load<SpriteFont>("LoadingFont"), "LoadingFont")
According to what I've read, you have to use VS2010 to compile your assets into .xnb format, which I have done, and place them into the Content subfolder in your bin directory, which I have also done. However, I get an error saying "Could not load LoadingFont asset!".
I'm not really sure what else to do. I read a very old post saying that assets made using XNA 4 won't work, but I don't know if that's still true, or how to change my version of XNA to 3.1.
Any ideas? Perhaps there's a better way without using VS2010 at all?
Have you added the content to the Content folder of your project and set the Build Action to Content (in the properties window).
I'm not exactly sure what the process is to use assets in the .xnb format. I know it can be done that way but I normally just add the raw image and sounds files to my Content folder directly. Font's might be a little trickier to do that way though.
EDIT: 2015
A lot of things have changed since this question was written. These days MonoGame has it's own Pipeline tool for processing content into XNB files. The first thing to try would be to process your SpriteFont using the new Pipeline. This way you can avoid the need to depend on XNA altogether.
Alternately, another way to get around font issues in MonoGame is to pre-render them to a texture using the BMFont tool and use MonoGame.Extended to render them in your game.
Once you've installed MonoGame.Extended you can load fonts created with BMFont just as you would a SpriteFont but using the BitmapFont class instead.
_bitmapFont = Content.Load<BitmapFont>("my-font");
Then render some text like so:
_spriteBatch.Begin();
_spriteBatch.DrawString(_bitmapFont, "Hello World", new Vector2(100, 200), Color.Red);
_spriteBatch.End();
I have a full tutorial on my blog
I've been using MonoGame in VS2012 with no trouble; Content.Load<T>("myContent") still works for me. One thing that has been catching me out lately (tip: don't code when sleep-deprived) is that you have to check your assets are set to "Copy to output directory" in Solution Explorer, or else when the game builds, the assets won't go with it, which is why you get that error - it can't load what isn't there! Right-click on your assets and look under Properties. If they're set to "Do not copy" then you'll want to change that.
Like #craftworkgames I can't give you a full answer. But the traditional Content Pipeline that came with XNA 3.1 has gone in 4. So any assets need loading a slightly different way. For example, to load a .png asset to display a sprite I do the following:
rock = Texture2D.FromStream(GraphicsDevice, TitleContainer.OpenStream(#"Rock-Large-Stones-PT.png"));
and add the .png file to the solution as normal. I'm pretty sure it's going to be something similar for fonts but I haven't quite figured it out yet either ;)
I was having the same issue not sure if you got it resolved or not but here is what I did.
Click on the Monogame Content Pipeline under the "Content" folder.
Add in your spritefont or texture.
Make sure in the Monogame Content Pipeline that you change the action from "Build" to "Copy"
Then when you want to load the content simply;
texture = content.Load("texture.png");
Hope this helps :)
I had similar problem but with 'Windows 8 Store' as a target platform... while everything was fine with Windows Open GL version.
On Windows 8 I received "could not load as a non-content file" when I tried content.Load("Fonts/TestFont").
I replaced MonoGame DLLs in my solution with the MonoGame.Windows8 project (I downloaded the sources from CodePlex) and I did some debugging... and found out that MonoGame looks for the Content folder in the bin...\Debug\AppX folder... while during the build the Content folder is copied into different place. So when I manually copied the Content folder into AppX folder, the error has gone and my game prototype works fine now.
I guess I either missed some setting in the Project preferences related to AppX (Presumably this folder is needed for the Windows 8 device emulator?) or... MonoGame should look for the Content folder in different place... Anyway I will be renewing the Content folder manually for now because it is copied into wrong place during the compilation.
I have Content folder in my project and build action is set correctly (Content)... and 'Copy always' is chosen but during the build (compliation) that Content folder is copied to Debug folder while it should be copied to Debug\AppX folder otherwise MonoGame can't find it.
(I maybe wrong with exact paths because I am currently at work and the issue is at my home PC)
Maybe it is just some configuration issue in my Visual Studio 2012.
Hope this information helps.

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