I'm converting an MVC3 web project to MVC4. I created a ElmahHandleErrorAttribute that inherits from HandleErrorAttribute that worked fine in MVC3 and also works fine on my local dev machine, but it throws the following exception in the test environment...
[InvalidOperationException: The given filter instance must implement one or more of the following filter interfaces: IAuthorizationFilter, IActionFilter, IResultFilter, IExceptionFilter.]
System.Web.Mvc.GlobalFilterCollection.ValidateFilterInstance(Object instance) +110
System.Web.Mvc.GlobalFilterCollection.AddInternal(Object filter, Nullable`1 order) +17
System.Web.Mvc.GlobalFilterCollection.Add(Object filter) +12
Home2Me.MvcApplication.RegisterGlobalFilters(GlobalFilterCollection filters) in c:\###\Home2Me\Global.asax.cs:16
Home2Me.MvcApplication.Application_Start() in c:\###\Home2Me\Global.asax.cs:118
[HttpException (0x80004005): The given filter instance must implement one or more of the following filter interfaces: IAuthorizationFilter, IActionFilter, IResultFilter, IExceptionFilter.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9249709
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +131
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253
[HttpException (0x80004005): The given filter instance must implement one or more of the following filter interfaces: IAuthorizationFilter, IActionFilter, IResultFilter, IExceptionFilter.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9164336
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256
There isn't really anything special about the class. It's pretty close to the standard one for Elmah.
public class ElmahHandleErrorAttribute : System.Web.Mvc.HandleErrorAttribute
{
/// <summary>
/// Called when an exception occurs.
/// </summary>
/// <param name="context"></param>
public override void OnException(ExceptionContext context)
{
base.OnException(context);
if (!context.ExceptionHandled) return; // if unhandled, will be logged anyhow
var e = context.Exception;
HandleException(e);
}
... (code snipped for brevity) ...
}
And here is the code that registers the filter in Global.asax.cs...
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new ElmahHandleErrorAttribute());
}
The filter is defined in a separate assembly that is also updated to MVC4. I have multiple projects that use this filter. One of them works fine in the test environment, and another has this same exact issue.
Any ideas on what might be wrong? I'm fairly confident that all the MVC3 references have been updated correctly in the project, including the web.config files in both the root and views directory. It does work locally and I uninstalled MVC3 and deleted all the "extra" MVC3 dlls lying around.
I believe I found an answer. I added a runtime section in the root web.config file to convert MVC3 references to MVC4.
<configuration>
... (snipped for brevity) ...
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
I would rather fix whatever it is that is referencing MVC3, but I can't figure out what that might be. This will have to be a good enough answer for now.
Related
After installing the latest version of Sensenet, the following error is displayed when application is started with debugging:
SenseNet.ExclusiveLock.MsSql component is missing.
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.InvalidOperationException: SenseNet.ExclusiveLock.MsSql component is missing.
Source Error:
Line 13: protected override void Application_Start(object sender, EventArgs e, HttpApplication application)
Line 14: {
Line 15: base.Application_Start(sender, e, application);
Line 16:
Line 17: AreaRegistration.RegisterAllAreas();
Source File: c:\users\administrator\source\repos\WebApplication4\WebApplication4\Global.asax.cs Line: 15
[InvalidOperationException: SenseNet.ExclusiveLock.MsSql component is missing.]
SenseNet.ContentRepository.RepositoryVersionInfo.IsComponentAllowed(SnComponentInfo component, Version installedComponentVersion) +217
SenseNet.ContentRepository.RepositoryVersionInfo.CheckComponentVersions(SnComponentInfo[] components, Boolean release) +237
SenseNet.Services.SenseNetGlobal.Application_Start(Object sender, EventArgs e, HttpApplication application) in C:\agent-02\_work\2\s\src\Services\SenseNetGlobal.cs:166
WebApplication4.MvcApplication.Application_Start(Object sender, EventArgs e, HttpApplication application) in c:\users\administrator\source\repos\WebApplication4\WebApplication4\Global.asax.cs:15
SenseNet.Portal.Global.Application_Start(Object sender, EventArgs e) in C:\agent-02\_work\2\s\src\Services\Global.cs:15
[HttpException (0x80004005): SenseNet.ExclusiveLock.MsSql component is missing.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +10107111
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +123
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +181
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +228
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +314
[HttpException (0x80004005): SenseNet.ExclusiveLock.MsSql component is missing.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10087352
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +99
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +263
I followed installation instructions closely and no build errors were reported.
you have a previous version of sensenet and you upgraded the NuGet packages, am I correct? It seems that this combination does not work, because the component above is installed automatically by the new infrastructure - which is not compatible with your version. The only solution I see here is to downgrade the packages to their older versions (at least last August, maybe older). SenseNet has changed a lot since we moved to .Net Core, and there are some incompatibilities with the .Net Framework libraries. Please consider taking a look at the new "sensenet as a service" solution that will free you from the upgrade hassle.
I have an ASP .Net Core 2.2 Web API. In it, I have an endpoint where the front-end (Angular app) can send a file to the API, and the API in turn uploads this file to an Amazon S3 bucket (us-east-1 region).
This works perfectly while I'm debugging in Visual Studio, but when I publish to my server (Windows Server 2016) I get the following exception:
Error: Exception has been thrown by the target of an
invocation. at System.RuntimeMethodHandle.InvokeMethod(Object
target, Object[] arguments, Signature sig, Boolean constructor,
Boolean wrapExceptions) at
System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Amazon.Extensions.NETCore.Setup.ClientFactory.CreateClient(Type
serviceInterfaceType, AWSCredentials credentials, ClientConfig config)
at
Amazon.Extensions.NETCore.Setup.ClientFactory.CreateServiceClient(ILogger
logger, Type serviceInterfaceType, AWSOptions options) at
Amazon.Extensions.NETCore.Setup.ClientFactory.CreateServiceClient(IServiceProvider
provider) at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite
factoryCallSite, ServiceProviderEngineScope scope) at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(IServiceCallSite
callSite, TArgument argument) at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite
scopedCallSite, ServiceProviderEngineScope scope) at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitSingleton(SingletonCallSite
singletonCallSite, ServiceProviderEngineScope scope) at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(IServiceCallSite
callSite, TArgument argument) at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite
constructorCallSite, ServiceProviderEngineScope scope) at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(IServiceCallSite
callSite, TArgument argument) at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite
scopedCallSite, ServiceProviderEngineScope scope) at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitSingleton(SingletonCallSite
singletonCallSite, ServiceProviderEngineScope scope) at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(IServiceCallSite
callSite, TArgument argument) at
Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.
b__0(ServiceProviderEngineScope scope) at
Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type
serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
at
Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type
serviceType) at
Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider
sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
at lambda_method(Closure , IServiceProvider , Object[] ) at
Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider.<>c__DisplayClass4_0.
b__0(ControllerContext controllerContext) at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass5_0.
g__CreateController|0(ControllerContext
controllerContext) at
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State&
next, Scope& scope, Object& state, Boolean& isCompleted) at
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
at
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
at
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext
context) at
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next,
Scope& scope, Object& state, Boolean& isCompleted) at
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext
httpContext) at
Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext
httpContext) at
PropWorx.API.Middlewares.TenantIdentifier.Invoke(HttpContext
httpContext, SharedContext sharedContext) in
C:\Users\fabsr\source\repos\PropWorx.API\PropWorx.API\Middlewares\TenantIdentifier.cs:line
73 at
Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext
context) at
Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext
context) at
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext
context) at
Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext
httpContext) at
Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext
httpContext, ISwaggerProvider swaggerProvider) at
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext
context) at
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext
context)
I've created the "credentials" file in the %UserProfile%.aws folder.
I've added the following two NuGet packages to the project:
AWSSDK.Extensions.NETCore.Setup
AWSSDK.S3
I have this in my Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddAWSService<IAmazonS3>();
services.AddSingleton<IS3Service, S3Service>();
}
S3Service.cs looks like this:
public class S3Service : IS3Service
{
private readonly IAmazonS3 _client;
public S3Service(IAmazonS3 client)
{
_client = client;
}
// Some methods to upload and delete objects... not important
}
I inject this service to one of my controllers:
public class FilesController : ControllerBase
{
private readonly IS3Service _s3Service;
public FilesController(IS3Service s3Service)
{
_s3Service = s3Service;
}
// Some actions to receive the file... not important
}
The error happens as soon as I call any action in this controller. In fact, the error appears to be happening when the S3Service is injected into the controller's constructor. If I remove the constructor injection, i.e.:
public class FilesController : ControllerBase
{
private readonly IS3Service _s3Service;
public FilesController()
{
}
// Some actions to receive the file... not important
}
The error goes away (but of course doesn't work properly)
Any ideas? Like I said, this works perfectly on my laptop while debugging in VS2017. But it doesn't work when published to the server. All other controllers in the API work fine. It appears to be a problem at the point of injecting the S3Service in the constructor...
I kept it simple. In my local machines, I was keeping the keys in the user-secrets and on the prod server I was keeping those in the IIS configuration file. and was just accessing these values from ConfigurationManager. Basically it was using the new AmazonS3Client(string, string, string) syntax. Also I was using a farily older version of .net core there is a possibility that the issue was fixed. Check out this which seems working.
I changed my code to get IAmazonS3 insatance not through but directly instantiating it inside my IS3Serice method and it worked. Somehow the DI is not able to pick config values and that's why was not able to resolve the object.
You can get some information about this from here
I went through the actual documentation
https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/net-dg-config-netcore.html
and found following:
If you look at the Debug tab in your project's properties, you can see this file is set to Development. This works great for local testing because you can put your configuration in the appsettings.Development.json file, which is read-only during local testing. When you deploy an Amazon EC2 instance that has EnvironmentName set to Production, this file is ignored and the AWS SDK for .NET falls back to the IAM credentials and region configured for the Amazon EC2 instance.
So this could be the reason that your initial configurations didn't work as you were trying to use access keys on production.
Also have a look at following answer
How to set credentials on AWS SDK on NET Core?
I'm testing Ninject, but following the how-to, i find it impossible to make it work. The information on the web is so messy even contradictory. I'm developping a website in MVC 4 on visual studio 2012 and i did install Ninject using Nuget.
So I get an error : "No parameterless constructor defined for this object.". As soon as I enter my controller.
I did the necessary steps :
Nuget installation
in NinjectWebCommon.cs, I did register my Interface in the RegisterServices method.
In my homecontroller I set my object like this :
public ISurvey _survey { get; set; }
[Inject]
public HomeController(ISurvey s)
{
_survey = s;
}
And I get the following error message :
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) +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) +110
[InvalidOperationException: An error occurred when trying to create a controller of type 'Surveys.Controllers.HomeController'. Make sure that the controller has a parameterless public constructor.]
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +247
System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +438
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +226
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +326
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +177
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +88
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +50
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
So I wonder what did I do wrong ? 4 Hours on it, I found that there may be a problem with my web.config file or that It could be a reference missing, or it could be a factory missing. Right now I don't even know what to do. Thanks for your help.
You must also install Ninject.MVC3 (https://www.nuget.org/packages/Ninject.MVC3/) which includes the Ninject Controller Factory, that takes care of instantiating the controllers and injecting the right dependencies into the controller constructor. I am almost certain that if you install Ninject.MVC3 through Nuget, everything gets configured automaticaly.
Without this package, MVC uses its default controller factory, that knows nothing about injecting dependencies.
Check if in your Web.config you have two lines for MVC versioning, I had something like:
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="4.0.0.0-4.0.0.1" newVersion="4.0.0.1" />
</dependentAssembly>
If you do then replace them with one line like, to redirect to highest version that you are using in my case it's 4.0.0.1:
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.1" newVersion="4.0.0.1" />
</dependentAssembly>
This did it for me.
I know there are some questions already on this topic but I am still missing something that is causing this error. I installed ninject.mvc3 package which installs ninject and ninject.web.common packages. No modification was made in global.asax (as suggested in official documentation).
App_Start/NinjectWebCommon.cs's RegisterServices method has the Bind statement after loading the Kernel. I am getting this error with this stack trace when I try to run the site.
[InvalidOperationException: Sequence contains no elements]
System.Linq.Enumerable.Single(IEnumerable`1 source) +379
Ninject.Web.Mvc.NinjectMvcHttpApplicationPlugin.Start() in c:\Projects\Ninject\ninject.web.mvc\mvc3\src\Ninject.Web.Mvc\NinjectMvcHttpApplicationPlugin.cs:53
Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map(IEnumerable`1 series, Action`1 action) in c:\Projects\Ninject\ninject\src\Ninject\Infrastructure\Language\ExtensionsForIEnumerableOfT.cs:32
Ninject.Web.Common.Bootstrapper.Initialize(Func`1 createKernelCallback) in c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\Bootstrapper.cs:53
Ninject.Web.Common.NinjectHttpApplication.Application_Start() in c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\NinjectHttpApplication.cs:81
[HttpException (0x80004005): Sequence contains no elements]
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): Sequence contains no elements]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881540
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12722601
What step am I still missing?
The source says on line 53:
ModelValidatorProviders.Providers.Remove(
ModelValidatorProviders.Providers.OfType<DataAnnotationsModelValidatorProvider>)
.Single());
Have you in some way inhibited the addition of the DataAnnotationsModelValidatorProvider ? Probably not - therefore I suggest you've got two copies of the same logic in your system - do you have >1 NinjectWebCommon.cs ?
Another thing worth trying (in general - I have no specif reason why it should fix this case for you) is see if the same thing still happens when you use the Include Prerelease NuGet packages.
I'm using Castle Windsor 3.1.0 in an ASP .NET 4 MVC application, which is giving me an exception in the Application_Start event when container.Register is called.
The exception is "The invoked member is not supported in a dynamic assembly.". Here's the stack trace:
[NotSupportedException: The invoked member is not supported in a dynamic assembly.]
System.Reflection.Emit.InternalAssemblyBuilder.GetExportedTypes() +56
Castle.Core.Internal.ReflectionUtil.GetAvailableTypes(Assembly assembly, Boolean includeNonExported) in c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\Core\Internal\ReflectionUtil.cs:165
Castle.MicroKernel.Registration.FromAssemblyDescriptor.<SelectedTypes>b__0(Assembly a) in c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\MicroKernel\Registration\FromAssemblyDescriptor.cs:56
System.Linq.<SelectManyIterator>d__14`2.MoveNext() +238
Castle.MicroKernel.Registration.FromDescriptor.Castle.MicroKernel.Registration.IRegistration.Register(IKernelInternal kernel) in c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\MicroKernel\Registration\FromDescriptor.cs:160
Castle.MicroKernel.Registration.BasedOnDescriptor.Castle.MicroKernel.Registration.IRegistration.Register(IKernelInternal kernel) in c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\MicroKernel\Registration\BasedOnDescriptor.cs:530
Castle.MicroKernel.DefaultKernel.Register(IRegistration[] registrations) in c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\MicroKernel\DefaultKernel.cs:506
Castle.Windsor.WindsorContainer.Register(IRegistration[] registrations) in c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\Windsor\WindsorContainer.cs:483
ProductX.Web.Windsor.Installers.ControllerInstaller.Install(IWindsorContainer container, IConfigurationStore store) in C:\TeamProjects\CompanyX.ProductX\Mainline\Admin\ProductX.Web\Windsor\Installers\ControllerInstaller.cs:24
Castle.Windsor.Installer.AssemblyInstaller.Install(IWindsorContainer container, IConfigurationStore store) in c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\Windsor\Installer\AssemblyInstaller.cs:56
Castle.Windsor.WindsorContainer.Install(IWindsorInstaller[] installers, DefaultComponentInstaller scope) in c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\Windsor\WindsorContainer.cs:319
Castle.Windsor.WindsorContainer.Install(IWindsorInstaller[] installers) in c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\Windsor\WindsorContainer.cs:452
ProductX.Web.MvcApplication.InitializeWindsor() in C:\TeamProjects\CompanyX.ProductX\Mainline\Admin\ProductX.Web\Global.asax.cs:41
ProductX.Web.MvcApplication.Application_Start() in C:\TeamProjects\CompanyX.ProductX\Mainline\Admin\ProductX.Web\Global.asax.cs:25
[HttpException (0x80004005): The invoked member is not supported in a dynamic assembly.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9171773
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +131
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253
[HttpException (0x80004005): The invoked member is not supported in a dynamic assembly.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9090876
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256
Here's how I'm calling Register:
container.Register(Classes.FromThisAssembly().BasedOn<IController>().LifestyleTransient());
When I build the application in Debug mode, it's fine. When I build in Release mode, the exception above occurrs. I can't find anything about this error through Google. My suspicion is that some .NET 4 restrictions were introduced with how reflection is done on dynamic assemblies, which is being introduced in this situation as a Release build optimisation.
Any idea anyone?
Looks like you're getting a dynamic assembly being emitted (somehow). Try adding a filter to ignore dynamic assemblies. This should work:
container.Register(Classes.FromThisAssembly().Where(t => !t.Assembly.IsDynamic).BasedOn<IController>().LifestyleTransient());