TypeLoadException when using Autofac.Mvc5 (3.2.0) Integration - autofac

Getting the TypeLoadException when using some of the registration extension methods.
builder.RegisterModelBinders(Assembly);
builder.RegisterModelBinderProvider();
builder.RegisterFilterProvider();
The following respective exceptions are thrown, however builder.RegisterControllers(Assembly) works fine.
TypeLoadException: Inheritance security rules violated while overriding member: 'Autofac.Integration.Mvc.AutofacModelBinderProvider.GetBinder(System.Type)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.
at Autofac.Integration.Mvc.RegistrationExtensions.RegisterModelBinders(ContainerBuilder builder, Assembly[] modelBinderAssemblies)
TypeLoadException: Inheritance security rules violated while overriding member: 'Autofac.Integration.Mvc.AutofacModelBinderProvider.GetBinder(System.Type)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.
at Autofac.Integration.Mvc.RegistrationExtensions.RegisterModelBinderProvider(ContainerBuilder builder)
TypeLoadException: Inheritance security rules violated by type: 'Autofac.Integration.Mvc.AutofacFilterProvider'. Derived types must either match the security accessibility of the base type or be less accessible.
at Autofac.Integration.Mvc.RegistrationExtensions.RegisterFilterProvider(ContainerBuilder builder)
Here are what the relevant packages packages.config look like:
<package id="Autofac" version="3.3.0" targetFramework="net45" />
<package id="Autofac.Mvc5" version="3.2.0" targetFramework="net45" />
<package id="Autofac.Wcf" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc" version="5.1.0" targetFramework="net45" />
If it's any consolation, the previous Autofac.Mvc5 package was throwing the same error.
These are the binding redirects for Autofac:
<dependentAssembly>
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>

I had this error after upgrading from MVC 4 to MVC 5 , it didn't update the nuget package for autofac mvc integration which was stil on mvc 4 , so uninstall/reinstall under nuget of all autofac libraries fixed this error for me.

I rebuilt the test project's .csproj and the test passes now, I have not isolated the exact issue. If I find it, I will post it here.

Related

Unable to find version '4.2.1.188' of package 'Glass.Mapper'

I am new to Sitecore and Glass.Mapper tools. I am working with Visual Studio 2013 and Sitecore 8.1 for a solution I have begun working on (not the author).
Due to other questions I have observed, I will try to demonstrate what my solution now has in it to remove build errors.
My packages.config includes the following:
<package id="Glass.Mapper" version="4.2.1.188" targetFramework="net45" />
<package id="Glass.Mapper.Sc" version="4.2.1.188" targetFramework="net45" />
My nuget.config includes the following:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<packageSources>
<add key="nuget v2" value="https://www.nuget.org/api/v2" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
I have added these as project references to each of these Dlls from our Packages directory, which also includes the following in a few of the projects:
<package id="Glass.Mapper.Sc.CastleWindsor" version="3.3.0.25" targetFramework="net45" />
<package id="Glass.Mapper.Sc.Core" version="4.2.1.188" targetFramework="net45" />
<package id="Glass.Mapper.Sc.Mvc-5" version="3.3.0.45" targetFramework="net45" />
Solution errors have been reduced from several hundred to ~20, mostly due to this issue, and the Metadata file "..." could not be found errors which appear since dependent projects fail to generate their project Dlls.
We cannot upgrade Nuget in place, and we cannot perform upgrades using Manage Nuget Packages for Solution due to code in place which references deprecated methods in key packages.
If you browse packages on nuget.org with your web browser, you can guess the pattern for viewing a specific version of a package. So, version 4.2.1.188 of GlassMapper will use the URL https://www.nuget.org/packages/Glass.Mapper/4.2.1.188
There, I see a message saying
The owner has unlisted this package. This could mean that the package is deprecated or shouldn't be used anymore.
So the package exists, so existing packages should be able to restore it, but the owner has delisted it to reduce the probability that new projects will start using it. Interestingly the package owner has delisted all versions of the package, suggesting the package is deprecated.
Anyway, as I mentioned, normally the package can still be restored (that's the point of unlisting vs deleting). So my best guess is that the version of NuGet that works with Visual Studio 2013 doesn't support unlisted packages as it's really, really old.
You could download nuget.exe from nuget.org/downloads, restore from the command line and then use Visual Studio. Otherwise you'll probably need to upgrade to a newer version of Visual Studio.

Is there a Lightspeed 5.x NuGet package that can be used with ASP.Net 5?

I did a search on NuGet and couldn't find a Lightspeed NuGet package.
I have pro license for Lightspeed 5 so I have all the binaries I need to use Lightspeed in a non-ASP.Net 5 code.
However, it is my understanding that ASP.Net 5 doesn't allow you to allow you to reference DLLs directly, you have to create a NuGet package first.
So, I created a NuGet package of my POCO objects, DB context and Lightspeed references and added it to a .Net Framework 4.5 console application; it added the appropriate references (NuGet spec I used is show below).
<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$id$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<copyright>Copyright 2015</copyright>
<references>
<reference file="$id$.dll" />
<reference file="Mindscape.LightSpeed.dll" />
<reference file="Mindscape.LightSpeed.Linq.dll" />
</references>
</metadata>
<files>
<file src="..\Mindscape.Lightspeed\Mindscape.LightSpeed.dll" target="lib\net45\Mindscape.LightSpeed.dll" />
<file src="..\Mindscape.Lightspeed\Mindscape.LightSpeed.Linq.dll" target="lib\net45\Mindscape.LightSpeed.Linq.dll" />
</files>
</package>
However, this didn't work as expect when I tried to add this package to my to my ASP.Net 5 website (package added but using statement causes a compiler error).
Does anyone know a work-around to get Lightspeed working with ASP.Net 5?
Ideally Mindscape would publish a NuGet package.
Turns out the have their own NuGet feed that is listed in the "Keys" section of your subscription

sqlite .net 1.0.92.0 entity framework 6

It's not duplicate question, because it's for new release of sqlite.
I can't build entity data model database first from sqlite database, here is my packages :
<packages>
<package id="EntityFramework" version="6.0.2" targetFramework="net451" />
<package id="System.Data.SQLite" version="1.0.92.0" targetFramework="net451" />
<package id="System.Data.SQLite.Core" version="1.0.92.0" targetFramework="net451" />
<package id="System.Data.SQLite.EF6" version="1.0.92.0" targetFramework="net451" />
<package id="System.Data.SQLite.Linq" version="1.0.92.0" targetFramework="net451" />
</packages>
when I want to build entity data model with "Ado.Net Entity Data Model" it can't and give me this error :
Your project references the latest version of Entity Framework; however, an Entity Framework database provider compatible with this version could not be found for your data connection. Exit this wizard, install a compatible provider, and rebuid your project before performing this action.
For some reason the EF6 assemblies were not in the references. By manually adding the system assemblies System.Data.Entity and System.Data.Entity.Design solved the problem, though VS gave me a warning about not using the latest EF, but the designer finally worked OK.

Only NUnit error: Could not load file or assembly 'EntityFramework'

I get an error message in NUnit when I try to run a specific test. The error looks like this:
ChatProj.Tests.MessageRepositoryTests.Logg_LoggWorking_AssertView:
System.IO.FileLoadException : Could not load file or assembly 'EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Here is a picture
I've looked at the 2 projects in my solution, and I'm refrencing EF 6.0.0.0 in both. I've tried to look up the PublicKeyToken=b77a5c561934e089 and this is what I found in my solution. It's extra weird because I've no problem debugging or building the webapp, and the other unittests are testing within the same project (same EF version) and not reciving this error (as you can see in the picture from before).
Any idea what could be causing this problem?
UPDATE:
I think I figured it out. I was using nuget.org/packages/FakeDbSet which was using a command like : var mockItemList = new InMemoryDbSet { new Message {MessageID = 5000, Name ="Erland", MessageString ="Foo Bar", MessageDate = DateTime.Now} }; which somehow is an old way of faking entity framework code. Can be seen here: i.imgur.com/f6dnJbq.png
First, ensure that the EF DLL is actually getting pulled into the bin folder for the test application. If it is and the DLL is for EF v6, do you see version redirects for EF in your app.config for the test project? Something like this?
<configuration>
<!-- Leave the rest of the configuration file alone and just add the runtime area as follows: -->
<runtime>
<assemblyBinding>
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
If not, try pasting that into the app.config.
Sorry, it's hard to fully diagnose without more information.

The type or namespace name 'Mvc' does not exist in the namespace 'System.Web'

After converting a Hybrid ASP.NET MVC1 app to MVC2 I'm getting the following error when I try and run the application:
The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
The allegeded culprit in the web.config file is System.Web.Mvc:
<namespaces>
<add namespace="System.Web.Mvc"/>
<add namespace="System.Web.Mvc.Ajax"/>
<add namespace="System.Web.Mvc.Html"/>
So far my investigation seems to lead me to believe that version 2 of System.Web.Mvc is not installed or has not been picked up.
I've tried creating a File > New Project based on MVC 2 and that's picking up the new (v2) version of MVC. I've also converted some other projects (that were not hybrids) and they've converted without problem to MVC2.
I've also uninstalled MVC1 to try and remove references to it from the GAC. However, none of this has worked.
Any ideas?
Make sure you have the binding redirect in your Web.config:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Web.Mvc" />
</dependentAssembly>
</assemblyBinding>
</runtime>
This forces MVC 2 even if MVC 1 is on the machine.
Also: MVC 1 does have a System.Web.Mvc namespace, so make sure you also have:
<assemblies>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
I came across somthing similar and the solution was to change the reference to Microsoft.Web.Mvc so Copy Local was set to True.
I had the same error and clicking the detailed compilation error link in the page showed problems with System.Web.Helpers, .Http, and .WebPages.
After backing up the system I ran update-package -reinstall' and forced an uninstall/reinstall of all packages. This forced the web.config file to be rebuilt correctly and the dependentAssembly sections were constructed right.
After rebuilding the solution it ran first time.
Note, it did add the following bad providers section to the web.config.
<contexts>
<context type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</contexts>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
This only generates a build warning, but I did remove it in favor of the preceeding contexts element.