views:

1031

answers:

5

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 http://stackoverflow.com/questions/378895/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...

A: 

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
Thought of that - it breaks at the previous line (whenever it's evaluated).
Darren Oster
+1  A: 

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

David B
Yeah, sorry, my bad. I didn't actually use 'event' in my code, I just wasn't thinking when I wrote the post.
Darren Oster
+2  A: 

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
A: 

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

Harry
Sorry about the VB :P
Harry