none
"Specified cast is not valid" again RRS feed

  • Question

  • I am constantly getting "Specified cast is not valid" on every project I work on.  It normally boils down to trial and error to resolve the problem.  Being told by the expection that it can't create a key from value (I am guessing) does not really narrow the problem.  I know the main key is a GUID so I see no reaon why it should have a problem finding it.

    So the question is :  What is the procedure for tracking these errors down?  The log is useless since it happens before the SQL.

    at System.Data.Linq.IdentityManager.StandardIdentityManager.SingleKeyManager`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 GTrackConsole.Controls.DeviceBrowser.toolStripButtonSave_Click(Object sender, EventArgs e) in D:\function\GTrack\PC\GTrackConsole\Controls\DeviceBrowser.cs:line 130

    Regards,
    John J. Hughes II
    http://www.functioninternational.com/
    • Edited by ckumark Friday, June 26, 2009 5:59 PM Fixing thread title bug
    • Edited by jjhii Wednesday, October 14, 2009 6:50 PM
    Tuesday, June 23, 2009 3:39 PM

All replies

  • Please check your associations thoroughly, the problem might be connected with having an association between Guid Key and non-Guid key.


    Devart Team http://www.devart.com/dotconnect ADO.NET data providers for Oracle, MySQL, PostgreSQL, SQLite with Entity Framework and LINQ to SQL support
    Wednesday, June 24, 2009 2:07 PM
  • This is a known bug where you create an association that doesn't use the primary key at the other end.

    It is fixed in .NET 4.0 and a hotfix for .NET 3.5 SP1 is available from support services.

    [)amien 
    Wednesday, June 24, 2009 2:48 PM
    Moderator
  • Damien,

    Yes I found the problem and you are correct that the primary key was a GUID on the parent and I was using a unique key for the relationship which seemed to confuse Linq.  Took me way to long to figure this out.  Currently in the DB I have the primary key as the GUID but in the mapping I have it set to the unique key as a work around.

    I will try to figure out how to get the hot fix I guess, I assume this must be installed on client computer too :(

    But back to the question.  Where yes this answered this problem, it took too long to find it.  I am sort of looking for a better way of tracking them down.  Is there one?

    Regards,
    John
    jjhii
    Wednesday, June 24, 2009 3:22 PM
  • Hi Damien... can you please quote the hotfix number here?

    It seems to be impossible to get a hotfix from CSS without knowing the number. And I can't find any evidence of it in any search at MS.

    Thanks!
    Monday, July 20, 2009 11:20 PM
  • Wednesday, September 16, 2009 5:54 PM