8

Despite this being one of the best error messages I've ever seen (second only to, "This operation could destabilize the rent in the space-time continuum"), it's also one of the most frustrating.

I have developed an ASP.NET MVC site which works perfectly through VS2008. It works perfectly hosted on a local IIS7 server (Win2008Server & Win7beta), and also on another Win2008Server host. A few days ago, I uploaded the site to a new host (Win2008Server), and have run into the "Operation could destabilize the runtime" error whenever one (and only one) of my LinqToSQL statements is evaluated.

The Linq statement in question has been simplified to the point of obscurity, and still whenever I evaluate the result the error occurs:

var result = from e in db.calendarEvents select e;
foreach (var event in result)  // error occurs on this line
{
    ...
}

The remote host in question is running in full trust, and there are no switch statements in sight (these two issues came up on Google as being related to the error).

A similar issue was reported at Operation could destabilize the runtime?, but there are no interfaces used (that I am aware of).

Any ideas?

--- Just a pause: The table in question uses a TIME data type, and maps to a TimeSpan property. Apparently this was only available in .NET 3.5 SP1. I'm waiting to find out if my new host has SP1 installed...

Community
  • 1
  • 1
Darren Oster
  • 9,146
  • 10
  • 48
  • 66
  • http://images.marketworks.com/hi/55/54565/st101_6.jpg ? – Iain Holder Jan 27 '09 at 00:34
  • Can you provide more information about what calendarEvents is and perhaps also provide the command text for this query? var text = db.GetCommand(result).CommandText Also, I presume you have tried it with a name other than "event" as that is a reserved word. – DamienG Jan 27 '09 at 00:38

5 Answers5

3

OK, the end result was that my host was running my site on a server with .NET 3.5 installed (not SP1), and the one table that used the TIME SQL datatype broke with the above error. http://msdn.microsoft.com/en-us/library/bb386947.aspx states that LINQ to SQL supports mapping of these new types starting with .NET 3.5 SP1.

My host kindly migrated my site to a .NET 3.5 SP1 server, and all is good.

Darren Oster
  • 9,146
  • 10
  • 48
  • 66
1

event is a keyword. Use @event for your variable name instead.

Amy B
  • 108,202
  • 21
  • 135
  • 185
0

In past instances where I have seen this error occur, it was due to reflection attempting to set a readonly property or field. As Linq2Sql uses reflection, my guess is that this is the problem. You should investigate the type definition of the class of which "e" is an instance.

Make sure that attributes are on the correct members. And watch out for readonly in Linq2SQL classes.

leat
  • 1,418
  • 1
  • 15
  • 21
0

What happens if you do this

var result = (from e in db.calendarEvents select e).ToList();
foreach (var event in result)  // error occurs on this line
{
    ...
}

so that the SQL is evaluated before you go into the loop?

Glenn Slaven
  • 33,720
  • 26
  • 113
  • 165
0

It might be worth changing this code to fetch the data, and then checking the ensure that the array has values.

dim result = (from e in db.calendarEvents).toArray
If not results is nothing andalso results.length > 0 then
   'Do Loop
End If

If the linq query returns nothing you avoid the error of trying to complete your for loop

Andrew Harry
  • 13,773
  • 18
  • 67
  • 102