Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Specified cast is not valid" error when saving LINQ-To-SQL entity

App Details: C#, ASP.NET MVC, SQL Server 2008 ( Same version & SP level), Linq-To-SQL ORM

I'm trying to diagnose an exception I'm receiving:

"Specified cast is not valid." at System.Data.Linq.IdentityManager.StandardIdentityManager.SingleKeyManage`2.TryCreateKeyFromValues(Object[] values, V& v)
at System.Data.Linq.IdentityManager.StandardIdentityManager.IdentityCache`2.Find(Object[] keyValues)
at System.Data.Linq.IdentityManager.StandardIdentityManager.Find(MetaType type, Object[] keyValues)
at System.Data.Linq.CommonDataServices.GetCachedObject(MetaType type, Object[] keyValues)
at System.Data.Linq.ChangeProcessor.GetOtherItem(MetaAssociation assoc, Object instance)
at System.Data.Linq.ChangeProcessor.BuildEdgeMaps()
at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)
at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
at System.Data.Linq.DataContext.SubmitChanges()
at Repository.Save() at etc....

The problem is that this is occurring only on our servers, not on our local development boxes. I've tracked it down to a single property we're modifying:

event.SalesForceId = "701Q0000000AOTIIA4";

If I comment out that line, everything works fine.

I've tried:

1 ) waxing all of the code on the server and redeploying. Same issue.
2 ) Pulling down a copy of the server DB and trying it locally. Works fine.
3 ) Trying another IIS environment we have setup on the same box. Same issue.
4 ) Physically comparing ( using AdeptSQL ) both local and remote schemas. No differences.
5 ) Verifying the datatypes of both columns ( local and remote ) are the same. Also, this column is a FK to another table. I verified that both are of the same data type, down to the collation.

The server is Windows Server 2008 and the local box is Windows 7 x64. Both have all important updates setup.

The only thing I can think of is perhaps since the database and web server are on different boxes that could be an issue? Otherwise, I'm completely stumped.

Any ideas?

like image 373
gcaprio Avatar asked Jan 26 '11 04:01

gcaprio


1 Answers

This is a well-known bug in LINQ to SQL.

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351358

There is a hotfix for the issue.

http://support.microsoft.com/hotfix/KBHotfix.aspx?kbnum=963657&kbln=en-us

like image 140
jason Avatar answered Oct 07 '22 02:10

jason