Here's a real treat. I'm working on yanking some old .Net 1.1 code forward to 2.0, including a bunch of DataSets, so I was grabbing these old 1.1 DataSet XSD files, pasting into the new project directory, doing an "Add Existing" in the new project, and letting VS2005 re-generate all the "accessory" files that accompany the XSD. This wasn't really exciting, but it was easy, and it was working really well until I got to one that just wouldn't import cleanly.
The first thing I noticed was a build error:
Custom tool error: Failed to generate code. Failed to generate code. Exception has been thrown by the target of an invocation. Input string was not in a correct format. Exception has been thrown by the target of an invocation. Input string was not in a correct format.
Nice. Thanks for all the detail here, cuz' that just makes the problem obvious, right? Not so much. The next thing I noticed was that I wasn't getting a .cs file generated for this XSD - clearly a related problem, so maybe I can get a better error message out of the designer. So I right-clicked the XSD and hit "Run Custom Tool", and got a wealth of new information:
I hadn't really gotten my hopes up, but still...
As I walked away muttering product management suggestions for Microsoft under my breath, I ran into a co-worker who suggested breaking this beast down and adding one part of the XSD at a time until it barfed. Of course! This ended up being somewhat time-consuming, but it did, in fact, point out the place where the XSD was broken.
The 1.1 schema had a flag that could be used to indicate the value to use when null values turned up. I therefore, had a couple of lines in my XSD that looked like this:
<xs:element name="profile_type_id" type="xs:int" minOccurs="0" codegen:nullValue="" />
Note the value -- empty string, which is not a default one typically associates with int's. The 1.1 designer seemed perfectly happy with this, but the 2.0 designer wasn't. I'm still not real thrilled with the punt-on-error approach exhibited by the 2.0 designer - that's a great way to blow a bunch of time chasing down inane syntax problems.
But lucky for you, you'll know just where to look, won't you?