Troubleshooting “Invalid cast exception for WDDX recordset” in ColdFusion MX 7

Over the past few working days I’ve been making some minor enhancements / bug fixes to a reporting product currently in beta. Said product at a 50,000 foot view basically compiles a report into a massive structure which I then convert to WDDX and store in a database so that it can be transformed easily into different display formats as well as viewed at a later date.

Out of the blue I kept getting low-level errors like this whenever the structure was convered to WDDX from the <cfwddx> tag itself:


Exception during WDDX operation.
java.io.IOException: Invalid cast exception for WDDX recordset.

java.io.IOException: Invalid cast exception for WDDX recordset
at coldfusion.wddx.RecordSetSerializer.writeObject(WddxObjectSerializerFactory.java:346)
at coldfusion.wddx.WddxOutputStream.writeObject(WddxOutputStream.java:310)
at coldfusion.wddx.WddxOutputStream.writeDictionary(WddxOutputStream.java:525)
at coldfusion.wddx.DictionarySerializer.writeObject(WddxObjectSerializerFactory.java:300)
at coldfusion.wddx.WddxOutputStream.writeObject(WddxOutputStream.java:310)
at coldfusion.wddx.WddxOutputStream.writeDictionary(WddxOutputStream.java:525)
at coldfusion.wddx.DictionarySerializer.writeObject(WddxObjectSerializerFactory.java:300)
at coldfusion.wddx.WddxOutputStream.writeObject(WddxOutputStream.java:310)
at coldfusion.wddx.WddxSerializer.serialize(WddxSerializer.java:254)
at coldfusion.tagext.lang.WddxTag.serialize(WddxTag.java:285)
at coldfusion.tagext.lang.WddxTag.doStartTag(WddxTag.java:149)
at coldfusion.runtime.CfJspPage._emptyTag(CfJspPage.java:1908)
......

Obviously something wasn’t being cast correctly in the struct, thereby making it fail when trying to convert it to WDDX.

Being that the structure I’m converting to WDDX is very complex, I basically went down the path of doing StructDelete()‘s on parts of it until I narrowed down the problem to a SQL Server query (the only such type within the report). I played around with <cfparam>‘s in the bean where that query was set using getters and setters thinking by trying to precast that particular query in the struct before adding it. This unfortunately didn’t work, and I didn’t really think that it would given past experience, but it was a necessary step just to make sure it wasn’t something I was doing wrong somewhere.

Finally I remembered the database which the query was coming from was the database which I’d been using to evaluate the jTDS JDBC drivers with. It seemed strange that a JDBC driver could screw-up casting, but just for troubleshooting sake, I went ahead and switched the DSN over to the Microsoft SQL Server JDBC Driver. I ran the process again, and what do you know, that fixed the problem.

When Googling for “Invalid cast exception for WDDX recordset” there are basically no relevant links, so I thought I’d post a bit about it in case someone else runs into this problem in the future.

This entry was posted in Languages, Tips, Hacks, & Tricks and tagged , , , , , , , , , , . Bookmark the permalink.

One Response to "Troubleshooting “Invalid cast exception for WDDX recordset” in ColdFusion MX 7"

Leave a reply