The Error
Recently, I have been working on WCF Services and I have come across some strange issues with WCF Contract formatting issues. In particular, I sometimes see this error message
"System.ServiceModel.FaultException `1[System.ServiceModel.ExceptionDetail]: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter"
I got this error regarding the inability to recognize a change that I have made in a WCF Contract assembly during development. I had a enumeration in the contract that needed an extra value and after adding that extra value, I kept being side tracked by this strange error. I have the typical [DataContract] attribute on the enum class with the [EnumMember] attribute above each enumeration value. After searching around the web I didn't find an informative solution to the problem.
Details
The issue was happening in my unit tests when the client would call through the proxy the formatter would throw this exception. We have the proxy reusing all of the references, so there is a copy of the WCF Contract locally and on the server. I first made sure that after I made the change to the Contract, that the assembly that I have on the client matched the updated contract on the server.
The Solution
I realized that when i was running these tests locally, there was a temporary asp.net file folder involved. In the end, the files are copied into the Microsoft .net Temporary ASP Files directory and the service host stored those files there in order to run. I suppose when the service host is recycled the code in the temp folder is no longer used an a new directory is created. Well, during development, I wasn't restarting the local service host and it was comparing the new WCF Contract assembly in the client with the older WCF Contract assembly in the service host. So, even though I updated the Service WCF Contract, the service host maintained an older copy of the WCF Contract assembly and the result was that the Contracts were not the same yielding this error being thrown. So, I now have a window to the location: "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files" open to recycle the older version of the WCF Contract that the service host is using. You must stop the service host in order to delete the files but really, when you start the service host it should push out the new temporary ASP net files to the Temp folder and you should be good.
Cheers