Postsharp compile error Ambiguous match System.Runtime.InteropServices - postsharp

I'm trying to add PostSharp Logging to a .NET Framework app. I'm getting this error. How do I resolve it? Is there a way to tell PostSharp which type it should map to?
Unhandled exception (postsharp-x86-srv.exe 6.10.8 release | .NET Framework 4.8 (X86)): PostSharp.Sdk.CodeModel.BindingException:
Ambiguous match: need to map 'System.Runtime.InteropServices.ImportedFromTypeLibAttribute, System.Runtime.InteropServices, Culture=neutral, Context=Runtime' and have several candidates:
'System.Runtime.InteropServices.ImportedFromTypeLibAttribute, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, Context=Reference'
'System.Runtime.InteropServices.ImportedFromTypeLibAttribute, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, Context=Reference.

Related

The type 'MaxLengthAttribute' exists in both 'EntityFramework, and 'System.ComponentModel.DataAnnotations

I am doing some spring cleaning on a legacy Web Api 2 project (target 4.5). As part of the the nuget updates, I moved Microsoft.AspNet.WebApi.HelpPage from version 5.0.0 to 5.2.3. Once I do that, I am getting the following message:
Error CS0433 The type 'MaxLengthAttribute' exists in both
'EntityFramework, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' and
'System.ComponentModel.DataAnnotations, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35'
It looks like this was a problem a while back when they moved that class from EF to DataAnnotations and the solution was to upgrade EF. Since I have the most recent stable version of EF (5.2.3), I am not sure what else to do. I tried removing System.ComponentModel.DataAnnotations from the using statements, but then it doesn't pick up the EF MaxLengthAttribute. Cleaning and rebuilding the solution also does not work.
Any pointers are appreciated.

Nuget.exe fails with "Could not load file or assembly 'System.Net.Http...'

I am trying to run "nuget restore" on a server that does not have a Visual Studio installation. But nuget.exe fails immediately. What else needs to be installed for NuGet to run?
C:\Users\kevin>nuget help
Could not load file or assembly 'System.Net.Http,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or
one of its dependencies. The system cannot find the file specified.
Could not load type
'System.Runtime.CompilerServices.IAsyncStateMachine' from assembly
'mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'. Could not load file or assembly
'System.Net.Http.WebRequest, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The
system cannot find the file specified.
Had this issue as well. Newer versions of NuGet requires .NET 4.5. installing .NET 4.5.2 resolved the issue for me.

Prevent inheritance of incompatible configuration section in child application

Project A
uses entity framework 4.4.0.0 and has below entry in web.config
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
Project B
uses entity framework 6.0.0.0 and has below entry in web.config
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
Project B is hosted under Project A in IIS (Project B was virtual directory, later converted to web application)
If I access project B, it shows message in browser that there is duplicate entry of entity framework.
I commented entry in project B
<!--<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />-->
This makes Project B run, but as soon it access data from database, an exception is thrown.
An error occurred creating the configuration section handler for entityFramework: Could not load file or assembly 'EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies.
I cant edit Project A EF or Project B EF, as I don't have access
Any suggestions on how to deal with this?
You can do that by disallowing inheritance of the section. To do so, you can add this atribute to what shouldn't be inherited in the parent web.config: inheritInChildApplications="false"
As explained here not all elements suport it, so perhaps you have to do it in a parent, and redefined all the other things that should be inherited: How to stop inheritance of <configSections>in Web.Config This is a good solution for it: Avoid web.config inheritance in child web application using inheritInChildApplications
You can also see the 7th tip of this asp.net log: 10 Things ASP.NET Developers Should Know About Web.config Inheritance and Overrides

Umbraco gets error on dev server

I just published my local version to a dev server. My local is working perfectly, but the dev has an error:
Could not load file or assembly 'System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Does anybody know how can I fix it?
I started to use VS 2015, because of nuget version. Now I got some different error in the output box:
No way to resolve conflict between "System.Net.Http.Formatting, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" and "System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". Choosing "System.Net.Http.Formatting, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" arbitrarily.
1> Consider app.config remapping of assembly "System.Net.Http.Formatting, Culture=neutral, PublicKeyToken=31bf3856ad364e35" from Version "5.0.0.0" [] to Version "5.2.3.0" [F:\Projects\frs\frs\bin\System.Net.Http.Formatting.dll] to solve conflict and get rid of warning.
1> Consider app.config remapping of assembly "System.Web.WebPages, Culture=neutral, PublicKeyToken=31bf3856ad364e35" from Version "1.0.0.0" [] to Version "2.0.0.0" [F:\Projects\frs\frs\bin\System.Web.WebPages.dll] to solve conflict and get rid of warning.
1> Consider app.config remapping of assembly "System.Web.Mvc, Culture=neutral, PublicKeyToken=31bf3856ad364e35" from Version "3.0.0.0" [] to Version "4.0.0.0" [F:\Projects\frs\frs\bin\System.Web.Mvc.dll] to solve conflict and get rid of warning.
Maybe this will help
https://our.umbraco.org/forum/getting-started/installing-umbraco/53820-Could-not-load-file-or-assembly-SystemNetHttp-after-upgrade-to-v-621
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
to this:
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
I had the same problem with Umbraco. I have installed Umbraco v7.4.3 and I tried the Ucalendar Package in it.
You have to remove the Package and restore the app_data and config folders.

Using Asp.net Identity in with Entity Framework throws Could not load type .Schema.IndexAttribute' from assembly 'EntityFramework, Version=6.0

public EmployeeDTO AuthenticateEmployee(string username, string password)
{
try
{
var userLogin = UnitOfWork.UserLoginRepository.Get(x => x.UserName == username).FirstOrDefault();
if (userLogin == null)
return null;
else
{
var userStore = new UserStore<IdentityUser>();
var userManager = new UserManager<IdentityUser>(userStore);
// this throws an error.
var user = userManager.Find("username", "password");
}
}
}
Results in error:
Could not load type 'System.ComponentModel.DataAnnotations.Schema.IndexAttribute' from assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
I'm using EF 6.0, Microsoft.AspNet.Identity.EntityFramework Ver 2.0.
I couldn't perform any action based on EF using Identity is there anything I have to do, my EDMX is in another class library. I think its a DLL issue.
Please help me to use identity with EF.
I have gone through Msdn
IndexAttribute is one of the new things included in EF 6.1. So the problem is that you're referencing the wrong EF version (6.0). Please reference 6.1 in your project.
Look at EF Version History.
I also had this error but all the EntityFramework references in packages.config were pointing to the latest EF version (in my case 6.1.3). I unloaded the offending project where the error was occuring from and noticed the Hint paths for EF were old. After updating them, they worked fine.
Old References:
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
<Private>True</Private>
</Reference>
Updated working references:
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
<Private>True</Private>
</Reference>