Invalid cast (but not for a type missmatch) RRS feed

  • Question

  • Y have this simple code:

    var ctx = new MyDataContext();
    var request = from d in MyTable
                  select d;
    foreach(var item in request){

    In random times, and in specific computers, the foreach launch an "Specified cast is not valid".

    It happends to with FirstOrDefault command.

    Sometimes, I read the same table, and fails not the first time.

    Every time I create a new DataContext.

    Any ideas?

    Un saludo! Juan Segura

    Tuesday, March 27, 2012 9:55 AM


  • Hi Juan

    Are you disposing MyDataContext() after using it?

    "En los momentos de crisis, sólo la imaginación es más importante que el conocimiento"

    • Marked as answer by Juan Segura Friday, April 6, 2012 10:14 AM
    Tuesday, March 27, 2012 3:26 PM

All replies