Solving Autofac issue Inheritance security rules violated while overriding member GetService - autofac

I've got an ASP.NET MVC application using Autofac.
I've added the appropriate packages via:
Install-Package Autofac
Install-Package Autofac.Mvc4
When I ran the web application, this error was throw:
Inheritance security rules violated while overriding member: 'Autofac.Integration.Mvc.AutofacDependencyResolver.GetService(System.Type)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.
How can this be solved?

I had installed Autofac for MVC 4 when the project type was actually MVC 5.
To solve this, I ran Uninstall-Package Autofac.Mvc4 and
Install-Package Autofac.Mvc5

Related

Using Autofac Ioc InstancePerHttpRequest with Servicestack 5.1.0

We have recently upgraded our API's (using Forms Authentication) Servicestack version 4.0.40 to latest stable version of Servicestack (V5.1.0). We use Autofac Ioc registration using InstancePerHttpRequest for API's (this is using Autofac.Integration.Mvc from Autofac.Mvc4 package).
Below code does not work anymore after servicestack upgrade.
this.UseAutofac(afcBuilder.Build());
Error CS0012 The type 'ServiceStackHost' is defined in an assembly
that is not referenced. You must add a reference to assembly
'ServiceStack, Version=4.0.48.0, Culture=neutral,
PublicKeyToken=null'.
So we have tried alternate ways to make it work using InstancePerDependency but that is causing missing "ASP.NET_SessionId" cookie value after API authentication.
Please suggest code to get actual "InstancePerHttpRequest" work with latest ServiceStack version.
I've already answered this question in ServiceStack Customer Forums but for anyone else's benefit with similar issues I'll include it below:
The issue isn't with ServiceStack or AutoFac it's with one of your dependencies which still has a binary reference to an old v4.0.48 of ServiceStack (highlighted in the Exception). You can't mix and match ServiceStack .dlls from different versions so you would need to re-compile whichever assembly has the old binary ServiceStack reference to use the version of ServiceStack you're using.
Autofac wouldn't have a dependency to ServiceStack, it would be one of your dependencies that is registered with Autofac. You can either use an Assembly inspector like JetBrains dotpeek and inspect the .dll references of each dll reference in your project or comment out registrations until you find the one with the dependency.
Basically you're unlikely to get anywhere focusing on ServiceStack or Autofac .dll's, you need to find the .dll that has a reference to ServiceStack v4.0.48 and re-compile it to use the version of ServiceStack you've upgraded to.
If you look at the dependency of Autofac.Mvc4, you'll see it only has a dependency to Autofac. Autofac's not going to have a dependency to ServiceStack v4.0.48, one of your own .dll's is going to have the old binary reference that's causing the issue.

Ioc container for Web Api 2.2

I'm looking into using a IOC container for Web Api 2.2 (recently released). I want to use it as a dependency resolver for Web API controllers along with injecting my own dependencies.
I've tried using Unity and Autofac, using there Web Api nuget packages, without success. I've come to conclusion that they doesn't support Web Api 2.2 (yet).
Is there any other known IOC container that support Web Api 2.2?
Added assembly redirects to System.Web.Http 5.2.0.0 and got rid of the exceptions. Also noted that I hadn't registered all types (dependencies of the controller) and therefore the controller wasn't instantiated.
Thanks, works fine now. Is it possible to get Unity to throw exception if it fails to instantiate due to lacking dependencies instead of being silent?

BreezeJS compatibility with Entity Framework (EF) 6.1

I have just updated (via NuGet) to EntityFramework version 6.1 and Breeze.Server.ContextProvider.EF6 version 1.4.11.
My repository (which extends Breeze.ContextProvider.EF6.EFContextProvider) now shows an error when I try to override BeforeSaveEntity saying that there is no suitable method for override.
protected override bool BeforeSaveEntity(EntityInfo entityInfo) {
My controller then tries to access various breeze functions from the repository and receives errors saying that the symbols can not be resolved.
this.Repository.Metadata();
and
this.Repository.SaveChanges(saveBundle);
It seems to me that ContextProvider.EF6 is not compatible with EF6.1?
Found the solution.
Ensure that Nuget Package Restore is enabled.
Delete the packages folder.
Restore all the packages (either by building the application or going to the Package Manager and allowing it to restore the packages.
Problem solved :).

Does DotNetOpenAuth 4.3 work with Entity Framework 6?

I created an empty project in VS2013 and added these packages:
DotNetOpenAuth.AspNet
Microsoft.AspNet.Providers.Core
Microsoft.AspNet.Providers.LocalDb
Microsoft.AspNet.Membership.OpenAuth
In the process, Entity Framework 5 was added to the project. I manually installed EF6 and now I get this error when I try to authenticate a user with an external provider:
"Method not found: 'System.Data.Objects.ObjectContext System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext()'."
I checked the DNOA documentation but it does not say a word about dependencies/requisites.
Does anybody know if DotNetOpenAuth can work with EF6?
DotNetOpenAuth does not have EntityFramework as a dependency. The samples however do use EF. You must have some of your own code that uses entity framework.
That said, it sounds to me like you need to add a binding redirect or jiggle your entityframework configuration a bit in your web.config file.

ASP.NET MVC 2 site issues when updated IIS7 to .NET 4.5

I have a web app running ASP.NET MVC 2 along with other sites (using ASP.NET MVC 4), updated IIS7 to use .NET 4.5 and my MVC2 app stop working properly:
Issue: (blocker)
There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined
the solution:
comment out a section of web.config, based on http://forums.asp.net/p/1571308/3939106.aspx:
Issue: (blocker)
Login stop working, the solution add this line <machineKey validation="SHA1"/> to web.config, based on Login fails after upgrade to ASP.net 4.0 from 3.5:
Issue:
One of the views is giving a Compilation Error:
CS0104: 'ContainerType' is an ambiguous reference between
'System.Web.DynamicData.ContainerType' and
'MVFleet2.Core.ContainerType'
on this line :
<%foreach (var specs in (List<ContainerType>)ViewData["ContainerTypes"])
This error never happened before the update, I know the obvious solution is to use the full name for the cast, but I'm looking for a solution so i can force the web app to run in the context of .NET 3.5 and bypass this issues, so i don't have to deal with this and probably more issues in the future... is this possible?
If you want to use the older version of the framework (.net 3.5), you need to change the Application Pool in IIS to run as .Net 2.0.
You should fully qualify the ContainerType type definition to MVFleet2.Core.ContainerType.ContainerType.