Winform embeded XNA contentmanager only recognize XNB - c#

I'm writing a MapEditor in winform with embeded XNA.
And my biggest problem is whenever I try to load any file with the ContentManager, it only reads .XNB files.
I wanted to read an effect file like this:
effect = contentManager.Load<Effect>("Effect2");
But then I get the error that "Effect2.xnb doesn't exists".
And if I add "Effect2.fx" it still give me error with the message "Effect2.fx.xnb doesn't exists" :\
I have no idea what to do.
I saw a solution by set the content properties. But I cannot set those properties in this case,because it's a winform application.
Does anyone have a great idea or anything?
Edit!
Solution found!
I implemented the ContentBuilder from this example with writing a few helper methods for dynamic loading: http://create.msdn.com/en-US/education/catalog/sample/winforms_series_2

You'll have to add an XNA Content project, and include your content in that project. All of those files will be compiled/processed into individual XNB files, which you'll be able to load. Just make sure to reference that project in your WinForms project.
The same rules apply for a Game project: It still needs an accompanying Content project.
EDIT:
Ahh, right... you want to load them dynamically. For that, you'll need to ensure that any computer that tries to use your map editor will have the XNA development framework installed. Then you'll need to process the files manually before loading them with the ContentManager... not entirely sure how to do this.
EDIT:
Take a look at this post for more information about loading unprocessed content at runtime: How do I load a texture in XNA at runtime?

Related

The argument docData must implement the interface IVsTextStream ERROR after importing image as resource

I am coding a UserInterface for our ETO Autodesk CAD Software. This is done as a simple add on in C#. Effectively its a class Library DLL placed under a certain path.
Now at the point I need to show images in the user Interface I get this message: The argument docData must implement the interface IVsTextStream.
The code is not saving anymore and eventually the complete windows form is suddenly empty.
I try to use pictureBox or add the image directly on the tab of a tabcontrol. I used different file formats like png or bmp. Always the same Error.
Hope someone can help. Internet does not show anything.
Same Problem occurs to me for a windows application. I have searched for the same issue and find somewhere that "deleting resx file from the form may help you." Well, my issue was resolve after doing so.
Hope it will be helpful for you.
VS2019 (16.9.2) Got the The argument docData must implement the interface IVsTextStream
My case happens when importing new thing to resx. (Inserting an image to the form or control also counted as importing thing to resx) I compared my project the working one and noticed wrong file dependency, I made the following fixes:
Note that this is WinForm for .NET framework, not .NET core. When creating new project in VS there are 2 separated project templates:
"Windows Forms App (.NET Framework)" <- I'm using this one
"Windows Forms App" <- This one will be using newer gen of cross platform .NET family
My fix
I found that my resx was parented in wrong fashion. MainForm.resx should be parented (dependent upon) MainForm.cs
I found that my resx was associated with wrong tool. Correct one for my form's resx is 'blank'. Note that Custom Tool for application global Resources.resx should be PublicResXFileCodeGenerator
For OP's case of blank form after error dialog
I also suffered from this, and I has confirmed that the designer somehow confused and actually REMOVED all of your form contents. This cannot be undone, unless you have version control, sadly.

Monogame content pipeline tool failing to compile XML data to XNB

I'm new to the Monogame content pipeline tool, as opposed to XNA which would do the compiling you need on itself. So I may be having a pretty simple problem I fail to see a solution for. Here's my XML file:
<?xml version="1.0" encoding="utf-8"?>
<XnaContent xmlns:ns="Microsoft.Xna.Framework">
<Asset Type="Game1.Screens.SplashScreen">
<SplashScreen>
<Path>Images/Image1</Path>
</SplashScreen>
</Asset>
</XnaContent>
So I'm not entirely sure as of what <Asset Type="..."> wants as a value, but the debugger tells me there's an error there:
Could not resolve type 'Game1.Screens.SplashScreen'. So it's a simple tutorial I was watching:
The Tutorial
There the person decided to teach on how to use XML serialization. So he was using XNA but most of this code should work on Monogame as well. Anyway, what he did was, add a new XML file to a folder, outside of the Content.RootDiretory and added his XML file in there. Since I've never released a project with Monogame yet, so correct me if I am wrong, but won't that XML file that's set to Copy always to output directory be user-viewable/editable? Or will it be compressed into XNB? Or perhaps it won't be even presented there? So that is the problem's root, now let's see the top:
Being unable to answer to myself whether the XML file will actually be presented in the final product's Content directory, I decided to use the Content pipeline tool and add the above XML file from there as I was sure that it would be converted into XNB. But now I get this error. And I don't know where am I wrong? Should I set the file's build action from the default Build to Copy the error disappears, but the XML file will be in my Content directory instead of the XNB one. Please advice.
Here's some more information about the SplashScreen class:
It inherits from another class, GameScreen.
It is inside the Screens, folder inside the project's folder. That's why I tried to use Game1.Screens.SplashScreen, where Game1 is the name of my project.
Thanks in advance!
Your intuition is correct. The tutorial's version would have to ship the game with the xml file. But the Xna content pipeline can build it into a binary file for shipping your game and the runtime content pipeline can load it into your game.
when it loads it into your game, it needs to know what class the data will fit into so it can plug the data into an instance of that class
Class MyGameInitialConfiguration
{
public string path;
/*
other possible game settings can be added too
public float heroPower;
public string badGuyName;
*/
}
//then in the xml file
<asset type=MyGameInitialConfiguration>
Now, since the first thing the build process does when you hit run is build the assests (convert the fbx into xnb and the images into xnb and your xml into xnb), in needs to know what a "MyGameInitialConfiguration" is before you hit run... but if you add this class to the game project, it wont build the class until after it needs it and you will get an error.
So you actaully have to add an additional project to your solution to hold this class and make your game project and content project dependent on it so it is the first project to build. Then by the time the game project runs, it is aware of what a "MyGameInitialConfiguration" is and can load date into it.
Obviously, you can access that class instance from your game code and pull "path" from it.
Here is the end all for XNA knowledege: http://www.shawnhargreaves.com/blogindex.html
In particular, this blog: http://blogs.msdn.com/b/shawnhar/archive/2009/03/25/automatic-xnb-serialization-in-xna-game-studio-3-1.aspx
thank you for this question, took me back so many years. the Xna content pipeline was awesome.

Link images to a c# program [duplicate]

I don't know if I asked it right, but basically what happened is that I made a winform app which loads its image from the resource folder.
The problem is that when I build the project and get the exe and give it to a friend, he won't have that resource folder like I do, so he'll get an error saying missing file.
How can I somehow mix, or combine, or attach the image with my app?
You need to add it to the project by navigating to the Properties Window and going to the resource tab and adding the image from there.
Alternatively, from the PictureBox Control you can import resource from your computer.
if you don't need to update it in the future, compile your program with the image property build action set to embedded resource.
if you need to change it in the future compile with property build action set to content.

ContentPipeline at runtime in XNA?

Does anyone know of anyway to simulate the ContentPipeline in XNA at run-time?
It is my understand that the XNA Content Pipeline makes use of MSBuild at game compile time, which is obviously not redistributable (and definitionally not at run-time).
But if I have an fxb file, and can read the fxb format directly, is there any way to process the file "inline" at run-time, and just build a model myself rather than calling
Model m = Content.Load<Model>("resource name")?
Any help greatly appreciated. Thanks.
This sample on the app hub site does just that:
http://xbox.create.msdn.com/en-US/education/catalog/sample/winforms_series_2
Its associated with widows forms and xna, but you may glean the run time content processing out of it even if your not using winforms.

Unable to get WPF Sound Visualization Library working

I've recently begun work on an audio application using C#.NET. I've begun some basic implementation of the NAudio library which I intend to use throughout the project. While looking at NAudio's documentation on CodePlex I found a link to the WPF Sound Visualization Library, I was attracted by one of its features in particular which I knew I would require in my app.
So I downloaded and added it to my project References.
I've copied how it is referenced within a window's XAML document, like so:
xmlns:svl="clr-namespace:WPFSoundVisualizationLib;assembly=WPFSoundVisualizationLib"
and then tried to add a control within the library using:
<svl:WaveformTimeline x:Name="testWaveformTimeline"/>
The problem is that the designer/XMAL editor claims: "svl:WaveformTimeline" does not exist in namespace "clr-namespace:WPFSoundVisualizationLib;assembly=WPFSoundVisualizationLib".
Now I know that it does exist. I can make reference to the WaveformTimeline object in the class file, and the object shows up in Visual Studio's Object Browser.
I'm not at all sure why this is the case. If anyone knows any possible solutions to this, or things I should check any help would be appreciated.
I had the same issue and I just found the solution:
By right-clicking on the WPFSoundVisualizationLib .dll I had to 'unblock' the file which had been marked as 'unsafe' by windows because the file were coming from a WebSite. Weird but it was obviously the reason I couldn't use the WaveformTimeLine in my project. A bit late but maybe still worths to post it.
More info here: https://msdn.microsoft.com/en-us/library/dd409252(VS.100).aspx

Categories

Resources