Monday, October 25, 2010

"Specified Cast is Not Valid" - LinqToSql error on submit

While working on a project using LinqToSql I got the error "Specified Cast is Not Valid" when calling SubmitChanges.

After searching a bit on the web I found out the error is due to a problem in .NET Framework 3.5. Luckily there is a hotfix that addresses this problem. Here are some articles about the problem:




The first article is very specific:
"When database contains two tables, both with automatic integer primary keys, and a relationship between a unique char field in one and a non-unique char field in the other, inserting new rows into the second table fails on submit with InvalidCastException."

This is a bit too specific as to the usage of int and char, because the error occurs in other situations as well which can be seen in the second article. Here the error occurs using GUID and int. And to top that up, in my own situation the error occurred using int and long.

The third article has a link from which to download a hotfix to solve the problem.

If you want to obtain the hotfix in a more official way you can use this link:

0 comments:

Post a Comment