I have a OneClick program, Project A, that references class library project B. Project B had Json.net version 4.5.0.0 that was upgraded to 7.0.0.0. Upon building project A I get the error messages:
No way to resolve conflict between "Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" and "Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed". Choosing "Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" arbitrarily.
Consider app.config remapping of assembly "Newtonsoft.Json, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" from Version "4.5.0.0" [C:\Program Files (x86)\Microsoft Visual Studio 12.0\Blend\Newtonsoft.Json.dll] to Version "7.0.0.0" [[projectpath]\Newtonsoft.Json.dll] to solve conflict and get rid of warning.
C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1697,5): warning MSB3276: Found conflicts between different versions of the same dependent assembly. Please set the "AutoGenerateBindingRedirects" property to true in the project file. For more information, see http://go.microsoft.com/fwlink/?LinkId=294190.
I have cleaned every project in the solution and rebuilt them. I've closed/opened VS, recleaned, rebuilt, same thing. Manually deleted obj + bin folders, same thing.
I've changed the Settings/Publish/Application Files menu to every variation of inclusion/exclusion for json.net.
And finally, I've global searched in Sublime(VS doesn't pick up everything) for 4.5.0.0 and come up with virtually nothing except the json.net references in the manifest files project A creates. I can't seem to find a single lingering reference to the old library, yet it keeps ending up in the manifest upon building.
I've solved my problem by adding <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> in the .csproj's relevant <PropertyGroup>s, but I'm not sure why it works. Can anyone explain to me what's going on? Is this a bad way to solve this problem?
Related
I have a project file targeting net 472. It depends on a bunch of libraries that are built against netstandard2. Some of those libraries depend upon the Microsoft.Extensions.Primitives library although (as far as I can tell) there is no directly dependency from the root project. When I build it, I see this warning...
Severity Code Description Project File Line Suppression State
Warning Found conflicts between different versions of "Microsoft.Extensions.Primitives" that could not be resolved.
There was a conflict between "Microsoft.Extensions.Primitives, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" and "Microsoft.Extensions.Primitives, Version=5.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60".
"Microsoft.Extensions.Primitives, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" was chosen because it was primary and "Microsoft.Extensions.Primitives, Version=5.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60" was not.
References which depend on "Microsoft.Extensions.Primitives, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" [C:\Users\neilm\.nuget\packages\microsoft.extensions.primitives\5.0.0\lib\net461\Microsoft.Extensions.Primitives.dll].
C:\Users\neilm\.nuget\packages\microsoft.extensions.primitives\5.0.0\lib\net461\Microsoft.Extensions.Primitives.dll
Project file item includes which caused reference "C:\Users\neilm\.nuget\packages\microsoft.extensions.primitives\5.0.0\lib\net461\Microsoft.Extensions.Primitives.dll".
C:\Users\neilm\.nuget\packages\microsoft.extensions.primitives\5.0.0\lib\net461\Microsoft.Extensions.Primitives.dll
References which depend on "Microsoft.Extensions.Primitives, Version=5.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60" [].
C:\Users\neilm\.nuget\packages\lazycache\2.1.3\lib\netstandard2.0\LazyCache.dll
Project file item includes which caused reference "C:\Users\neilm\.nuget\packages\lazycache\2.1.3\lib\netstandard2.0\LazyCache.dll".
C:\Users\neilm\.nuget\packages\lazycache\2.1.3\lib\netstandard2.0\LazyCache.dll
D:\work\code\b6\Backend\CSharp\Libraries\Standard\TableAccess_std\bin\Debug\netstandard2.0\TableAccess_std.dll
D:\work\code\b6\Backend\CSharp\Libraries\Standard\CommsCode_std\bin\Debug\netstandard2.0\CommsCode_std.dll
D:\work\code\b6\Backend\CSharp\Libraries\Standard\Recognisers\bin\Debug\netstandard2.0\Recognisers.dll
The relevant section, elided for readability, is
References which depend on "Microsoft.Extensions.Primitives, Version=5.0.0.0,...
C:\Users\neilm\.nuget\packages\microsoft.extensions.primitives\5.0.0\lib\net461\Microsoft.Extensions.Primitives.dll
Project file item includes which caused reference...
C:\Users\neilm\.nuget\packages\microsoft.extensions.primitives\5.0.0\lib\net461\Microsoft.Extensions.Primitives.dll
which seems to be describing a self-reference. Any idea how this might be occurring? I've tried nuking the package cache, as well as the bin and obj folders but can't seem to get rid of it. TIA.
Edit I should probably add this is just one of a number of System packages for which I am getting this warning. Others include:
System.Diagnostics.DiagnosticsSource
System.Memory.Data
Edit 2 In case it is relevant, the root project is an Azure Cloud Service "Classic" worker role built using the Azure SDK which is why (regrettably) I can't just target .Net5 to try and work around this.
Edit 3 The conflicts appear to be resolved when adding local dependencies at a matching version but I would still like to understand where the original conflict is coming from and what the warning is trying to tell me. I think it is implying that the 472 framework depends on a different version of those packages/dlls but if so it's unclear what the appropriate resolution should be.
I have an ASP.Net project which has several sub projects referenced.
I decided today to update some of my nuget packages to have newer versions, what a mistake it was.
Now when I try to debug my app I get this exception:
System.IO.FileNotFoundException: 'Could not load file or assembly
'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral,
PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The
system cannot find the file specified.'
InnerException : FileNotFoundException: Could not load file or assembly
'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The
system cannot find the file specified.
It seems like it's looking to load 6.0.0.0 which is not referenced by any of my subprojects, maybe one of the other nugetpackages ?
I've followed several questions here to perform different operations including:
- Deleting packages folder in Windows Explorer
- Reinstalling the Newtonsoft.Json package
- Clearing the cache of the package in the settings of VS
- Restoring the packages
- Cleaning my solution
- Restarting VS
I'm using VS 2017 community.
I tried to update several other packages to see if it could be linked and I got many new exceptions so I just decided to stop the mess and rollback everything.
But the problem is still here after the rollback so i'm really unsure about what I should do now.
Links I've checked before: Nuget package installed but references not resolved
https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore-troubleshooting
I spent 2 days googling, trying to resolve conflict situation with dll versioning in Xamarin. I saw a lot of posts with identical issues (just different NuGet packages) but as I saw, no concrete solution anywhere. I will try to summarize briefly here.
I am using Xamarin for Android (Not Xamarin Forms). This project references my .NET standard 2.0 (.NET Core) project that contains all core logic. I Installed Automapper via NuGet in my core project and suddenly I have build warning that describes the conflict. Conflict is that Xamarin for Android (Mono) uses Microsoft.Csharp.dll version 2.0.5.0 and Auto mapper which is in referenced Core project uses Microsoft.Csharp.dll 4.0.0.0
Here is the output from build process related to mentioned:
There was a conflict between "Microsoft.CSharp, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". (TaskId:131)
2> "Microsoft.CSharp, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not. (TaskId:131)
2> References which depend on "Microsoft.CSharp, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Microsoft.CSharp.dll]. (TaskId:131)
2> C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Microsoft.CSharp.dll (TaskId:131)
2> Project file item includes which caused reference "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Microsoft.CSharp.dll". (TaskId:131)
2> Microsoft.CSharp (TaskId:131)
2> References which depend on "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" []. (TaskId:131)
2> C:\Users\missa\.nuget\packages\automapper\7.0.1\lib\netstandard2.0\AutoMapper.dll (TaskId:131)
2> Project file item includes which caused reference "C:\Users\missa\.nuget\packages\automapper\7.0.1\lib\netstandard2.0\AutoMapper.dll". (TaskId:131) C:\Users\missa\.nuget\packages\automapper\7.0.1\lib\netstandard2.0\AutoMapper.dll (TaskId:131)
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2110,5): warning MSB3277: Found conflicts between different versions of "Microsoft.CSharp" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.
So, build process has chosen an older version from Xamarin (this is confirmed because I extracted APK to see which dll is physically inside and found 2.0.5.0)
Now, the summary of the questions is:
If I leave the warning and accept current situation, I will have Microsoft.Csharp.dll 2.0.5.0 I suppose Android project is OK with this since it originally references this version, but how will AutoMapper behave since it is built with 4.0.0.0 reference? If it uses some new features, and the old version doesn't have them, it is not good.
Can I somehow force Xamarin to use Microsoft.Csharp.dll 4.0.0.0 since I don't see this reference directly (Mono reference is using it)? I can't use the binding redirect from app.config since Xamarin for Android doesn't support app.config. Even if there is a way somehow, is it smart solution since maybe Microsoft.Csharp 4.0.0.0 is not backward compatible with 2.0.5.0
If 1 or 2 are not good solutions, is it possible somehow (codebase path or something else) to make the situation to have both versions and that every component references its original?
This issue with AutoMapper is just an example, but basically, this case can happen with any other package. I saw that it was actually with NewtonJson and is solved in the new version of NewtonJson package where reference to Miscrosoft.Cshap.dll is removed.
I'm converting my project from MVC 4 to MVC 5 (and .Net 4 to .Net 4.5.2, which is the real driver of the changes.)
When I run one of my pages I get this error (blank space added by me for easier reading)
[A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast
to [B]System.Web.WebPages.Razor.Configuration.HostSection.
Type A originates from 'System.Web.WebPages.Razor, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context
'Default' at location
'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'.
Type B originates from 'System.Web.WebPages.Razor, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context
'Default' at location
'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET
Files\studentportal3g\2204bad2\aece9b3b\assembly\dl3\ad80387c\91adbf51_fc73d101\System.Web.WebPages.Razor.dll'.
When I first saw this is though, Ah easy! Not so much :)
I've gone over every project and made sure it's version is upgraded to MVC 5 which has the 3.0.0.0 version of System.Web.WebPages.Razor.dll.
Clean rebuild, still get the error. No problem , I'll delete the cached temp files.
Clean rebuild, still get the problem. I go back, manually check each version of System.Web.WebPages.Razor.dll, in the references of each project that has a reference to it. I check my folder where I copy dlls to make references to them manually, it's not there.
If my solution doesn't' contain a copy of the DLL or a reference to the DLL, and I've manually deleted the cache folders in 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET
Files\studentportal3g...
Where is the old bad dll coming from? How do I fix this error? How do I prevent it happening again?
Thanks,
Eric-
Visual Studio is a great tool, but it doesn't always make the right choices when it comes to upgrading dependencies, nor does it support every possible option available in MSBuild. Whenever you find yourself in a bind such as this you should manually review and (if necessary) edit your .csproj file in order to resolve it.
The problem isn't that your file exists in the GAC or that it has not been installed by NuGet, the issue is most likely that one of your project files still has a reference to the old version of System.Web.WebPages.Razor version 1.0.0.0, and you need to find all references to it and change them to 3.0.0.0 accordingly.
Right-click on your project node in Solution Explorer and click Unload Project.
Right-click the project node again and click Edit <projectName>.csproj.
Search the file for references to System.Web.WebPages.Razor and update the version and the HintPath accordingly (as shown below). Make sure the HintPath you use actually points to an existing file.
Repeat these steps for all dependent projects in the solution (and any that are in DLLs that are not part of the solution).
Old Reference
<Reference Include="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.WebPages.1.0.20105.408\lib\net40\System.Web.WebPages.Razor.dll</HintPath>
</Reference>
Updated Reference
<Reference Include="System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.0.0\lib\net45\System.Web.WebPages.Razor.dll</HintPath>
</Reference>
You should also go through the web.config and /Views/web.config files to ensure that they are not referencing any old versions of this assembly.
NOTE: If the above instructions don't solve your issue, the issue likely is outside of your solution. Most likely there is a 3rd party library that is referencing the old version of the file somewhere. If so, you could attempt to get an updated version of the DLL.
You may also want to check out this question.
It looks like the old DLL is in the Global Assembly Cache (GAC). The GAC is a place where you can store assemblies that can be referenced from several applications on the machine. Click here to read more about GAC.
Use the tool gacutil to update the assembly in the GAC.
The tool is located somewhere under "Microsoft SDKs" folder in Program Files. For me, it was located in
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\
Open cmd and navigate to the place where gacutil i stored. Then use it like this:
gacutil.exe -i [path to your assebly] -f.
The -i parameter is for indicating where your assembly is located. The -f parameter is used to force an update of the assembly, if it was already there.
Example
Say your DLL is located in
C:\temp\System.Web.WebPages.Razor.dll
Then you would run gacutil.exe -i "C:\temp\System.Web.WebPages.Razor.dll" -f
Getting following build error.
Error 15 Unknown build error, 'Could not load file or assembly
'log4net, Version=1.2.11.0, Culture=neutral,
PublicKeyToken=669e0ddf0bb1aa2a' or one of its dependencies. The
located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)'
I dont quite get whats going on.
I tried using GUI for references, it didn't help. Spent 1.5 hours on this already and issue is still present.
I go directly to project file now and the only reference to log4net there is the following:
<Reference Include="log4net, Version=1.2.12.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\ExternalDlls\.NET 4.0\log4net.dll</HintPath>
</Reference>
I still get this error. Why does it even mention V1.2.11?
Thanks in advance
Okay got build working finally.
I went through all other projects and did Resharper - Remove unused references action.
After it was done, project started to build.
Can you check what version actually exists in the Path ....\ExternalDlls.NET 4.0\log4net.dll mentioned and see what version is present in GAC.
Remove the version in GAC, remove the below reference the from project file and add it again from the ExternalDlls folder
<Reference Include="log4net, Version=1.2.12.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\ExternalDlls\.NET 4.0\log4net.dll</HintPath>
</Reference>
If you are creating a nuget package that is referencing log4net make sure your nuspec file is specifying the correct version of log4net (this is the problem I ran into after log4net released the new build). And make sure that if you don't want the latest version of log4net you encapsulate your version with "[" and "]" so that it doesn't get the latest. See this.. http://docs.nuget.org/docs/reference/versioning#Specifying_Version_Ranges_in_.nuspec_Files
Hope this helps someone.
I am facing this issue today. To solve this problem I deleted log4net.dll file reference from Bin Folder through visual studio. and rebuild the website.
It automatically picks up log4net dll. This solved problem. Reason for this issue was Reference bind through visual studio may not be upto date with the actual file version.