I’m a little inexperienced with the C# language and especially with Visual Studio.
I’m developing an application in Visual Studio for screen capture using Microsoft.Windows.SDK.Contracts and SharpDX.Direct3D11 both installed through NuGets Packages, to actually use libraries such as Windows.Graphics.Capture; Windows.Graphics.DirectX.Direct3D11.
My project specifications:
Visual Studio version: 17.11.4
Windows 10 SDK: 10.0.19041.0
Microsoft.Windows.SDK.Contracts version: 10.0.26100.1742
However, I’m facing the following problem:
`CS1704 An assembly with the same simple name Windows.UI.Xaml.Core.Direct.XamlDirectContract' has already been imported. Try removing one of the references (e.g. 'C:UsersBRUNO.nugetpackagesmicrosoft.windows.sdk.contracts10.0.26100.1742refnetstandard2.0Windows.UI.Xaml.Core.Direct.XamlDirectContract.winmd') or sign them to enable side-by-side.`
This is just an example because the same situation occurs with other references related to Microsoft.Windows.SDK.Contracts, specifically with these elements, all from the same directory:
`Windows.UI.Xaml.Core.Direct.XamlDirectContract.winmd`
`Windows.Storage.Provider.CloudFilesContract.winmd`
`Windows.Security.Isolation.Isolatedwindowsenvironmentcontract.winmd`
`Windows.Networking.Connectivity.WwanContract.winmd`
`Windows.Foundation.UniversalApiContract.winmd`
`Windows.ApplicationModel.Calls.CallsVoipContract.winmd`
`Windows.ApplicationModel.Calls.CallsPhoneContract.winmd`
`Windows.ApplicationModel.Calls.Background.CallsBackgroundContract.winmd`
`Windows.AI.MachineLearning.MachineLearningContract.winmd`
I have done extensive internal and AI research to actually find a solution to this problem, but so far without success.
I tried to look for duplicate references in operating system directories, within the Visual Studio solution, and found no evidence;
I deleted the respective references in the directory specified in the error, but when removing it, other errors occur, because in fact the project depends on these references;
I tried to sign the assembly;
I downloaded the project, and checked the generated XML file to see if there were any duplicate files, and found no evidence;
I uninstalled Visual Studio;
I manually downloaded the Windows 10 SDK;
I created other projects without actually 1 line of code, to check if it could be something related to the script, and I added Microsoft.Windows.SDK.Contracts via NuGet and the same errors occurred;
I created a virtual machine, only with Visual Studio installed, with the same specifications, and the problem also occurred
2
Answers
You could try the following steps:
Target Specific Windows SDK, if you are targeting windows 10,
then make sure .csproj file has this line:
Remove and Reinstall NuGet Packages as this might be an issue of mismatch due to installing packages at different times.
Avoid Mixed SDK Versions
Use a tool like Dependency Walker to analyze your dependencies and find out where the conflicting assemblies are coming from.
This guide says Causes for duplication include, please check the following steps.
1.Check if your project references multiple versions of the same assembly.
Go to your project’s references and ensure that you don’t have multiple references to the same assembly.
For example: The project had a reference to the
Windows.UI.Xaml.Core.Direct.XamlDirectContract
and a COM reference that generated the "same"Windows.UI.Xaml.Core.Direct.XamlDirectContract
.2 As the outputs says,"Try removing one of the references xxx".
Could you find the two different places your project references to
Windows.UI.Xaml.Core.Direct.XamlDirectContract
from the output information?If yes, please remove one of the references.
Besides, this issue is similar to old ticket, you can check if it helps.