Custom Importer / Reader / Writer not working

Hello,

i know this has been discussed several times now on the internet, and I also found most of them and i tried everything but I was still not able to fix that. And it´s really starting to piss me of right now i am looking for the issue for more than 4 days now. I dont get what the hell i am doing wrong, i followed several tutorials now, even video tutorials but always something doesnt work or it ends up in “just” the error: Unable to load asset as a non content file whilst the inner exception says it cannot find the contentreadertype type or something like that.

HERE

is my project, it consists of a Shared Project which contains the content file (mgcb) and it gets referenced by the DesktopGL and Android project.

You will see its not much in there yet because i started with adding that Custom Content Reading stuff into my game.

I hope there are some ppl. willing to help me :slightly_smiling:

Simply what i want to do is, creating an importer for an xml file basically but with another file type ending.

The sample in the project attached is a menu importer / reader / writer.

I have a simple class Menu where i store for now basic values.

I dont know what the problem is, maybe you guys can track this down.

Edit: I will explain the structure a little:

I have a DesktopGL project
I have an Android project
I have a Shared Project which gets referenced by the DesktopGL and Android project. It contains the class Menu, which is the class i want to get from Content.Load(…) when loading my menu file. And the MenuReader class.
The SharedProject should btw. also contain all the game logic code later so that i just need to call the game code
in each platform project.
Last project is Content Pipeline Extension project which contains Writer and Importer, and it references the Shared Project to have access to the Menu and the Menu Reader.

Like this everything should be fine because the Desktop and android only references required classes and not also the content pipeline extension library.

Now my classes:

MenuReader (located in the Shared Project):

public class MenuReader : ContentTypeReader<Menu>
{
    protected override Menu Read(ContentReader input, Menu existingInstance)
    {
        return input.ReadObject<Menu>();
    }
}

Importer (located in the pipeline library project)

[ContentImporter(".mnu", DisplayName = "Menu Importer - Teraxia.ContentPipeline")]
public class MenuImporter : ContentImporter<Menu>
{
    public override Menu Import(string filename, ContentImporterContext context)
    {
        Menu menu = null;

        var serializer = new XmlSerializer(typeof(Menu));
        using (var reader = new StreamReader(filename))
            menu = serializer.Deserialize(reader) as Menu;

        return menu;
    }
}

Writer (located in the Pipeline Extension library project)

public class MenuWriter : ContentTypeWriter<Menu>
{
    public override string GetRuntimeReader(TargetPlatform targetPlatform)
    {
        return typeof(MenuReader).AssemblyQualifiedName;
    }

    public override string GetRuntimeType(TargetPlatform targetPlatform)
    {
        return typeof(Menu).AssemblyQualifiedName;
    }

    protected override void Write(ContentWriter output, Menu value)
    {
        output.WriteObject(value);
    }
}

and the model Menu class (located in the Shared Project as well)

[XmlRoot]
public class Menu
{
    
    [XmlArray]
    public MenuItem[] MenuItems { get; set; }
    
}

public class MenuItem
{
    
    [XmlElement]
    public string Label { get; set; }

    [XmlElement]
    public string Operation { get; set; }

}

Thanks in advance.

I’m not exactly sure what you mean by this?

A file that doesnt end with .xml but with .mnu. But its still an Xml file which i can deserialize with the XmlSerializer.

ok. I’ve just never heard of that done before. Is that normally done? I mean, are you certain that’s even possible?

-And on that note, if I can ask you, why would one need to use mnu over xml ?

Yes this is definately possible, there are classes in the framework that allows you to create custom content files.
Basically what i wanna do is exactly this, creating custom contents for my game.

It might be a little advanced topic but its definately well known.

To answer your question: Its much more comfortable if you can define your own content files. You can store data the way you want and let them load predefined.

I’m on mobile, so I can’t really check out your project, but I can guess.

Are the name of your reader and writer the same except for their respective suffix, i.e. XReader and XWriter where X can be anything? If not you’ll want to override GetRuntimeReader in the writer so MG knows what reader should be used for content written with that writer. The second thing I can think of is that the game needs to reference the dll with the reader.

I edited the main post and added the classes + structure of my project :slight_smile:

Hey, i am still having this issue.

I got my main project (which is the game) and it contains a class MapData that i want to import.
There is another project which is for the extension which provides Extension Writer, Importer and Processor.
The Extension Project references the game project because the game project contains the type to be imported/processed.

I have finished my extension project now, and when i add this dll in the content pipeline as reference, neither the processor or the importer is showing up. What is the problem?