The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

jjsema (3) [Avatar] Offline
#1
The following code produces "System.Security.VerificationException : Operation could destabilize the runtime." exception.

1: public IQueryable<IPerson> GetPersons()
2: {
3: var db = new Data.Linq.SampleDbContext();
4:
5: var query = from p in db.Persons
6: select (IPerson) new Domain.Person {
7: FirstName = p.FirstName, LastName = p.LastName
8: };
9:
10: return query;
11: }

It seems to work if IQueryable<Person> is used, however I want to be able to use interfaces but cannot work out how to do this in my queries.

Iterating through the query with a foreach loop to populate with IPerson is 1 option, but would prefer to keep deferred execution if possible.

Thanks
jjsema (3) [Avatar] Offline
#2
Re: Operation could destabilize the runtime
i just found following works:

return query.OfType<IPerson>();

but not too sure what the exception means...
jwooley (123) [Avatar] Offline
#3
Re: Operation could destabilize the runtime
I suggest you check out Anders Heilsburg's C# Futures talk at PDC '08, specically regarding Co-Variance and Contra-Variance. The PDC videos are available at microsoftpdc.com

Jim
jjsema (3) [Avatar] Offline
#4
Re: Operation could destabilize the runtime
Wow! Thanks, that is very interesting.. hope it comes out soon!