0
votes

I have a hosted MVC 4 application with MEF system in it. Everytime the system tries to create the controller that is injected by the MEF, this error occurs:

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 fine If I hosted on my local IIS, but it produces error when I hosted on external hosting provider.

What is causing this error?

1

1 Answers

0
votes

Try checking what is happening in the constructor of EAccountingController. I had this same issue in a Windows service/console application and it turned out that I had an unhandled exception in the constructor of the MEF part being loaded (due to an environment difference between my development and production environments).

The key part of the error message was:

An exception occurred while trying to create an instance of type '[somenamespace.sometypename]'.

In your case, it is EAccountingControllers.EAccountingController.

This is not so much a MEF error as it is an unhandled exception occurring while trying to create an instance of EAccountingController (i.e. probably in the constructor).

The answer to what the problem is likely lies within EAccountingController and what it does when an instance is being created.