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

  • SEARCH
  • Home
  • 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 6194509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:18:31+00:00 2026-05-24T03:18:31+00:00

here is my class to serialize/deserialize. public class MyDic { … [XmlElement(IsNullable = true)]

  • 0

here is my class to serialize/deserialize.

public class MyDic
{
    ...

    [XmlElement(IsNullable = true)]
    public List<WebDefinition> WebDefinitions;                      

    ...
}

and it’s a full definition of the struct WebDefinition.

public struct WebDefinition
{
   public string Definition;
   public string URL;

   public WebDefinition(string def, string url)
   {
       Definition = def;
       URL = url;
   }
   public override string ToString() { return this.Definition; }
}

i expected Dictionary.WebDefinitions can nullable when deserialzation. but it occured a runtime error when

//runtime error : System.InvalidOperationException
XmlSerializer myXml = new XmlSerializer(typeof(Dictionary), "UOC");

why i can’t use XmlElementAttribute.IsNullable?

note1:

when i delete a line [XmlElement(IsNullable = true)], it works properly with no error.(serialization and deserialization).

note2:
exception is System.InvalidOperationException and message is : "error occured in during reflection 'UOC.DicData' type"

thanks.

  • 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-24T03:18:31+00:00Added an answer on May 24, 2026 at 3:18 am

    As I indicated in the comment “and in particular the InnerException”; since you didn’t add this, I ran the sample, and the innermost InnerException is:

    IsNullable may not be 'true' for value type WebDefinition. Please consider using Nullable<WebDefinition> instead.

    That tells you everything you need, I think. Changing it to WebDefinition? (aka Nullable<WebDefinition> does indeed fix it.

    But key point here: read the exception and the InnerException.

    IMO, a better “fix” here is to make it a class; since WebDefinition is not a “value”, it has no business being a struct
    (and in particular a struct with public mutable fields is … evil):

    public class WebDefinition
    {
        public WebDefinition(){} // for XmlSerializer
        public string Definition { get; set; }
        public string URL { get; set; }
        public WebDefinition(string def, string url)
        {
           Definition = def;
           URL = url;
        }
        public override string ToString() { return this.Definition; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my class: public class Command { [XmlArray(IsNullable = true)] public List<Parameter> To
Here's my code: [Serializable()] public class Project { private List<string> _Kinds = new List<string>();
Here is my code: public static class SerializationUtil { public static string Serialize(object obj)
Here's my code: class Publisher(models.Model): name = models.CharField( max_length = 200, unique = True,
Here's my binding source object: Public Class MyListObject Private _mylist As New ObservableCollection(Of String)
here is my example code: Public Class Parent Private _TestProperty As String Private WithEvents
Here are the domain model classes: public abstract class BaseClass { ... } public
Here is a VB.NET code snippet Public Class OOPDemo Private _strtString as String Public
Here's a simplified version of my class: public abstract class Task { private static
Here is the domain that I wish to have: public class Person { public

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.