Home Dashboard Directory Help
Search

Random 'Unable to load one or more of the requested types' Errors by Cox, Ken


Status: 

Closed
 as Fixed Help for as Fixed


13
0
Sign in
to vote
Type: Bug
ID: 588847
Opened: 8/24/2010 7:13:27 PM
Access Restriction: Public
2
Workaround(s)
view
12
User(s) can reproduce this bug

Description

When my large ASP.NET 4 Web application starts after updating files, it frequently reports what appear to be bogus and random errors. For example, it suddenly complained about an Entity Framework Profiler assembly that had been working fine (and worked fine later – keep reading):

Inheritance security rules violated by type: 'HibernatingRhinos.Profiler.Appender.ProfiledDataAccess.ProxiedDataReader'. Derived types must either match the security accessibility of the base type or be less accessible. Source:/WebAuth/finance.aspx

When I removed the ‘offending’ assembly and dirtied the web.config file, the site worked again until the next change to an .aspx page. Then, the failure to load was blamed on MVC even though this is not an MVC application:

Could not load file or assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. Source:/dashboard.aspx

Note that these strange errors are happening on the live site as well as on my development machine. I really suspect that Entity Framework 4 is implicated somehow. The stack trace for both the preceding errors is virtually identical:

Stack Trace:
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) at System.Reflection.RuntimeModule.GetTypes() at System.Reflection.Assembly.GetTypes() at System.Data.Metadata.Edm.ObjectItemConventionAssemblyLoader.LoadTypesFromAssembly() at System.Data.Metadata.Edm.ObjectItemAssemblyLoader.Load() at System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, ObjectItemLoadingSessionData loadingData) at System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, KnownAssembliesSet knownAssemblies, EdmItemCollection edmItemCollection, Action`1 logLoadMessage, Object& loaderCookie, Dictionary`2& typesInLoading, List`1& errors) at

Details
Sign in to post a comment.
Posted by Pawel Kadluczka - MSFT on 4/23/2012 at 5:12 PM
This is fixed in .NET Framework 4.5
Posted by mryogi76 on 9/30/2011 at 3:56 AM
I am getting this error while trying to read types of a codedUIAssembly. Nothing to do with IIS. Hope Microsoft resolves it soon.
Posted by Humberto Martinez on 6/14/2011 at 4:53 PM
I had this same problem, it turns out there was an extra .dll in my bin folder, and when the entitydatasource tried to load it, crashed, i just removed it since it was targeting a windows forms environment and the problem went away.

so the moral of the story is.. double check whats in your bin!
Posted by sergioadh on 6/7/2011 at 8:58 AM
You seem to be getting this random errors by using EntityDataSource, but I don't have any on my page, all data is gathered in code-behind using entity framework and still I get this error, and it's annoying because it works for 1 hr then it doesn't then maybe it works again, on live private tests ... any real workaround to this?
Posted by Microsoft on 4/7/2011 at 2:27 PM
Andy, did you really try adding the setting for ContextTypeName property in all your EntityDataSource instances and that didn't work?

Entity Framework Team
Posted by Andy Rive ra on 3/28/2011 at 2:12 PM
After 5 hours of dealing with this problem I got it working. I tried everything suggested by everyone on this connect ticket and the other one. The thing that finally solved it was setting all my referenced assemblies to “copy local = true”. If I copy every dll including system ones such as system.data.entity.dll etc into the bin folder it works. If any dll reference is missing it stops working. My scenario was a win7 64bit development workstation where everything worked fine using VS2010 and IIS. Then when copied to a windows 2003 server standard edition with IIS 6 it would not work. Both computers have the latest versions of the OS updates etc.

Hope this helps you!
Posted by Microsoft on 3/22/2011 at 4:21 PM
Hi Ken,

The theory that this might be dependent of runtime compilation order sounds interesting. EntitDataSource actually uses ASP.NET methods to get the referenced assemblies, in particular a call to System.Web.Compilation.BuildManager.GetReferencedAssemblies(). So, if this method ever returned an assembly that doesn’t really exist, that could be an explanation, but that would strange. I would rather look for a stale assembly.

As I said, I have seen this issue happen before, and in one case digging also revealed a missing MVC type. The culprit turned out to be a CAPTCHA component that was original compiled with a reference to an MVC assembly that wasn’t either in the bin directory nor in the GAC in that particular machine. Perhaps this will provide you a clue.

I agree the issue is quite problematic, especially since the EntityDataSource designer wizard never configures the ContextTypeName property.

Let me how things go when you try the workaround.

Diego
Posted by Cox, Ken on 3/22/2011 at 2:24 PM
Hi Diego,

Thanks for the response.

What makes this strange is that dirtying the web.config clears up the issue for that particular build. If the assembly or type couldn't be loaded, how would dirtying the web.config make the assembly suddenly available?

Also, the error frequently refers to an MVC assembly which is not referenced in the project at all - at least as far as I can tell.

I keep wondering if this is a problem with the order of run-time compilation. If an individual page compilation isn't ready at the time the EntityDataSource starts its search for types, the type may truly not exist yet. Forcing a recompilation via the web.config might get the ducks in a row. Still, that doesn't explain the bogus MVC errors.

This is quite a hazardous issue because there's no guarantee that the site will run without intervention after a new build.

I'll try the ContextTypeName workaround.

Thanks,

Ken
Microsoft MVP [ASP.NET]
ASPInsider
Posted by Microsoft on 3/22/2011 at 1:48 PM
Ken,

I thought I had responded previously to this Connect issue but I cannot see my response here, so I apologize for the long delay.

We have seen this issue in the past and it is usually associated with an assembly or type that really cannot be loaded. There are multiple possible reasons for that, e.g. the assembly was compiled with a reference that is not present (that seems to be the case in the exception that you provided), or the assembly is not compatible with the present version of the CLR.

In any case, the fact that an assembly or type that cannot be loaded is aggravated by the default behavior of the EntityDataSource, which will try to load all assemblies referenced by the application trying to find all possible entity types.
If it is not possible for you to identify and remove the assembly that is producing the error, you can turn off the default behavior of EntityDataSource by setting the ContextTypeName property in the control in the markup to the class name of your derived ObjectContext type.

In the future, we might consider making EntityDataSource more resilient to this kind of failure, but this would potentially hide other legitimate failures.

Hope this helps,
Diego
Posted by Cox, Ken on 11/19/2010 at 6:45 AM
Is there any hope of a patch for this or at least a tool that will point out exactly where two controls are using the same EntityDataSource? This is a troublesome bug because it affects the reliability of web applications. There's a danger they won't restart without someone dirtying and resaving the web.config file.
Posted by Microsoft on 8/25/2010 at 2:38 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Posted by dook77 on 8/24/2010 at 8:38 PM
I am having an issue in particular with Sax.dll.


LOG: DisplayName = Sax, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5ddc67619681886c


ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) +0
System.Reflection.RuntimeModule.GetTypes() +4
System.Reflection.Assembly.GetTypes() +78
System.Data.Metadata.Edm.ObjectItemConventionAssemblyLoader.LoadTypesFromAssembly() +75
System.Data.Metadata.Edm.ObjectItemAssemblyLoader.Load() +42
System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, ObjectItemLoadingSessionData loadingData) +233
System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, KnownAssembliesSet knownAssemblies, EdmItemCollection edmItemCollection, Action`1 logLoadMessage, Object& loaderCookie, Dictionary`2& typesInLoading, List`1& errors) +162
System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies, EdmItemCollection edmItemCollection, Action`1 logLoadMessage) +648
System.Data.Metadata.Edm.ObjectItemCollection.ExplicitLoadFromAssembly(Assembly assembly, EdmItemCollection edmItemCollection, Action`1 logLoadMessage) +78
System.Data.Metadata.Edm.MetadataWorkspace.ExplicitLoadFromAssembly(Assembly assembly, ObjectItemCollection collection, Action`1 logLoadMessage) +119
Posted by Cox, Ken on 8/24/2010 at 7:21 PM
For a fuller report, see my blog post here:

http://weblogs.asp.net/kencox/archive/2010/08/24/fed-up-with-system-data-metadata-edm-objectitemassemblyloader.aspx

Ken
Sign in to post a workaround.
Posted by Cox, Ken on 3/29/2011 at 5:25 PM
Diego's suggestion to set the ContextTypeName property *seems* to have helped - at least for my first deployment attempt.

You should set the ContextTypeName="ProjectNameNameSpace.EntityContainerName"

Here's an example of some markup:

<asp:EntityDataSource ID="edsCategoryTypesFilter" runat="server" ConnectionString="name=OfficeBookDBEntities1"
        ContextTypeName="OfficeBook.OfficeBookDBEntities1" DefaultContainerName="OfficeBookDBEntities1"
        OrderBy="it.CategoryName" EntitySetName="AccountTypeCategories" EntityTypeFilter="AccountTypeCategories">
    </asp:EntityDataSource>

Ken
Posted by Paresh Bhatewara on 9/15/2010 at 10:20 AM
Do not use one EntityDataSource for two controls. Create two EntityDataSource controls for two different controls.