0

If I access my MVC website in my local IIS, there is no error, but if I host the MVC website to external hosting provider, I got

Error 500 - Internal Server Error

Here is the picture:

enter image description here

NOTE: My MVC application is using virtual path provider, and allows MEF to use plugin dll at runtime, my main site is doing ok. All the pages can be accessed, but the pages from plugin, cannot be accessed. Why is this happening?


------ UPDATE--------

I traced the error, and I found this:

The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.

1) Specified argument was out of the range of valid values. Parameter name: site

Resulting in: An exception occurred while trying to create an instance of type 'EAccountingControllers.EAccountingController'.

Resulting in: Cannot activate part 'EAccountingControllers.EAccountingController'. Element: EAccountingControllers.EAccountingController --> EAccountingControllers.EAccountingController --> AssemblyCatalog (Assembly="EAccounting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")

Resulting in: Cannot get export 'EAccountingControllers.EAccountingController (ContractName="EAccounting")' from part 'EAccountingControllers.EAccountingController'. Element: EAccountingControllers.EAccountingController (ContractName="EAccounting") --> EAccountingControllers.EAccountingController --> AssemblyCatalog (Assembly="EAccounting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")

It is my MEF problem, the plugin is somehow produced this error, I wonder what is happening?

Alvin Stefanus
  • 1,873
  • 2
  • 22
  • 60

1 Answers1

0

The problem probably comes from MefContrib.Web.Mvc library, which seems to be triggered by certain method calls. Here is some explanation from Fordio on "Why are my controllers being instantiated when they're not being called?":

The factory overrides GetControllerType, I assume to try and resolve controllers that live in assemblies somewhere other than the default application or it's references. The implementation of GetControllerType first calls into base.GetControllerType to see if Defaultcontroller can resolve it.

If it can't - which is the case for urls that don't exist - it asks MEF for all exports that implement IController. This returns an IEnumerable> with one item for every class that implements IController in the bin/ folder (by default).

It then runs a linq query over the IEnumerable, calling GetType() on the Value property of each Lazy. Requesting the Value of a Lazy forces the instance to be created. This is why every controller in the bin/ is being constructed for a page that doesn't exist.

As it stated that each controller linked with the plugin might be mapped to page that not to be exist, try checking every part of code that referenced the plugin, or remove MefContrib references on controller factory declaration code and use DefaultControllerFactory instead (ensure you have backup before making edits, in case you need to rollback wrong changes).

Also, you may examine SetControllerFactory method on Application_Start as suggested by OP of that problem (https://stackoverflow.com/a/18188344/6378815), comment out the method usage like this:

// ControllerBuilder.Current.SetControllerFactory(new CompositionControllerFactory(new CompositionControllerActivator(dependencyResolver)));

AFAIK, MEFContrib implementation allows locating controllers placed outside /bin directory, which become issue if the controller factory doesn't recognize given path to desired view. If those solutions still won't work, try inspecting IIS configurations on external host, ensure MEF instances has been set properly.

Additional references:

MSDN Reference

How to integrate MEF with ASP.NET MVC 4 and ASP.NET Web API

Community
  • 1
  • 1
Tetsuya Yamamoto
  • 24,297
  • 8
  • 39
  • 61