This project has moved. For the latest updates, please go here.

System.Reflection.ReflectionTypeLoadException

Apr 16, 2015 at 6:35 PM
Using SQL Server Full version (2008), but cannot get site to load. I am fairly certain my connections strings are correct, but it honestly gives the same error even if I put in garble. It's almost like it isn't getting to the connect part, but is dying before that.

It is iis 7.5


Server Error in '/' Application.

Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Source Error:


An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:



[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() +9
System.Reflection.Assembly.GetTypes() +143
System.ComponentModel.Composition.Hosting.AssemblyCatalog.get_InnerCatalog() +241
System.ComponentModel.Composition.Hosting.AssemblyCatalog.GetExports(ImportDefinition definition) +13
System.Linq.<SelectManyIterator>d__142.MoveNext() +267
System.ComponentModel.Composition.Hosting.CatalogExportProvider.InternalGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition) +477
System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable
1& exports) +48
System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition) +136
System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExports(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable1& exports) +54
System.ComponentModel.Composition.Hosting.AggregateExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition) +404
System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExports(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable
1& exports) +54
System.ComponentModel.Composition.Hosting.CompositionContainer.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition) +230
System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(ImportDefinition definition, AtomicComposition atomicComposition) +78
System.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValueCore(String contractName, ImportCardinality cardinality) +98
TicketDesk.Web.Client.MvcApplication.Application_Start() +54

[HttpException (0x80004005): Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +12600621
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +175
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475

[HttpException (0x80004005): Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12617668
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12457285
Coordinator
Apr 18, 2015 at 5:05 AM
This is actually one of the reasons I didn't continue with the managed extensibility framework (MEF) as a IoC/DI framework in TD 2.5. The errors you get with it are quite obtuse, and it is difficult to pinpoint the cause of it's failures from just a stack trace, especially when it dies during startup. If you can attach a debugger, you'd be able to dig into the exception and see exactly which exports failed. When the error comes from Application_Start event like this though, there is a 90%+ chance it is either a bad connection string, or missing tables or data in the database --missing application settings data often causes that exception.

I presume you ran the SQL Creation scripts on your 2008 SQL server? Another thing that trip people up sometimes is that full editions of SQL server don't enable TCP/IP by default when you install it, so check that on the SQL box in SQL Configuration Manager (for both the 32 and 64 bit server settings). Also, firewalls on either server can block the standard SQL ports as well.

When in doubt, I recommend you make a very simple empty MVC application targeting .Net Framework 4.5 or higher, copy the security connection string from TicketDesk to your test apps web.config, and make a simple test controller that tries to read the version record from application settings table (or anything from any table that has data).. that takes MEF and TicketDesk specific code out of the equation, and makes it much easier to troubleshoot general server and asp.net related issues.
Apr 21, 2015 at 2:49 PM
I am having this same issue but the suggestions do not resolve the problem. I re-ran the scripts on the database, enabled TCP/IP in SQL server config manager, disabled the firewall. Not sure what else I can try?
Coordinator
Apr 21, 2015 at 2:54 PM
I'll run up a server 2012 vm tonight and see if I can replicate it. I'll also look at options for additional diagnostics during the startup so we can get better info from MEF about the failure.
Apr 21, 2015 at 2:56 PM
Thanks so much!
Coordinator
Apr 21, 2015 at 2:56 PM
Any additional info you can provide about your setup will be helpful, especially SQL versions and sp levels.
Coordinator
Apr 21, 2015 at 2:58 PM
Also, check the Windows event logs and see if MEF was kind enough to drop it's traces in there.
Apr 21, 2015 at 3:24 PM
Sure.

Server 2012 standard Edition 64-bit
IIS version 8.0.9200.16384
SQL Express version 12.0.2000.8
Apr 21, 2015 at 3:53 PM
I see a few ASP.Net errors:

Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 4/21/2015 11:26:46 AM
Event time (UTC): 4/21/2015 3:26:46 PM
Event ID: 303a1563ea2b4efaa715a7bee07a8b0a
Event sequence: 2
Event occurrence: 1
Event detail code: 0

Application information:
Application domain: /LM/W3SVC/1/ROOT-1-130741036062645920 
Trust level: Full 
Application Virtual Path: / 
Application Path: E:\ticketdesk2publish\ 
Machine name: SONAPP 
Process information:
Process ID: 2160 
Process name: w3wp.exe 
Account name: NT AUTHORITY\LOCAL SERVICE 
Exception information:
Exception type: HttpException 
Exception message: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app)
at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers)
at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context)
at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context)
at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)

Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at System.ComponentModel.Composition.Hosting.AssemblyCatalog.get_InnerCatalog()
at System.ComponentModel.Composition.Hosting.AssemblyCatalog.GetExports(ImportDefinition definition)
at System.Linq.Enumerable.<SelectManyIterator>d__142.MoveNext()
at System.ComponentModel.Composition.Hosting.CatalogExportProvider.InternalGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable
1& exports)
at System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExports(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable1& exports)
at System.ComponentModel.Composition.Hosting.AggregateExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExports(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable
1& exports)
at System.ComponentModel.Composition.Hosting.CompositionContainer.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValueCore[T](String contractName, ImportCardinality cardinality)
at TicketDesk.Web.Client.MvcApplication.Application_Start()



Request information:
Request URL: http://localhost/ 
Request path: / 
User host address: ::1 
User:  
Is authenticated: False 
Authentication Type:  
Thread account name: NT AUTHORITY\LOCAL SERVICE 
Thread information:
Thread ID: 6 
Thread account name: NT AUTHORITY\LOCAL SERVICE 
Is impersonating: False 
Stack trace:    at System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app)
at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers)
at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context)
at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context)
at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)


Custom event details:


but not MEF errors.
Coordinator
Apr 22, 2015 at 5:37 AM
I have been able to reproduce the problem. I'm not sure exactly what the cause is yet, but I highly suspect there is a missing dll - either something that should be in bin that didn't make it into the distribution, or a GAC reference that is missing from stock windows server 2012. Now that I can reproduce it, I should be able to isolate the cause, but it may take me another day to produce a new distribution that fixes the issue.
Apr 22, 2015 at 12:06 PM
Edited Apr 22, 2015 at 7:49 PM
Ok. Thank you very much.
Coordinator
Apr 22, 2015 at 7:10 PM
I am almost certain I have found the problem. Server 2012 is missing the actual ASP.NET MVC 4 runtime... which seems insane to me, but kinda makes sense. You can download it as a stand-alone install from here: http://www.asp.net/mvc/mvc4

Give that a shot, and let me know.

In the meantime, I'm going to go ahead and see about updating TD 2.1.x to use the latest nuget references for aspnet, entity framework, etc. instead of just relying on the built-in .Net framework 4.5 components. This will ensure that the distribution's files include all/most of its own dependencies.
Apr 22, 2015 at 7:57 PM
Same error:

Server Error in '/' Application.

Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Source Error:


An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:



[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() +9
System.Reflection.Assembly.GetTypes() +143
System.ComponentModel.Composition.Hosting.AssemblyCatalog.get_InnerCatalog() +242
System.ComponentModel.Composition.Hosting.AssemblyCatalog.GetExports(ImportDefinition definition) +13
System.Linq.<SelectManyIterator>d__142.MoveNext() +267
System.ComponentModel.Composition.Hosting.CatalogExportProvider.InternalGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition) +477
System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable
1& exports) +48
System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition) +136
System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExports(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable1& exports) +54
System.ComponentModel.Composition.Hosting.AggregateExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition) +404
System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExports(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable
1& exports) +54
System.ComponentModel.Composition.Hosting.CompositionContainer.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition) +283
System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(ImportDefinition definition, AtomicComposition atomicComposition) +78
System.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValueCore(String contractName, ImportCardinality cardinality) +101
TicketDesk.Web.Client.MvcApplication.Application_Start() +54

[HttpException (0x80004005): Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +12864673
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +175
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475

[HttpException (0x80004005): Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881540
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159

System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12722601

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
Coordinator
Apr 23, 2015 at 4:10 AM
blah! I installed IIS remote management, web deploy, and the SQL Express management studio onto my test VM (after having reproduced the problem). One of those installs must have included whatever the missing dependency was, because suddenly TicketDesk started working fine (just like it does on every other system I've tested it with)... sadly, there are about 15 products and server features that are installed along with those packages, so it's hard to say which particular one had the magic missing dependency. I thought it would have been be the MVC 4 runtime component though, since that is the version TD 2.1x was using. Worth a shot anyway...

I've put up a beta release for 2.1.4 - this one updates TD 2.1x to using nuget packages for the core MVC and EF dependencies (instead of the stock .Net framework versions). My hope is that this will result in self-contained dependencies for everything except the main .Net Framework 4.5 itself. I haven't had time yet to fully test this on a fresh windows server VM though, so I've flagged it as a beta for now.

If you want to test it out, I'd appreciate it. I'll be able to finish testing it myself on a fresh new server 2012 VM tomorrow, but it looks good locally and on the VMs I do have setup already... though all of them also ran the previous release fine too. I won't know for sure until I get a fresh 2012 server VM setup again.
Coordinator
Apr 24, 2015 at 2:56 AM
Just finished testing 2.1.4. On the same server where 2.1.3 gives a ReflectionTypeLoadException, version 2.1.4 runs without complaint. I'm upgrading the release to stable. If anyone gets a chance to confirm this resolves the problem, please drop a note here.

Thanks.
Apr 24, 2015 at 8:31 PM

Thanks. I will give this new version a try next week.


Thanks.

May 4, 2015 at 5:33 PM
Getting an issue with the 2.1.4:


CREATE DATABASE permission denied in database 'master'.
An attempt to attach an auto-named database for file E:\TicketDesk2.1.4\App_Data\TicketDesk.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: CREATE DATABASE permission denied in database 'master'.
An attempt to attach an auto-named database for file E:\TicketDesk2.1.4\App_Data\TicketDesk.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

Source Error:


An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


I modified the connection string in the web.config file to this:
<connectionStrings>
<clear />
<add name="TicketDeskSecurityConnectionString" connectionString="Data Source=sonapp\SONSQL;AttachDbFilename=|DataDirectory|\TicketDesk.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="TicketDeskEntities" connectionString="metadata=res://*/Models.TicketDeskEntities.csdl|res://*/Models.TicketDeskEntities.ssdl|res://*/Models.TicketDeskEntities.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=sonapp\SONSQL;AttachDbFilename=|DataDirectory|\TicketDesk.mdf;Integrated Security=True;Connect Timeout=30;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
<add name="ElmahLog" connectionString="Data Source=sonapp\SONSQL;AttachDbFilename=|DataDirectory|\TicketDesk.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
Coordinator
May 4, 2015 at 7:06 PM
In your first post, you indicated you were using a full edition of SQL 2008. Full editions of SQL server do not support user instance databases (a.k.a file attached databases). In your connection strings though, you are using the AttachDbFilename parameter, which is for mounting user instance databases. You need to switch this to use the "initial catalog" or "database" parameter instead... this should look something like this:

Server=myServerAddress;initial catalog=myDataBase;Trusted_Connection=True;MultipleActiveResultSets=true;
May 4, 2015 at 8:12 PM
I am using SQL Express 2014.
Coordinator
May 4, 2015 at 9:40 PM
SQL 2012 an 2014 Express also only support fixed databases... so the same advice holds -- use the initial catalog or database parameter instead of AttachDbFilename.

See, back in late 2011, the SQL support team apparently felt like they weren't getting enough calls. So the SQL 2012 team split SQL Express into two products. SQL Express would take fixed databases, while user instance databases would go to the new SQL Server 2012 LocalDB edition. SQL Server 2012 and 2014 only support user instance databases with the LocalDB edition.

Not satisfied that they'd caused enough confusion, in late 2013 they decided to rename the upcoming 2014 version of LocalDB to "SQL Express 2014 LocalDB"... because, that makes it more clear.

The SQL 2012 LocalDB server and instance name was "(localdb)/v11.0", but still not satisfied with causing chaos they decided that for SQL 2014 Express LocalDB they'd make the server and instance name "(localdb)\MSSQLLocalDB" instead... cause, you know, just going with /v12.0 would have been predictable.

Either way, your setup is seems geared to SQL Express 2014 of the NOT localdb variety... but even if it were localdb, you created the DB manually using scripts so it still isn't a user instance database. If you do want to go with a user instance DB, make sure it's LocalDB you have installed, and delete the fixed database you created. TicketDesk includes a database file in the app_data folder that is already configured for localdb (just update the connection string to use the correct server/instance name).