bug in XmlSerializer.FromTypes()?

It seems that XmlSerializer.FromTypes() method cannot handle inner class 
properly .. or is there anything I did wrong?

The following code will throw a reflection exception at FromTypes() method.  
Is there a work-around?


using System;
using System.Xml;
using System.Xml.Serialization;

namespace My
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class Class1
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {

            try
            {
                Console.WriteLine("-- This is OK.---");
                XmlSerializer s1 = new XmlSerializer(typeof(T));
                XmlSerializer s2 = new XmlSerializer(typeof(X));

                Console.WriteLine("--- This will throw exception! ---");
                XmlSerializer[] s3 = XmlSerializer.FromTypes(new Type[] 
{typeof(T), typeof(X)}); // use My.T result in same problem
            }
            catch(Exception e)
            {
                Console.WriteLine("=========================");
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Console.WriteLine("=========================");
            }

            Console.Write("Enter any key to continue ..");
            Console.In.Read();
         }
    }

    [XmlRootAttribute("T")]
    public class T
    {
        [System.Xml.Serialization.XmlElement("myU", Type = typeof(U))]
        public U myU;

        [System.Xml.Serialization.XmlRootAttribute("U")]
        public class U
        {
            [System.Xml.Serialization.XmlElement("name")]
            public string name;
        }
    }

    [XmlRootAttribute("X")]
    public class X
    {
        [System.Xml.Serialization.XmlElement("myU", Type = typeof(U))]
        public U myU;

        [System.Xml.Serialization.XmlRootAttribute("U")]
        public class U
        {
            [System.Xml.Serialization.XmlElement("Xname")]
            public string name;
        }
    }
}
0
XingZhou (2)
11/8/2004 4:01:32 PM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
511 Views

Similar Articles

[PageSpeed] 57

Sorry for not making myself clear :-)  The problem is not inner class, 
instead, it's about the "duplicated" classnames even if the classes are in 
different scope.  In the code sample I gave, the issue is that both T and X 
have an inner class called U.  In fact, if I rename any of the two Us, the 
code will work happily.


"Xing Zhou" wrote:

> It seems that XmlSerializer.FromTypes() method cannot handle inner class 
> properly .. or is there anything I did wrong?
> 
> The following code will throw a reflection exception at FromTypes() method.  
> Is there a work-around?
> 
> 
> using System;
> using System.Xml;
> using System.Xml.Serialization;
> 
> namespace My
> {
>     /// <summary>
>     /// Summary description for Class1.
>     /// </summary>
>     class Class1
>     {
>         /// <summary>
>         /// The main entry point for the application.
>         /// </summary>
>         [STAThread]
>         static void Main(string[] args)
>         {
> 
>             try
>             {
>                 Console.WriteLine("-- This is OK.---");
>                 XmlSerializer s1 = new XmlSerializer(typeof(T));
>                 XmlSerializer s2 = new XmlSerializer(typeof(X));
> 
>                 Console.WriteLine("--- This will throw exception! ---");
>                 XmlSerializer[] s3 = XmlSerializer.FromTypes(new Type[] 
> {typeof(T), typeof(X)}); // use My.T result in same problem
>             }
>             catch(Exception e)
>             {
>                 Console.WriteLine("=========================");
>                 Console.WriteLine(e.Message);
>                 Console.WriteLine(e.StackTrace);
>                 Console.WriteLine("=========================");
>             }
> 
>             Console.Write("Enter any key to continue ..");
>             Console.In.Read();
>          }
>     }
> 
>     [XmlRootAttribute("T")]
>     public class T
>     {
>         [System.Xml.Serialization.XmlElement("myU", Type = typeof(U))]
>         public U myU;
> 
>         [System.Xml.Serialization.XmlRootAttribute("U")]
>         public class U
>         {
>             [System.Xml.Serialization.XmlElement("name")]
>             public string name;
>         }
>     }
> 
>     [XmlRootAttribute("X")]
>     public class X
>     {
>         [System.Xml.Serialization.XmlElement("myU", Type = typeof(U))]
>         public U myU;
> 
>         [System.Xml.Serialization.XmlRootAttribute("U")]
>         public class U
>         {
>             [System.Xml.Serialization.XmlElement("Xname")]
>             public string name;
>         }
>     }
> }
0
XingZhou (2)
11/8/2004 4:34:15 PM
Reply:

Similar Artilces:

Bug Reporting
I have tried to use the support links to report various bugs in Entourage and Office but always get a message saying support on Entourage has been or is about to be discontinued - even though the thoughtfully provided product lifecycle link http://support.microsoft.com/lifecycle/search/?sort=PN&alpha=Entourage&x=12&y=10 shows that Entourage is supported until 2008. It also seems obvious, due to the number of unresolved posts on here, that Microsoft do not monitor this forum effectively. I cannot find any way of reporting a problem by email. I was offered a toll-free number to ca...

Real strange symptom.. Big Exchange bug of 2005?
Current setup: Exchange SBS 2003, Outlook 2003 Setup date: around Sept this year Hi all, i face a really really strange situation. I have some rules setup already to put dedicate user, e.g., Michael Jordan, to a folder "Jordan". Therules work well that put email from MJ to folder Jordan but today i found 3 emails from MJ sent few days before is not work. Instantly i trigger the rule manually "Run rule now" so that the email from MJ put back to folder "Jordan" although i m not sure why email does not follow the rule. BUT, the strange is, even i "Run rule now...

The word "confirmation" causes a bug in e-mail
Our company has noticed that if one types the word "confirmation" in the subject line then tabs to the message, Outlook will start to initiate a series for "enter" commands (it appears) and then one has to end the Outlook Task in order for it to cease. Has this happened in other companies? -- If it ain''''t broke...I''''m still working on it. DonMark <DonMark@discussions.microsoft.com> wrote: > Our company has noticed that if one types the word "confirmation" in > the subject line then tabs to the message, Out...

Help Bug: "Track a paycheck to reflect deductions"
Track a paycheck to reflect deductions Before you edit a recurring paycheck deposit to reflect deductions, have a paycheck stub handy. -------------------------------------------------------------------------------- Note: To perform this advanced task, you must be using Advanced Bills. To find out if you’re using Advanced Bills, look for the Essential Bills or Advanced Bills label in the upper-right corner of the Bills summary page. Go to the Bills summary page. If you're using Essential Bills, you must switch to Advanced Bills to perform this task. In the left pane under Other tas...

Small BUG in Outlook 2000
We found a small bug in outlook 2000 user interface. Its just a display issue.How do we submit this to microsoft. Thanks "ksheeraj&upkar" <ksheera.kumud@kla-tencor.com> wrote in message news:02a501c3dbb1$547eb430$a501280a@phx.gbl... > We found a small bug in outlook 2000 user interface. > Its just a display issue.How do we submit this to > microsoft. > Thanks > As they've released Outlook 2002 and now Outlook 2003 is it worth it? Will MS fix a "small display bug" in something two generations old? I don't think so! You are wasting your...

a bug in ms access??
Dear all, I try to convert a string to date in ms access 2003, use the function ##. ? #25-2-2008# the result is 25-2-2008 ? #2-3-2008# the result is 3-2-2008 is this a bug in the access or am i something wrong? Thanks in advance for any help Regards, Yan Zhou Not a bug, but a trap For an understanding of how Access understands the dates you enter, see: International Date Formats in Access at: http://allenbrowne.com/ser-36.html -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than alle...

Default Site ID bug?
I have run across an issue in GP 10 which seems like a bug, but I'm looking for some confirmation one way or the other. Here are the steps to reproduce the problem: - Create a sales order via the Sales Transaction Entry window. Use a customer whose default shipping method has a shipping type of pickup. - Use a Default Site ID called WH1 that has a tax schedule called TAXSCH1. TAXSCH1 should have a single tax detail called TAXDET1 with tax of 10%. - Enter a freight charge of $100. Be sure freight tax option is Base On Customers. - You should see $10 tax, as expected. - Change the ...

Odd behaviour: A bug?
Could someone explain me the reason the formula: =SUM(IF($C$7:$C$18<=$E $3;$D$7:$D$18;0)) gives different results when placed in 2 different places? To replicate the problem: -Fill C7:C18 with dates, for example from 01/01/2009 to 01/12/2009 -Fill E3 with 01/11/2009 or any other date -Fill D7:D18 with numerical values -Fill E6:E19 with this formula: =SUM(IF($C$7:$C$18<=$E$3;$D$7:$D $18;0)) What I get: -In E6 and E19 the result is #Value! -In E18 the result is 0 -In E7:E17 the result is the correct sum (the expected behavior). Any enlightenment on this?? I would really appreciate yo...

Like search in SQL server 2008 x64 BUG?
I am having problem with a like search in SQL server 2008. It works in x86 but not in x64. The server has collation Sami_Sweden_Finland_100_CI_AS Steps to reproduce: SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON SET ANSI_PADDING ON GO CREATE TABLE dbo.forsakringsgivare2( namn varchar(40) COLLATE Sami_Sweden_Finland_100_CI_AS NOT NULL ) GO CREATE TABLE dbo.forsakringsgivare3( namn varchar(40) COLLATE Finnish_Swedish_CI_AI NOT NULL )GO insert into forsakringsgivare2 values('L�nsf�rs�kringar') insert into forsakringsgivare3 values('L�nsf�rs�kringar') --this...

BUG: New emails dont show in inbox
Outlook 2007 has been a dog so far. Slow performance on a very fast mahcine, addins that dont work, and now the worst of them all - new messages to my inbox show as being there but do not appear if I'm looking at my inbox. So for example, I've got 3 folders - inbox and then two other subfolders "business" and "farming." My view is on inbox itself. I hit send/receive and I'll get messages. I'll have 2 new messages in inbox, which is bold, but i cannot see them. I have to click on business or farming to view that folder and then when I click back to inbox they...

XmlSerializer crashes on instantiation
I ran into a bizarre crashing of one of my programs earlier today, and noticed my IE 6 was messed up (maybe this is important, maybe it isn't, but it coincided with this not working). After fixing IE 6 by uninstalling Google Toolbar, this bug remains. Whenever I instantiate XmlSerializer, i.e.: XmlSerializer x = new XmlSerializer(typeof(UIFA)); (including creating a console program JUST to run that one line of code, and to have a blank, qualified class to serialize) I get: System.IO.IOException: The directory or file cannot be created. Here is some bonus Stack Trace: at System.I...

Bug in CString-operator += ?
Hi, Sometimes the use of '+=' to concatenate a new string to the end of a CString leads to an unexpected result: For example: In a function I have the following code: ........ CString fnaam("JOS"); fnaam+=".INI'; ...... The result should always be "JOS.INI", but in some cases the result is an empty string: "" This happens typically at the 46th time I call the function. If instead I use the following code in my function: ........ CString fnaam("JOS"); CString ini(".INI"); fnaam+=ini; ...... the error does not occur. ...

Recover Deleted Items Bug?
Can someone tell me if this is a bug. When you have the policy, "Empty Deleted Items folder upon exiting" turned ON your recovered deleted items does not work. When the policy is OFF it works. Can someone from MS tell me if there is a fix for this or what might be happening? We are running in cached mode. If you are not in cached mode it works all the time. When in cached mode we have the problem listed above. Thanks in advance Sounds like you don't have the server set to retain deleted items. Check the Exchange Server Administration and verify that you have it turned on and ...

word 2007 content controls bug?
I have a form where I'm using the rtf-controls and the Active-X checkbox control. When I protect the form, everything works fine until I've checked a checkbox. Then the rtf-controls stop working. Why is that? Avoid combining different kind of controls. -- Stefan Blom Microsoft Word MVP "Asa Cronqvist" <asa@lexiconsult.se> wrote in message news:916674a6-f81b-4a05-9058-404b3a1073eb@o30g2000yqb.googlegroups.com... >I have a form where I'm using the rtf-controls and the Active-X > checkbox control. When I protect the form, everything works fi...

Bug Submission: Microsoft Office for Mac (All Versions) VB Bug
Howdy, I am posting this bug here with hopes of a fix. The bug is present in all versions of Microsoft Office for Mac. If the User's Home directory is located *anywhere* else other than the same drive that Office is launched from, certain VB functions will not work. Scenario: User is managed by Apple's Workgroup Manager. Their home directory is on a remote server. User successfully launches Microsoft Excel. Application functions normally EXCEPT for recording macros or using data analysis add ins. Problem: VB configuration is hard coded to local drive (specifically the "...

Excel 2007 Table Bug
Has anyone come across a problem with Excel 2007 Tables? I frankly don't have much use for tables but since Microsoft shortsightedly placed table autoformatting on the other side of this barrier, I often convert a range to a table and the convert it back to a range leaving the formatting in place. Trouble is, when I convert a table back to a range I find that the area defined is now troublesome--chiefly, formulae no longer work! I suspect the problem is the boneheaded new referencing method that Microsoft uses for Tables (which is what, for me, makes Tables totally useless: one referenc...

Excel Calc Bug
Leave it up to microsoft to let the consumer test their product for them! I dont' think they would take it seriously until there was a lawsuit. Look at calculator. Have they ever -provided a fix- for the miscalculations it causes? Sad. Very Sad! ...

XmlSerializer help
Hi, I have a class: public class Note { public string name; public string information; } And i Serialize this class, but want to Serialize it to an XmlDocument which will contain many of these elements. How do i do this? Thank you, Tim. Timothy, take a look at Chris Lovett's XmlNodeWriter on www.gotdotnet.com [0]. Simply pass the node where you want to insert the serialized XML into the XmlDocument to an XmlNodeWriter and pass the XmlNodeWriter to the Serialize method. -- HTH Christoph Schittko [MVP] Software Architect, .NET Mentor [0] http://gotdotnet.com/Communit...

BUG in O2K3
I posted this yesterday, with no response, and am posting again today as this is clearly a bug in Office 2003. Office 2003 is not properly integrated (well not at all!) with the IE setting "Reuse windows for launching shortcuts" (Internet Options - Advanced). This causes severe readability issues for users who need to make many url clicks from within Outlook, and don't want multiple instances of the IE window opening. See this for someone else's report of the same issue: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&frame=right&th=b9c079b670 8a7bde&...

Dissappearing settings tab
OK, I have CRM 3.0 working and everything seems to be running fine except for access to the settings tab on the client. For some reason when I'm logged in as an Small Business Server 2003 authenticated user when I load up CRM in a web browser the "Settings" tab is not there. My role is an administrator. However if I logon locally to my computer and not as an authenticaed SBS user I point my browser to the server and it asks me to provide my login details as I'm not authenticated. When I do so through the CRM interface I then get the Settings tab showing! It's ...

The infamous unread email flag bug
Anyone know if Microsoft is planning to fix this bug? I'd imagine it shouldn't take that much code to fix it. It's been several years that people have been complaining about this on the web. Basically if you have a Rule that automatically marks certain mail read, the task tray notification icon (little yellow envelope) stays there. It is supposed to disappear. This bug forces the user to continuously open and sort through the inbox to see what arrived, when there is nothing there - it was already processed and marked read. This often affects spam plug-ins. The bug exis...

CDatabase/CRecordset Unicode bugs in MFC7.1
[Note: see also the thread: "Stack gets corrupted when using ODBC connection pooling and UNICODE support" started by Pavel Chuchuva 2003-08-12 03:55:31 PST in microsoft.public.vc.database. -Eric] I'm looking for recommendations on how to best work around several CDatabase & CRecordset bugs. Please note that we have dozens of legacy components to support here. We currently have some classes in place to override some of the bad behavior, but they are causing some strange behavior of their own. First, the bugs: (Bug 1) This may be Microsoft's SRX020906600020, although I...

Bug or feature?
The first returns an empty string as expected but the second is null. Is this a bug or feature? SELECT RIGHT('ABC', 0) SELECT RIGHT(CAST('ABC' AS VARCHAR(MAX)), 0) Cheers, Michael On Tue, 30 Mar 2010 16:35:02 +1100, "Michael C" <mike@nospam.com> wrote: >The first returns an empty string as expected but the second is null. Is >this a bug or feature? > >SELECT RIGHT('ABC', 0) >SELECT RIGHT(CAST('ABC' AS VARCHAR(MAX)), 0) > >Cheers, >Michael > You don't say which version you are on, bu...

WS_SYSMENU causing bugs in NCPAINT?
Hi! I'm drawing my window the way I like it... handling WM_NCPAINT, WM_NCCALC... But I've found out that if I do not remove the WS_SYSMENU, Wndows is causing bugs, sometimes Windows draws the "original" title bar and a border... But if I remove the WS_SYSMENU style, I track the original sys-menu, and there will be no sys menu when right clicking the minimized application, because there's no sys menu!! Is there any solution for this? Thanks.. Martin ...

MFC BUG! CTreeCtrl & manifest breaks edit label timer
Yo MSVP's and MS guys, I have a VC7 dialog-based app that has a CTreeCtrl with the TVS_EDITLABELS style set. As long as I am not using the manifest for XP look & feel, everything works fine for in-situ edit labels. This means that when I click on item, the timer (with ID==43) gets set correctly, and when I click on it again, the editbox appears for the item. As soon as I include the manifest, the timer still gets set correctly, but the editbox will not appear for the item. Other than adding my processing in an NM_CLICK handler, anyone know a way to fix this? Thanks in adva...