Question: I'm having a little bit of trouble understanding what the problem is here. I have a bit of code that pulls records from a database using LINQ and puts them into an object which is cast into an interface. It looks a bit like this:

```
public IEnumerable<ISomeObject> query()
{
    return from a in dc.SomeTable
           select new SomeObject
           {
             //Assign various members here
           } as ISomeObject;
}

```

When I test this, I put the returned IEnumerable into a variable called results and run this line:

```
Assert.AreEqual(EXPECTED_COUNT, results.Count());

```

When this is run, I get a System.Security.VerificationException: "Operation could destabilize the runtime."

I found the solution [here](http://devlicio.us/blogs/derik_whittaker/archive/2008/11/29/quot-operation-could-destabilize-the-runtime-quot-from-casting-from-concrete-to-interfaces-with-linq.aspx), which is this:

```
var results = from a in dc.SomeTable
              select new SomeObject
              {
                //Assign various members here
              } as ISomeTable;
return results.OfType<ISomeObject>();

```

This works, but I'm having trouble understanding what's happening here. Why did I get the exception in the first place and how did the lines of code above fix it? The MSDN documentation seems to suggest that this is an issue of type safety, but I'm not seeing where the previous code was type-unsafe.

**UPDATE**
A little bit more information I found out. The first example works if I make the return type IQueryable. This sheds a little bit more light on *what* was going wrong, but I'm still confused about the *why*. Why didn't the compiler force me to cast the IEnumerable into an IQueryable?

Answer: 
I came across this error with similar code;

```
IEnumerable<Table> records = (from t in db.Tables
                              where t.Id.Equals(1)
                              select t).ToList();

```

This seemingly harmless code was part of a UserControl method which was called from a Page. No problem in a .NET4 development environment, however, when the site was PreCompiled and deployed to the server on .NET3.5 I got this error.

I suspect this has something to do with the fact that the control was being compiled into a separate DLL combined with the security changes between the frameworks as described in [this .NET security blog](http://blogs.msdn.com/b/shawnfa/archive/2009/11/12/differences-between-the-security-rule-sets.aspx)

My solution: run the live site on .NET4
In my case i had wrongly declared the Storage property in the Column attribute of a Linq2SQL class 

```
    [Column(Storage = "_Alias", DbType = "NVarChar(50)")]
    public string UserAlias

```