Saturday, March 12, 2011

Application Domains and LINQ Reqults

 

Another quick note; it’s generally not a good idea to try and pass the results of LINQ queries across application domain boundaries, unless you first convert them to a list, array or other well known type.

The result of a LINQ query is typically some kind of anonymous type (often an enumerator), and that type exists only in the application domain where the original query was run and the compiler generated the type for you. Passing that type across an application domain boundary will typically result in a missing type exception. Alternatively, it could conceivably cause other unwanted code or assemblies to be compiled into the other application domain.

Convert the result to a known list, array, dictionary, or other collection avoids this problem so long as that type is known in both application domains (which all of the standard .Net ones should be).


No comments:

Post a Comment