Click here to Skip to main content
15,887,683 members
Home / Discussions / C#
   

C#

 
AnswerRe: sending the value of a parameter in a form to another form smart device Pin
Sandesh M Patil22-Apr-10 2:19
Sandesh M Patil22-Apr-10 2:19 
GeneralRe: sending the value of a parameter in a form to another form smart device Pin
bacem smari22-Apr-10 3:39
bacem smari22-Apr-10 3:39 
Questionstore the results of a WMI requests in a SQLite database Pin
hafsaben22-Apr-10 0:02
hafsaben22-Apr-10 0:02 
QuestionChanging the disposition of my listView.items in csharp smart device [modified] Pin
Tunisien8621-Apr-10 23:40
Tunisien8621-Apr-10 23:40 
AnswerRe: Changing the disposition of my listView.items in csharp smart device Pin
Tunisien8622-Apr-10 5:27
Tunisien8622-Apr-10 5:27 
QuestionCreating Database and assigning DataSet shema to the Data Source Pin
pandit8421-Apr-10 23:20
pandit8421-Apr-10 23:20 
AnswerRe: Creating Database and assigning DataSet shema to the Data Source Pin
Dave Kreskowiak22-Apr-10 6:21
mveDave Kreskowiak22-Apr-10 6:21 
QuestionHow to add XmlInclude attribute dynamically Pin
Anindya Chatterjee21-Apr-10 23:09
Anindya Chatterjee21-Apr-10 23:09 
I have the following classes

[XmlRoot]
public class AList
{
   public List<B> ListOfBs {get; set;}
}

public class B
{
   public string BaseProperty {get; set;}
}

public class C : B
{
    public string SomeProperty {get; set;}
}

public class Main
{
    public static void Main(string[] args)
    {
        var aList = new AList();
        aList.ListOfBs = new List<B>();
        var c = new C { BaseProperty = "Base", SomeProperty = "Some" };
        aList.ListOfBs.Add(c);

        var type = typeof (AList);
        var serializer = new XmlSerializer(type);
        TextWriter w = new StringWriter();
        serializer.Serialize(w, aList);
    }    
}


Now when I try to run the code I got an InvalidOperationException at last line saying that

The type XmlTest.C was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.

I know that adding a [XmlInclude(typeof(C))] attribute with [XmlRoot] would solve the problem. But I want to achieve it dynamically. Because in my project class C is not known prior to loading. Class C is being loaded as a plugin, so it is not possible for me to add XmlInclude attribute there.

I tried also with

TypeDescriptor.AddAttributes(typeof(AList), new[] { new XmlIncludeAttribute(c.GetType()) });


before

var type = typeof (AList);


but no use. It is still giving the same exception.

Does any one have any idea on how to achieve it?

QuestionCross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on. Pin
jkpieters21-Apr-10 22:59
jkpieters21-Apr-10 22:59 
AnswerRe: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on. Pin
Anindya Chatterjee21-Apr-10 23:12
Anindya Chatterjee21-Apr-10 23:12 
GeneralRe: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on. Pin
Jimmanuel22-Apr-10 0:58
Jimmanuel22-Apr-10 0:58 
GeneralRe: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on. Pin
Luc Pattyn22-Apr-10 1:32
sitebuilderLuc Pattyn22-Apr-10 1:32 
GeneralRe: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on. Pin
Luc Pattyn22-Apr-10 1:34
sitebuilderLuc Pattyn22-Apr-10 1:34 
AnswerRe: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on. Pin
Jimmanuel22-Apr-10 1:05
Jimmanuel22-Apr-10 1:05 
GeneralRe: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on. Pin
jkpieters22-Apr-10 1:21
jkpieters22-Apr-10 1:21 
GeneralRe: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on. Pin
Dave Kreskowiak22-Apr-10 2:11
mveDave Kreskowiak22-Apr-10 2:11 
GeneralRe: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on. Pin
Jimmanuel22-Apr-10 3:12
Jimmanuel22-Apr-10 3:12 
GeneralRe: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on. Pin
Anindya Chatterjee22-Apr-10 2:13
Anindya Chatterjee22-Apr-10 2:13 
Question2 tables in 2 DataGridViews on a single form Pin
shivapriyak21-Apr-10 22:51
shivapriyak21-Apr-10 22:51 
AnswerRe: 2 tables in 2 DataGridViews on a single form Pin
sanforjackass22-Apr-10 0:12
sanforjackass22-Apr-10 0:12 
GeneralRe: 2 tables in 2 DataGridViews on a single form Pin
shivapriyak22-Apr-10 0:54
shivapriyak22-Apr-10 0:54 
GeneralRe: 2 tables in 2 DataGridViews on a single form Pin
sanforjackass22-Apr-10 1:01
sanforjackass22-Apr-10 1:01 
GeneralRe: 2 tables in 2 DataGridViews on a single form Pin
shivapriyak22-Apr-10 20:07
shivapriyak22-Apr-10 20:07 
GeneralRe: 2 tables in 2 DataGridViews on a single form Pin
sanforjackass22-Apr-10 21:42
sanforjackass22-Apr-10 21:42 
QuestionMemory Issue Pin
abcurl21-Apr-10 22:45
abcurl21-Apr-10 22:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.