Scott Hanselman

HOW TO: Debug into a .NET XmlSerializer Generated Assembly

November 6, '04 Comments [3] Posted in ASP.NET | XmlSerializer | Bugs
Sponsored By

The XmlSerializer is a much maligned piece of software, but I have to tell you, it's the bomb.  We use it a lot here at Corillian. Recently we had to debug a pretty funky problem where an enum was writing out to an XML file, but wasn't reading back in. We suspected it was a namespace thing, but the XmlSerializer is such a black box, a lot of people really have trouble dealing with it. It inspires a trial-and-error style, while I prefer to debug and step around myself.

Here's how to debug into a generated assembly from the XmlSerializer.

1. Given an application like:

using System.Xml;
using System.Xml.Serialization;
using System.Text;
using System.IO;

namespace Foo
{
    public class Bar
    {
        public static void Main(string[] args)
        {
            XmlSerializer x = new XmlSerializer(typeof(Person));
            Person p = new Person();
            p.first = "Scott";
            p.last = "Hanselman";
            x.Serialize(new StreamWriter("foo.xml"),p);
        }
    }

    public class Person
    {
        public string first;
        public string last;
    }
}

2. Create a yourapplication.exe.config like this:

<?xml version="1.0" encoding="utf-8" ?>
<
configuration>
   <system.diagnostics>
      <switches>
         <add name="XmlSerialization.Compilation" value="1" />
      </switches>
   </system.diagnostics>
</
configuration>

3. Compile and run and step up to the line where the XmlSerializer is constructed, and step over that line.

4. Go to c:\documents and settings\[username]\local settings\temp and look at the most recently created *.cs file. Open that file, it will have a name like asdasdfs.0.cs. Note that there are *.pdbs in that folder as well.

5. Set a breakpoint anywhere in that generated file.

6. Debug to taste (see screenshot below)

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

New Beta 2 Whidbey IDE Feature

November 5, '04 Comments [3] Posted in Musings
Sponsored By

Next Whidbey Feature: "Looks like you're writing shitty code!"

[via Stuart Laughlin]

Now playing: Various Artists - Street Official Mixtape, Vol. 1

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Spam Soap Reporting

November 5, '04 Comments [7] Posted in XML | Web Services
Sponsored By

This is getting a little out of hand. However, having the SPAM caught (via MX record) via SpamSoap.com BEFORE it gets to my Inbox helps. Sheesh, between BitTorrent (now 35% of the Internet’s (or Internets’ - depending on your political persuasion)) traffic, and SPAM, I’m amazed we have any traffic left.

At least there's hope as Jeremy Jaynes got 9 years for SPAMming.


Subject: Spam Soap Reporting

Spam Soap Reports
For hanselman.com
From 10/1/2004 Through 10/31/2004

Domain

Total Email

Spam

% Spam

Viruses

hanselman.com

150,319

142,591

94.9%

227

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

We are a divided nation...

November 4, '04 Comments [29] Posted in Musings
Sponsored By

UPDATE: My response to the many thoughts offered regarding this post is in the comment section below...Thanks to all who joined in.

I found the maps off this link (via Chris Sells) very interesting when put next to each other.  I find this very telling, as 9/11, Iraq, Health Care, Social Security, Gay Marriage, all these things, haven't changed the way the country thinks. This NYTime Columnist says it well when he says 'This was not an election. This was station identification...We don't just disagree on what America should be doing; we disagree on what America is.' There's always been city-folk vs. country-folk, born-again vs. other faiths, left vs. right, but this is getting more fundamental.

2000 Vote Map by County
2004 Vote Map by County

It's interesting that 2nd Amendment is touted as crucial and immutable to many people, but the separation of church and state is eroding (Faith-based Inititives, 'In God We Trust' on our Money, the 10 Commandments in Courthouse)...of course Islam would feel as if we're on a Crusade, a non-Judeo-Christian President could never be elected in this country. 'Mr. Candidate, do you pray?' 'Hm...not so much. I'm more of an analyst.'

Can you see Al Gore praying?
Why is prayer important to a president?
Do we need a mandate from on high to run a country?
Does Greenspan pray on an interest rate decisions?
Could I be elected president if I came out and said 'I'm not a fan of hunting?' 'Why, not killing animals for sport is un-American!'

I understand why Fear (the primary motivator of the last 4 years) would cause people to revisit their faith, but faith should always be balanced with thought. People like Bush for the fact that he 'has conviction, and stands by his decisions' - but isn't it learning from your mistakes that makes you a better person?

I wish we had a leader who thought, who inspired spirited, not spiteful, debate and discourse, who was wise and thoughtful, and had more MIPS than I.

Wisdom crieth without; she uttereth her voice in the streets: She crieth in the chief place of concourse, in the openings of the gates: in the city she uttereth her words, saying, How long, ye simple ones, will ye love simplicity? and the scorners delight in their scorning, and fools hate knowledge?
Proverbs (ch. I, v. 20-22)

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Digging the new Vertical Mouse - Helping my Carpal Tunnel

November 4, '04 Comments [12] Posted in Musings
Sponsored By

I picked up a new mouse today and I'm digging it.  It's called the "VerticalMouse" and I'm wondering why I didn't think of it myself.  Before today I used a Microsoft Optical Wireless, a Microsoft Optical (Thumb) Trackball and a Wacom 4x6 tablet, all at the same time.  I have them all attached to a four point USB hub, and I'd switch from one to the other as I started to hurt.  However, this mouse is comfortable enough that I'll probably start using it all the time. 

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.