Fails to Compile C# project due to primary reference - visual-studio-2010

I'm trying to compile the project with targeted framework as ".NETFramework 4.0". But I get the following warning:
The primary reference "XXX" could not be resolved because it has an
indirect dependency on the framework assembly
"System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" which could not be resolved in the
currently targeted framework. ".NETFramework,Version=v4.0". To resolve
this problem, either remove the reference "Fdi" or retarget your
application to a framework version which contains
"System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089".

I found an earlier (but similar) problem: Visual Studio 2010: Reference Assemblies Targeting Higher Framework Version
Johannes Rudolph found this answer on MSDN's forums ( http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/dfadfb34-5328-4c53-8274-931c6ae00836 ):
However, there're 2 workarounds.
Option 1:
Step1: Unload the referencing project targeting .NET 2.0
Step2: Right click the unloaded project and select edit from context menu
Step3: Add <SpecificVersion>true</SpecificVersion> to the reference.
Below is a sample from my repro solution:
<ProjectReference Include="..\HighFX\HighFX.csproj">
<Project>{8DD71CAF-BEF7-40ED-9DD0-25033CD8009D}</Project>
<Name>HighFX</Name>
<SpecificVersion>true</SpecificVersion>
</ProjectReference>
Step4: Reload the project.
Now your should be able to build within the Visual Studio 2010, there could still be a warning as below, but the build can be successful.
Warning 1 The project 'XXX' cannot be referenced. The referenced project is targeted to a higher framework version (3.5)
Option2:
Use the command line tool csc.exe to build each of your source file, which won't prevent the building.

Related

Forcing VS to use an assembly with a lower version

This is a general question but I will describe my specific scenario - My project is a .NET Core 3.0 SignalR Console application in VS19 (same with VS17)
After upgrading everything to Core 3.0 build now fails with:
Error CS1705 Assembly 'Microsoft.AspNetCore.SignalR.Client' with identity
'Microsoft.AspNetCore.SignalR.Client, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=adb9793829ddae60' uses 'Microsoft.AspNetCore.Http.Connections.Common,
Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' which has a higher version
than referenced assembly 'Microsoft.AspNetCore.Http.Connections.Common' with identity
'Microsoft.AspNetCore.Http.Connections.Common, Version=1.1.0.0, Culture=neutral,
PublicKeyToken=adb9793829ddae60'
What I understand is that despite the nuget highest version of Microsoft.AspNetCore.Http.Connections.Common being 1.0.0.0, for some reason Microsoft.AspNetCore.SignalR.Client requires 3.0.0.0 which does not exist (yet).
How can I tell VS to use Microsoft.AspNetCore.Http.Connections.Common 1.0.0.0 instead ?
I tried in my csproj to add specific version to the reference:
<PackageReference Include="Microsoft.AspNetCore.Http.Connections.Common" Version="1.1.0">
<SpecificVersion>False</SpecificVersion>
</PackageReference>
But nothing changed. I also tried with <SpecificVersion>True</SpecificVersion>, same result :(
Any help ?
Some of the .NET Core prerelease libraries aren't available on the main NuGet feed. You need to add the nightly/dev feed to your NuGet package sources and, hopefully, it should be available there.
The feeds are:
ASP.NET Core
https://dotnet.myget.org/gallery/aspnetcore-dev
.NET Core
https://dotnet.myget.org/F/dotnet-core/api/v3/index.json
To add the feed to Visual Studio
In the Manage NuGet Packages window for your project click on the cog in the top right corner.
In the new dialog click the red 'x' in the top right
Paste the URL above in the "Source" tex box
Give the feed a name (e.g. ASP.NET Core Dev)
Click Update
Ensure the feed is at the bottom of the list (so this is the last one used for packages)
Click OK
Now you can change the Package Source in the NuGet window to either your new feed or "All" and click the 'include prerelease' to see the pre-release versions of the packages.

Wrong FSharp.Core version looked for in a Xamarin.Forms project

In a Xamarin.Forms project I am getting an error on Windows 8.1 and UWP:
Could not load file or assembly 'FSharp.Core, Version=3.259.3.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.
The actual version of F# used throughout the solution is 3.7.4.0:
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile>Profile7</TargetFrameworkProfile>
<TargetProfile>netcore</TargetProfile>
<TargetFSharpCoreVersion>3.7.4.0</TargetFSharpCoreVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
There is an F# PCL project and C# platform-specific projects. The error occurs only when using F# libraries from Nuget in the PCL. These packages tend to use:
<TargetFSharpCoreVersion>3.259.3.1</TargetFSharpCoreVersion>
I have tried the following, but they do not change the error:
Putting an app.config file with a binding redirect to 3.7.4.0 in the F# project and/or the build directory
Installing the FSharp.Core Nuget package into all projects
Very grateful for any help.
Edit: in the original question there was an incompatibility between the profile (111) and the intended TargetFSharpCoreVersion (3.7.4.0) which was causing additional issues.

Spurious mscorlib of wrong version showing up in dll build

I am building a Cpp/Clr dll with .NET Framework 2.0. Builds fine. However, when I create an Example program to use the dll, also with 2.0, I get this error:
The primary reference "C:\...\MemBuffDll.dll" could not be resolved because it has an indirect dependency on the .NET Framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which has a higher version "4.0.0.0" than the version "2.0.0.0" in the current target framework.
I have very carefully rebuild the entire solution (not too hard, only two projects in it) and made sure I used only cut and paste of code from one file to another in the re-creation. I as VERY careful to make sure I specified the 2.0 Framework.
When I exclude the Example Solution, everything builds fine. When I reload it, I get the above message. So, I searched in the contents of every file in the entire solution and found the reference in both the .dll and in a file ending with .metagen. The metagen lines of interest are:
ImageRuntimeVersion: v4.0.30319
Assembly MemBuffDll, Version=0.0.*, Culture=Invariant Language (Invariant Country):
hash=SHA1, flags=PublicKey
Assembly mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:
hash=None, flags=None
Assembly mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:
hash=None, flags=None
Assembly System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:
hash=None, flags=None
Why are the two lines with 4.0.0.0 in there? This is supposed to be a 2.0 build.
Really puzzled,
-greenhorn greg
The answer to the question is:
"The C++ IDE does not support multi-targeting"
Because I didn't understand this answer when I'd seen it in other posts, I'm going to try and clarify for the benefit of other poor souls who stumble upon this "feature".
What this means is that my VS 2010 cannot (correctly) target .net 2.0 when I'm doing a C++ project. I had specified .net framework 2.0 for both of my projects in my solution and the settings were accepted. However, the C++ portion (actually C++/CLI) actually built with two references, both the v2.0 that I had specified and v4.0 that is the native(?) for my VS 2010. Note that it did not throw an error or warning and only the .dll and the .metagen files contained this reference.
When the other project in my solution tried to reference the project, I got the error mentioned in my OP. It would not build.
The solution to the problem is twofold:
Install VS 2008 and recreate the problem project under that. Will probably need refactoring. Note that the Express edition worked just fine for this.
Change your targets to .net 4.0. This is what I did because refactoring the dll would be a PITA and the target platform (Windows Embedded 8 Standard) supports .net 4.0
Hope this helps somebody else like me that runs into this.

Add Deployable Assemblies option missing from Visual Studio 2010

I've uploaded an MVC3 website and I'm getting this error:
Could not load file or assembly 'System.Web.Helpers, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its
dependencies. The system cannot find the file specified.
Having seen this before I know that it's an issue where the libraries I need aren't there. I have to bin deploy.
However I can't find the "Add Deployable Assemblies" option when I right click the project.
And according to this answer:
Starting with MVC 3 Tools Update we are now using Nuget package
references, which means that your project is automatically
bin-deployable. Since the tooling gesture is no longer necessary it
was removed from VS 11.
So why hasn't my application been "automatically bin-deployed" if this is the case?
Any suggestions?
Install Visual Studio 2010 Service Pack1 and you will get the option.
http://iwantmymvc.com/2011-03-23-bin-deploy-aspnet-mvc-3-visual-studio

Having errors running JigLibX 0.3.1 on XNA 4.0

Warning 1:
The referenced assembly "Microsoft.Xna.Framework.Content.Pipeline,
Version=4.0.0.0,Culture=neutral, PublicKeyToken=842cf8be1de50553"
could not be resolved because it has a dependency on
"Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently
targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please
remove references to assemblies not in the targeted framework or
consider retargeting your project. JigLibX
Warning 2:
The referenced assembly "Microsoft.Xna.Framework.Content.Pipeline,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553"
could not be resolved because it has a dependency on
"Microsoft.Build.Framework, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently
targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please
remove references to assemblies not in the targeted framework or
consider retargeting your project. JigLibX
Error 3:
Error loading pipeline assembly "HeightmapProcessor, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null". JigLibGame
How can I solve this?
Your assembly (you didn't give details - is it an application? a game? a library? a content pipeline extension?) is depending on the XNA content pipeline assemblies, which themselves require the full .NET 4 framework -- currently you are targeting the .NET 4 Client Profile framework.
You need to do exactly what the exception says:
You could remove the assembly references to the content pipeline assemblies, if that is possible.
Or you could change the target framework. To do this, right click your project in the Solution Explorer, select Properties, on the Application tab find the Target framework drop-down and change from ".NET Framework 4 Client Profile" to ".NET Framework 4"
It is worth pointing out that the XNA content pipeline assemblies are not redistributable: you cannot include them with your game.

Resources