“Unable to load one or more of the requested types.” when using EntityDataSource with Entity Framework in ASP.NET

I always love pushing something out that fails miserably and randomly. Especially when using straight Microsoft technologies. It seems these folks don’t eat their own dog food, or we wouldn’t encounter this crap.

Anyway, it took quite a while to figure out the resolution to this issue, but it all lies in the fact that their control is “trying” to be intelligent, and really only needed a little direction.

Let me explain, when the EntityDataSource loads, it looks for the Context. Where may you ask? Well, it actually uses reflection and attempts to load all types from the assembly to resolve the entities. If there is any error in this at all, it blows up. There are a number of reasons this can fail. Dependency mismatches, bad references, and other things that may not break your application but break this feature.

How can I fix this? I am sure you are asking this right now. “Damn it Brian, Get to the freaking point and the fix!” Fine.

It’s pretty simple.

Set this property on the EntityDataSource in your .aspx file. ContextTypeName .

The value? Well, the full namespace and class of your context. Example. Seekford.Data.MyEntityContext

More detailed example:

<asp:EntityDataSource … ContextTypeName="Seekford.Data.MyEntityContext" />

Happy coding!

4 thoughts on ““Unable to load one or more of the requested types.” when using EntityDataSource with Entity Framework in ASP.NET”

  1. Thanks for this post. I am not sure yet it fixes the issue will know soon… but your post makes it easy to understand why this error occurs and that is always some comfort (not knowing and just trying stuff to fix drives me crazy).

  2. How do I find out what my full namespace and class are? Mind you, when you add an edmx, it creates all that shit for you.

    1. The namespace and class for the models are sitting in the generated classes under the EDMX. Hit the Plus sign in the solution explorer to see all your generated files. You can then just look at the top of the class definitions for namespace and class names.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.