Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8259153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:47:36+00:00 2026-06-08T02:47:36+00:00

I have written an Interface for writing a very very simple Plugin. In fact

  • 0

I have written an Interface for writing a very very simple Plugin. In fact it is just a class that is loaded at runtime out of a dll file and is stored as Property in another class. That class that stores the interface has to get serialized. As example this is my serialized object:

<?xml version="1.0" encoding="utf-8"?><MD5HashMapper xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.namespace.net" />

But now If i want to load that Object I get an Exception:
As example :

{"<MD5HashMapper xmlns='http://www.vrz.net/Vrz.Map'> was not expected."}

So does anyone has an idea how to solve that problem?

Code:
I have an Interface named IMap that is shared in a dll file to create Addins based on that interface:

public interface IMap
{
    object Map(object input);
}

I also have different Mappers (you can pass an input through them and they modify the output). All Mappers are derived from:

[XmlInclude(typeof(ConstMapper))]
[XmlInclude(typeof(FuncMapper))]
[XmlInclude(typeof(IdentMapper))]
[XmlInclude(typeof(NullMapper))]
[XmlInclude(typeof(RefMapper))]
[XmlInclude(typeof(VarMapper))]
[XmlInclude(typeof(TableMapper))]
[XmlInclude(typeof(AddinMapper))]
public class MapperBase:ComponentBase,IMap
{        public virtual object Map(object input) {
        throw new NotImplementedException("Diese Methode muss überschrieben werden");
    }

    public override string ToString() {
        return ShortDisplayName;
    }
}

Just forget ComponentBase. It is not important for this…

Now i also have a AddinMapper. The main function of that mapper is to cast create MapperBase Object out of the IMap object:
And that is exactly that class I want to seralize including the properties of the Mapper Property (type IMap).

    public class AddinMapper : MapperBase
{
    private static MapperBase[] _mappers;
    const string addinDirectory = @"Addin\Mappers\";

    //Mappers from *.dll files are loaded here:
    [XmlIgnore]
    public static MapperBase[] Mappers
    {
        get
        {
            if (_mappers == null)
            {
                List<MapperBase> maps = new List<MapperBase>();
                foreach (string dll in Directory.GetFiles(addinDirectory, "*.dll"))
                {
                    if (Path.GetFileName(dll) != "IMap.dll")
                    {
                        var absolutePath = Path.Combine(Environment.CurrentDirectory, dll);
                        Assembly asm = Assembly.LoadFile(absolutePath);
                        foreach (Type type in asm.GetTypes().ToList().Where(p => p.GetInterface("IMap") != null))
                        {
                            maps.Add(new AddinMapper((IMap)Activator.CreateInstance(type)));
                        }
                    }
                }

                Mappers = maps.ToArray();
            }
            return _mappers;
        }
        set
        {
            _mappers = value;
        }
    }

    IMap _base;

    public string MapperString { get; set; }

    [XmlIgnore()]
    public IMap Mapper
    {
        get
        {
            if (_base == null)
            {
                Type type = null;
                foreach (MapperBase mapperBase in Mappers)
                {
                    if (mapperBase is AddinMapper && ((AddinMapper)mapperBase).Mapper.GetType().FullName == _mapperName)
                    {
                        type = (mapperBase as AddinMapper).Mapper.GetType();
                        break;
                    }
                }
                if (type != null)
                {
                    XmlSerializer serializer = new XmlSerializer(type);
                    using (StringReader reader = new StringReader(MapperString))
                    {
                        Mapper = (IMap)serializer.Deserialize(reader);
                    }
                }
            }
            return _base;
        }
        private set
        {
            _base = value;
            StoreMapperString();
        }
    }

    string _mapperName;

    [System.ComponentModel.Browsable(false)]
    public string MapperName
    {
        get
        {
            return _mapperName;
        }
        set
        {
            _mapperName = value;
        }
    }

    public AddinMapper(IMap baseInterface) : this()
    {
        Mapper = baseInterface;
        _mapperName = baseInterface.GetType().FullName;
    }

    public AddinMapper() 
    {
    }

    public override object Map(object input)
    {
        return Mapper.Map(input);
    }

    public override string ToString()
    {
        return Mapper.ToString();
    }

    private void StoreMapperString()
    {
        MemoryStream memstream = new MemoryStream();
        XmlStore.SaveObject(memstream, Mapper);
        using (StreamReader reader = new StreamReader(memstream))
        {
            memstream.Position = 0;
            MapperString = reader.ReadToEnd();
        }
    }
}

An example for such a addin would be:

    public class ReplaceMapper : IMap
{
    public string StringToReplace { get; set; }
    public string StringToInsert { get; set; }
    public object Map(object input)
    {
        if (input is string)
        {
            input = (input as string).Replace(StringToReplace, StringToInsert);
        }
        return input;
    }
}

And the Problem is I want to save the Settings like StringToReplace,… as xml

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T02:47:38+00:00Added an answer on June 8, 2026 at 2:47 am

    I ve solved my problem:
    I really don t know why but take a look at this article: http://www.calvinirwin.net/2011/02/10/xmlserialization-deserialize-causes-xmlns-was-not-expected/
    (if link is dead later)

    XmlRootAttribute xRoot = new XmlRootAttribute();
    xRoot.ElementName = elementName;
    xRoot.IsNullable = true;
    
    
    XmlSerializer ser = new XmlSerializer(typeof(MyObject), xRoot);
    XmlReader xRdr = XmlReader.Create(new StringReader(xmlData));
    MyObject tvd = (MyObject)ser.Deserialize(xRdr);
    

    Now the important thing: It does not matter if you don t get an excption on serialization. You have to add the XmlRootAttribute on both ways: Serialisation and Deserialization.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a third-party (Win32) DLL, written in C, that exposes the following interface:
I have a utility class library I am writing. A have written a factory
I am writing a simple plugin system for my .NET app written in C#.
I have question to ask. I have a dll file written for reading&writing data
I have written a java annotation that looks like this: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) // can
Is it good idea to have application engine written in c++ and user interface
I have written a set of classes and interfaces that are implemented in Moose
have written this little class, which generates a UUID every time an object of
I have written a function that sorts a big scale of data. To test
I'm writing a graphical user interface to plot data on a xy-axis. It's written

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.