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 6582487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:17:10+00:00 2026-05-25T16:17:10+00:00

Suppose I have the following class: using System; using System.Collections.Generic; using System.Linq; using System.Text;

  • 0

Suppose I have the following class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NetworkSwitcher
{
    [Serializable]
    class testClass
    {
        public string str;

        public testClass(string _str)
        {
            this.str = _str;
        }
    }
}

Now when I try to execute the following, it throws a System.Windows.Markup.XamlParseException.

testClass tc = new testClass("Hello World");
XmlSerializer xsl = new XmlSerializer(typeof(testClass));
TextWriter WriteFileStream = new StreamWriter(@"C:\NSProfiles.xml");
xsl.Serialize(WriteFileStream, tc);
WriteFileStream.Close();

If I use a simple String type object instead of tectClass, the code works fine:

string data = "hello world";
XmlSerializer xsl = new XmlSerializer(typeof(String));
TextWriter WriteFileStream = new StreamWriter(@"C:\NSProfiles.xml");
xsl.Serialize(WriteFileStream, data);
WriteFileStream.Close();

So I guess the problem is in the class definition, how can I fix it? I am using WPF, not WinForms and I don’t have any prior experience in WPF or XMLSerialization. Let me know if I shall provide any other useful information.

  • 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-05-25T16:17:11+00:00Added an answer on May 25, 2026 at 4:17 pm

    To fix the error, add a default constructor to the class (a constructor that takes no arguments).

    Doing this alone will stop the error from happening, but may not serialize the string value correctly. I’m not 100% sure on that, as it may be able to serialize a public member variable.

    If not, you’ll want to add a public Property for the string value.

    A more “standard” implementation of this class would likely look like the following. You would either have a second constructor or just use the setter to set the value:

    [Serializable]     
    public class testClass     
    {         
        private string str;          
    
        public testClass()
        {             
        }     
    
        public string Str
        {
            get { return str; }
            set { str = value; }
        }
    } 
    

    Edit: Added the public modifier to the class. Should work now.

    Also, I am guessing you are calling the code that throws the exception in the constructor of the Window? That is the only reason I can see that this would throw a XAML exception. Errors in the constructor get wrapped in that XAML exception, so in these cases you want to look at the InnerException to find the problem.

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

Sidebar

Related Questions

Suppose I have the following class: public class TestBase { public bool runMethod1 {
Suppose I have the following class: class Camera { public Camera( double exposure, double
Suppose I have the following class: public class Foo { private List<Integer> list =
suppose I have the following class: class MyInteger { private: int n_; public: MyInteger(int
I'm using Google Guice for dependency injection. Suppose I have the following: public interface
Suppose we have the following class hierarchy: class Base { ... }; class Derived1
Suppose I have the following code: class some_class{}; some_class some_function() { return some_class(); }
Suppose I have the following declaration: class Over1 { protected: class Under1 { };
Suppose I have the following code: class siteMS { ... function __CONSTRUCT() { require
Let's suppose I have the following structure in my project (I'm using iBatis as

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.