ICloneable Exists in Two Assemblies - c#

Our dot net core 2.0 project has some classes that implement ICloneable (they have a .Clone() method that returns an object). Now, we are using a package Microsoft.Azure.Amqp and when building the project now gives an error:
Error CS0433 The type 'ICloneable' exists in both 'Microsoft.Azure.Amqp, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' and 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
Both have ICloneable in the "System" namespace, so how can the compiler know which one to use? Is there a way to say which DLL to use for that reference?

The question here has a solution to this problem. I'll summarise it briefly. Go to the reference in your project, and change "Aliases" to a value of your choosing. To use code from this assembly now, you will need to use the extern keyword like so at the top of your file: extern alias aliasname. Then you can reference code from this assembly like so: aliasname::System.ICloneable.

Related

The type 'JsonConvert' exists in both 'Newtonsoft.Json

I'm working on a project where I need Microsoft azure SDKs and Autodesk NuGet package as well, the issue is that when I install Autodesk forge Nuget I receive an error regarding with 'The type 'JsonConvert' exists in both 'Newtonsoft.Json'.
When I checked the reference object browser I got there are 2 versions Newtonsoft, one of that 6.0 refers to Microsoft azure sdk.
I tried to remove older version from .csproj but did not found.
here is the object browser screen below
error I'm getting is
The type 'JsonConvert' exists in both 'Newtonsoft.Json,
Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' and
'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=30ad4fe6b2a6aeed'
any suggestion to solve it, I do tried to check dependencies of both package but one do need Newtonsoft version greater than 10 and other still refer only 6.0
Edit :
Got solution so adding here what I refered
two different DLL with same namespace
extern alias (C# Reference)
Extern alias walkthrough
This situation can be resolved by using an alias name for one (or both) of the conflicting assemblies.
A similar question has been answered here: Assembly names conflict on external dependencies.
You need to do two steps:
Give the assembly an alias name (by selecting Properties in the Object Browser)
Use the keyword extern alias <alias-name>; in your code
An example is given in the above-mentioned similar question.
This is also explained in the documentation by Microsoft: extern alias. It introduces a parallel global namespace.

ASP.NET Boilerplate - Error building new project for MVC and EF combo

I have just downloaded, today, the free startup template for MVC5 and EF.
On opening, restoring all packages then building, I get the following build error in the "Core" project:
Error CS0508 'AppSettingProvider.GetSettingDefinitions(SettingDefinitionProviderContext)': return type must be 'IEnumerable' to match overridden member 'SettingProvider.GetSettingDefinitions(SettingDefinitionProviderContext)'
Error CS0012 The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
As the error message suggested, I added the reference to the assembly, however, that produced a whole lot of other errors.
Looking at the sample projects, they are using v2.1.3 of the APB assemblies and they compile fine.
The latest downloaded sample uses v3.0.0 of the APB assemblies.
Any help to get this up and running is appreciated. Thanks in advance.
Error CS0508 'AppSettingProvider.GetSettingDefinitions(SettingDefinitionProviderContext)': return type must be 'IEnumerable' to match overridden member 'SettingProvider.GetSettingDefinitions(SettingDefinitionProviderContext)'
AppSettingProvider already does that. Make sure you didn't modify the return type in that file.
Error CS0012 The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
Update to VS2017 15.3.3+. For VS2015, install NETStandard.Library.NETFramework package.

Dual References to IXMLSerializable

I have a class that implements IXMLSerializable in a .NET Standard Library, but I can't compile the library because it's referencing IXMLSerializable in two places. The output is as follows:
error CS0433: The type 'IXmlSerializable' exists in both
'System.Xml.ReaderWriter, Version=4.1.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' and 'System.Xml.XmlSerializer,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
I only see one reference under the dependencies though (System.Xml.XmlSerializer), which I need for the XML attributes. This is my first crack at a .Net Standard Library, so is there something I'm missing here?
Try upgrading your reference to System.Xml.XmlSerializer to version 4.1.0.0.
The error message says that you have two references to the library, but are using different versions. System.Xml.ReaderWriter is using a newer version than your project is, so you need to get that version.
You could also try removing your reference to System.Xml.XmlSerializer or switching it to an older version.

Windows 10: How do you create a PhoneLine class?

I would like to programatically make a call with my windows phone 10, however I have no idea how to create a PhoneLine class can someone point me how to do it?
I am both new to C# and the mobile world.
I found the API reference here:
https://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.calls.phoneline
and what I attempted to do is:
new Windows.ApplicationModel.Calls.PhoneLine();
However what I get is:
Severity Code Description Project File Line Suppression State
Error CS1069 The type name 'PhoneLine' could not be found in the
namespace 'Windows.ApplicationModel.Calls'. This type has been forwarded to
assembly 'Windows.Foundation.UniversalApiContract, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime' Consider
adding a reference to that assembly. App2 C:\documents\visual studio
2015\Projects\Helloworld2\App2\MainPage.xaml.cs 33 Active
As the error says ,
This type has been forwarded to assembly
'Windows.Foundation.UniversalApiContract, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'
Consider adding a reference to that assembly
You need to add Windows.Foundation.UniversalApiContract dll to the project as reference
If you read the error carefully you can see that it says this:
"This type has been forwarded to
assembly 'Windows.Foundation.UniversalApiContract,
Version=3.0.0.0,
Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime' Consider
adding a reference to that assembly."
You need to add a reference to the Windows.Foundation.UniversalApiContract assembly, as the class you are looking for has been moved over there instead.
According to this blog it can be found here:
C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.UniversalApiContract\1.0.0.0\Windows.Foundation.UniversalApiContract.winmd
Remove (x86) from the path if you're on a 32-bit system.

System.Security.Cryptography.HMACSHA1 exists in two assembly with same namespace

Error CS0433 The type 'HashAlgorithm' exists in both System.Security.Cryptography.Hashing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'System.Security.Cryptography.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
I make a class library targets both dnx46 and dnxcore50. When I reference HashAlgorithm class, visual studio 2015 give me above error. What is usual way to handle this situation? Use extern alias?
Try to use a fully qualified name, like
System.Security.Cryptography.HashAlgorithm hashAlgorithm
or you can have a look at extern alias, also check these questions:
Class with same name in two assemblies (intentionally)
Type exists in 2 assemblies

Categories

Resources