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 believe it is an issue of covariance or contravariance as noted by [this forum post](http://www.manning-sandbox.com/message.jspa?messageID=77137#77137).

See [Covariance and Contravariance in C#, Part Two: Array Covariance](http://blogs.msdn.com/ericlippert/archive/2007/10/17/covariance-and-contravariance-in-c-part-two-array-covariance.aspx) and the rest of the [Covariance and Contravariance series](http://blogs.msdn.com/ericlippert/archive/tags/Covariance+and+Contravariance/default.aspx) at Eric Lippert's blog.

Although he is dealing with Arrays in the article I linked, I believe a similar problem presents itself here. With your first example, you are returning an `IEnumerable` that could contain objects that implement an interface that is *larger* than `ISomeTable` (i.e. - you could put a Turtle into an Animals IEnumerable when that IEnumerable can only contain Giraffes). I think the reason it works when you return `IQueryable` is because that is *larger/wider* than anything you could return, so you're guaranteed that what you return you will be able to handle(?).

In the second example, [OfType](http://msdn.microsoft.com/en-us/library/bb360913.aspx) is ensuring that what gets returned is an object that stores all the information necessary to return only those elements that can be cast to Giraffe.

I'm pretty sure it has something to do with the issues of type safety outlined above, but as Eric Lippert says [Higher Order Functions Hurt My Brain](http://blogs.msdn.com/ericlippert/archive/2007/10/24/covariance-and-contravariance-in-c-part-five-higher-order-functions-hurt-my-brain.aspx) and I am having trouble expressing precisely why this is a co/contravariant issue.
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

```