My ASP.NET MVC 3 app works fine on my local machine (And usually works fine when i deploy it), but on this occasion i get the following error. The server is windows 2008 R2 with IIS7
EDIT: Bothe ILoggingService & IConfigSettings are both bound in Singleton Scope by Ninject (If That Helps)
Anyone get any pointers on what i should look for?
Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object.
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:
[NullReferenceException: Object reference not set to an instance of an object.]
DataPortal.Models.Repositories.KpiRepository..ctor(ILoggingService ls, IConfigSettings configSettings) +1295
DynamicInjector3f592a0195c345d8a7d555c4c4085e12(Object[] ) +128
Ninject.Activation.Context.Resolve() +279
System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +237
System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source) +298
System.Linq.WhereSelectArrayIterator`2.MoveNext() +109
System.Linq.Buffer`1..ctor(IEnumerable`1 source) +487
System.Linq.Enumerable.ToArray(IEnumerable`1 source) +103
Ninject.Activation.Providers.StandardProvider.Create(IContext context) +479
Ninject.Activation.Context.Resolve() +279
System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +237
System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source) +298
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +67
[InvalidOperationException: An error occurred when trying to create a controller of type 'DataPortal.Controllers.KpiController'. Make sure that the controller has a parameterless public constructor.]
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +247
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +85
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +280
System.Web.Mvc.<>c__DisplayClass6.<BeginProcessRequest>b__2() +66
System.Web.Mvc.<>c__DisplayClassb`1.<ProcessInApplicationTrust>b__a() +19
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Func`1 func) +161
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +405
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375
it was a dependency issue in the end. The project had a dependency on another project that hadn't been deployed.
It seems one of your argument "LoggingService or ConfigSettings" is not configured properly in your web.config. Check your previous working version config file.
In some cases it can be related to a problem with the database for example :
a select which returns a null value without a correct exception handling would cause the same error. Therefore,one needs to check his sql requests.
Related
i have to change the port of website for ssl proxy implementation but the site is not working when im trying to listen to any other port than 80 (ex:81,82,90,8443, 9443 etc).
The site works fine in port 80, other ports getting below error,
**
Server Error in '/' Application.
**
No parameterless constructor defined for this object.
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.MissingMethodException: No parameterless constructor defined for this object.
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:
[MissingMethodException: No parameterless constructor defined for this object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +159
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +256
System.Activator.CreateInstance(Type type, Boolean nonPublic) +127
System.Activator.CreateInstance(Type type) +11
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +92
[InvalidOperationException: An error occurred when trying to create a controller of type 'WRIPMS.Controllers.LoginController'. Make sure that the controller has a parameterless public constructor.]
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +256
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +81
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +280
System.Web.Mvc.<>c__DisplayClass6.b__2() +80
System.Web.Mvc.<>c__DisplayClassb1.<ProcessInApplicationTrust>b__a() +19
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Func1 func) +128
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +12650919
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
The error indicates that one of your controllers has a constructor that accepts a parameter. This is normal for an application with dependency injection. To make it work, you must create a custom IControllerFactory and inject it at application startup using
ControllerBuilder.Current.SetControllerFactory(new MyControllerFactory());
Since your application is working on port 80, I suspect that you have a controller factory (or a dependency of controller factory) that has something hard coded to work with port 80 only.
Im sorry it was my mistake there was some redundant entries in my web.config like Keys having path to save error log and all. My understanding was it wont make any troubles. It was working in local servers too. Well it got worked when i cleaned web.config redundant entries.
thank you.
I am currently developing an ASP.NET MVC application that uses Unity for the IoC container. The solution is deployed to Windows Azure using a SQL Azure backend and implments Azure Caching.
After deploying the app to Windows Azure everything seems to work fine. But then after a few requests I get the error "An attempt was made to access a socket in a way forbidden by its access permissions".
For example, if I browse to the site and repeatedly initiate an AJAX POST (e.g. autocomplete input) request it will work fine for the first few requests, but then crash out (by means of displaying a HTTP 500 error in the Chrome Dev Tools console). Then if I try and fresh the page I get the sockets error until the app is restart or the pool is recycled.
Even if I flick between pages I get the same error after a while, i.e. it's not just isolated to the AJAX request. The AJAX request is just the quickest way to replicate the issue.
I'm wondering if the error An error occurred when trying to create a controller of type 'MySite.Web.MVC.Controllers.LocationsController'. Make sure that the controller has a parameterless public constructor.] in the stack trace is a red herring because the ILocationCacheService mapping used by the controller is being resolved by Unity. The AJAX request works for the first few times so it definitely resolves the mapping.
Everything works fine locally, or at least I can't replicate the error.
Stack Trace
Server Error in '/' Application.
An attempt was made to access a socket in a way forbidden by its access permissions
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.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions
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:
[SocketException (0x271d): An attempt was made to access a socket in a way forbidden by its access permissions]
System.Net.Sockets.Socket.DoMultipleAddressConnectCallback(Object result, MultipleAddressConnectAsyncResult context) +1847654
System.Net.Sockets.Socket.DoDnsCallback(IAsyncResult result, MultipleAddressConnectAsyncResult context) +34
System.Net.Sockets.Socket.BeginConnect(String host, Int32 port, AsyncCallback requestCallback, Object state) +271
Microsoft.ApplicationServer.Caching.SocketConnectionFactory.BeginConnect(String host, Int32 port, AsyncCallback callback, Object state, TimeSpan timeout) +469
Microsoft.ApplicationServer.Caching.TcpClientChannelFactory.BeginConnect(String host, Int32 port, AsyncCallback callback, Object state) +119
Microsoft.ApplicationServer.Caching.TcpClientChannel.ConnectAsync() +368
Microsoft.ApplicationServer.Caching.SocketClientChannel.TryGetTcpChannelUntilTimeout(TcpClientChannel clientChannel, ITcpChannel& chnl) +41
Microsoft.ApplicationServer.Caching.SocketClientChannel.Send(EndpointID endpoint, IVelocityRequestPacket packet) +188
Microsoft.ApplicationServer.Caching.SocketClientChannel.Send(EndpointID endpoint, ICreateMessage message) +112
Microsoft.ApplicationServer.Caching.SimpleSendReceiveModule.Send(EndpointID endpoint, RequestBody request, Int32 retries) +73
Microsoft.ApplicationServer.Caching.SimpleSendReceiveModule.SendMsgAndWait(EndpointID endpt, RequestBody reqMsg, TimeSpan requestTimeout, IRequestTracker& tracker) +428
Microsoft.ApplicationServer.Caching.SocketClientProtocol.SendMessage(EndpointID endPt, RequestBody request) +52
Microsoft.ApplicationServer.Caching.DataCacheFactory.EstablishConnection(IEnumerable`1 servers, RequestBody request, Func`3 sendMessageDelegate, DataCacheReadyRetryPolicy retryPolicy) +253
Microsoft.ApplicationServer.Caching.<>c__DisplayClass5.<Initialize>b__2(RequestBody req) +83
Microsoft.ApplicationServer.Caching.SocketClientProtocol.SendReceive(IVelocityRequestPacket request, Func`2 delegate, EndpointID& destination) +34
Microsoft.ApplicationServer.Caching.SocketClientProtocol.Initialize(IEnumerable`1 servers) +367
Microsoft.ApplicationServer.Caching.DataCacheFactory.GetCache(String cacheName, CreateNewCacheDelegate cacheCreationDelegate, DataCacheInitializationViaCopyDelegate initializeDelegate) +400
Microsoft.ApplicationServer.Caching.DataCacheFactory.GetCache(String cacheName) +61
Microsoft.ApplicationServer.Caching.DataCacheFactory.GetDefaultCache() +11
MySite.Services.Cache.Implementations.LocationCacheService..ctor(ILocationService locationService) +64
lambda_method(Closure , IBuilderContext ) +176
Microsoft.Practices.ObjectBuilder2.<>c__DisplayClass1.<GetBuildMethod>b__0(IBuilderContext context) +35
Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) +10
Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +196
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +193
Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp(NamedTypeBuildKey newBuildKey) +113
Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context) +48
lambda_method(Closure , IBuilderContext ) +107
Microsoft.Practices.ObjectBuilder2.<>c__DisplayClass1.<GetBuildMethod>b__0(IBuilderContext context) +35
Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) +10
Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +196
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +193
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) +165
[ResolutionFailedException: Resolution of the dependency failed, type = "MySite.Web.MVC.Controllers.LocationsController", name = "(none)".
Exception occurred while: Calling constructor MySite.Services.Cache.Implementations.LocationCacheService(MySite.Services.Interfaces.ILocationService locationService).
Exception is: SocketException - An attempt was made to access a socket in a way forbidden by its access permissions
-----------------------------------------------
At the time of the exception, the container was:
Resolving MySite.Web.MVC.Controllers.LocationsController,(none)
Resolving parameter "locationCacheService" of constructor MySite.Web.MVC.Controllers.LocationsController(MySite.Services.Cache.Interfaces.ILocationCacheService locationCacheService)
Resolving MySite.Services.Cache.Implementations.LocationCacheService,(none) (mapped from MySite.Services.Cache.Interfaces.ILocationCacheService, (none))
Calling constructor MySite.Services.Cache.Implementations.LocationCacheService(MySite.Services.Interfaces.ILocationService locationService)
]
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) +329
Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides) +15
Microsoft.Practices.Unity.UnityContainerExtensions.Resolve(IUnityContainer container, Type t, ResolverOverride[] overrides) +18
Unity.Mvc4.UnityDependencyResolver.GetService(Type serviceType) +67
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +41
[InvalidOperationException: An error occurred when trying to create a controller of type 'MySite.Web.MVC.Controllers.LocationsController'. Make sure that the controller has a parameterless public constructor.]
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +178
System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +77
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +66
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +191
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +50
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
I managed to resolve this issue using connection pooling for cache with maxconnectionstoserver="1". Here is the web.config setting for the datacacheclient section:
<dataCacheClient name="default" isCompressionEnabled="true" maxConnectionsToServer="1" connectionPool="true" useLegacyProtocol="false">
public partial class RegistrationController : Controller
{
private readonly IPartnerRepository _partnerRepository;
public RegistrationController(IPartnerRepository partnerRepository)
{
_partnerRepository =partnerRepository;
}}
I use autoface to the dependancy injection and i have this error:
` No parameterless constructor defined for this object.
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.MissingMethodException: No parameterless constructor defined for this object.
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:
[MissingMethodException: No parameterless constructor defined for this object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +113
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232
System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
System.Activator.CreateInstance(Type type) +6
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +55
[InvalidOperationException: Une erreur s'est produite lors de la tentative de création d'un contrôleur de type « Registration.Front.Web.Controllers.RegistrationController ». Assurez-vous que le contrôleur a un constructeur public sans paramètre.]
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +179
System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +80
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +74
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +197
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +49
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +50
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
`
when i delete from the constructor, i haven't this error:
public partial class RegistrationController : Controller
{
private readonly IPartnerRepository _partnerRepository;
public RegistrationController()
{
}}
How can i resolve this?
ASP.NET MVC has special service that is responsible for creating an instance of controller - this service should implement IControllerFactory interface. Default implementation of the IControllerFactory expects that your controller has a parameterless constructor and invokes it.
If you want to use DI with controllers you have two possible options:
Write your own implementation of IControllerFactory which uses your DI container for instantiating a controller. You can register it in such way:
var factory = new CustomControllerFactory(container);
ControllerBuilder.Current.SetControllerFactory(factory);
Implement IDependencyResolver which can resolve any piece of MVC infrastructure including controllers.
Second option is preferrable.
You can read about this stuff with more details here (it's about Unity container but I think it should give you enough knowledge to do this with Autofac as well.
This can happen for number of reasons, one of them is that the dependency injection is not configured to inject a concrete class of IPartnerRepository.
The second is that if the concrete class itself has a constructor that depends on another dependency being injected, this second constructor is no configured for dependency injection.
And finally this can also happen if the DLL that contains the class being injected cannot be found, but usually the injection framework will tell you that it can't find the DLL.
If you are using Dependency Injection with Unity in an ASP.NET application
I got this problem resolved after I added
UnityConfig.RegisterComponents();
in application start in global.asax
We're running a web application distributed across load balanced 3 web servers. The exact same code base & configuration is deployed across the 3 servers, and since about 1 hour ago I'm getting the following error on one of them, but not the other two.
System.InvalidOperationException: An error occurred when trying to create a controller of type 'XXX.Controllers.HomeController'. Make sure that the controller has a parameterless public constructor. ---> System.MissingMethodException: No parameterless constructor defined for this object.
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType)
--- End of inner exception stack trace ---
at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType)
at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName)
at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state)
at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
We are running this with ASP.NET MVC (with Output Caching), NHibernate (with NHibernate caching) & StructureMap. The cache is not shared, so each web server manages its own cache, though the cache dependencies are the same across the 3 servers.
I don't really know where to start describing what/where it could be going wrong or the circumstances, because it's so strange to me.
I've seen this once before about 2 weeks ago, but it went away on its own after about an hour and I haven't seen it since. Has anyone else seen an error like this before?
Well, it seems your HomeController is missing a parameterless constructor. Are you sure it has one?
The default controller factory needs one to intialize your constructor.
Unless you are using your own ControllerFactory, in which case you need to register it during Application_Start:
protected void Application_Start()
{
//other code
ControllerBuilder.Current.SetControllerFactory(new MyCustomControllerFactory());
}
Assuming you're resolving controllers with structuremap, it may be your components are registered at the wrong place/time.
Are you registering components in Application_Start ?
I'm trying to deploy ASP.NET MVC 3 application wich uses Unity as a IoC container. Application works fine on local server, but when deployed it throws an exception: No parameterless constructor defined for this object. And this is thrown for a controller that should get some repository injected by my Unity DependencyResolver.
I've installed Unity with NuGet so it should be referenced directly, and I've checked that it gets copied to bin folder.
Edit:
Here's the stack trace:
[MissingMethodException: No parameterless constructor defined for this object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +98
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241
System.Activator.CreateInstance(Type type, Boolean nonPublic) +69
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +67
[InvalidOperationException: An error occurred when trying to create a controller of type 'nBlog.Controllers.HomeController'. Make sure that the controller has a parameterless public constructor.]
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +182
System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +80
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +74
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +196
System.Web.Mvc.<>c__DisplayClass6.<BeginProcessRequest>b__2() +49
System.Web.Mvc.<>c__DisplayClassb`1.<ProcessInApplicationTrust>b__a() +13
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Func`1 func) +124
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +98
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +50
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8841400
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +18
Anyone have an idea what might be the problem?
Edit 2:
I've solved the problem by adding references to Mvc libraries (System.Web.Mvc, etc.) in GAC instead of direct references.
Previously the application was referencing Mvc libraries directly and they were bin deployed to hosting server, because server had .net 4.0 and mvc 2 installed, but since hosting provider installed Mvc 3, I've changed to references to GAC. I guess it was some security issue, but I'm new to this application security in hosted environments and I would really like to know what exactly was the problem? Resource links would also be appreciated.
If Unity uses Reflection internally to construct classes and dependencies, then you will have an implicit dependency on your application being run in Full Trust.
Many shared hosting providers only allow up to Medium Trust, so it could be that Unity is being prevented from reflecting your code at runtime. You might be able to request that your application be run in Full Trust, but it depends on your hosting provider.
Some similar experiences from Rick Strahl's blog here
[EDIT]
Try testing locally by editing your web.config file:
<location allowOverride="false">
<system.web>
<!-- level="[Full|High|Medium|Low|Minimal]" -->
<trust level="Medium" originUrl=""/>
</system.web>
</location>