The first part of this tip discussed passing anonymous type among various function calls. That would work fine in all respect as long as the function call is made within a project (single DLL). But what happens when a DLL exposes a method and returns the Anonymous Type Collection to a function defined in another DLL. (Consider an application where BusinessLayer is separated from DataLayer (separate DLLs) and the data coming from DataLayer is collection of AnonymousType)

In this case it will throw a runtime exception, something like “the<anoymous property1> does not exist”. This is because the access scope of Anonymous Types is private (internal) by default, and are not accessible to the functions defined in separate DLLs.

For this, there is a work around. we need to explicitly make each and every member of Anonymous Type as Public. This can be achieved by using ExpandoObject

Consider my last example GetStudentDetails(), but first, we will modify the code a little bit- instead of creating the list of objects, we will create an IEnumerable collection.