0
votes

Problem

I am attempting to display a pdf file to the users of my Xamarin.Forms Android and iOS applications. I am trying to use the Nuget package Syncfusion.Xamarin.SfPdfViewer.

However, installing the package and recompiling results in the following error:

Error CS0433 The type 'ApplicationException' exists in both 'Syncfusion.Compression.Portable, Version=16.1451.0.37, Culture=neutral, PublicKeyToken=null' and 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'

Steps Tried

I have read and heeded the note on the Nuget package:

Note: This package needs to be installed in all Xamarin.Forms projects (PCL, Android, iOS and UWP).

I have searched the web for similar cases such as:

Specs

I am using:

  • Visual Studio 2017 version 15.7.2
  • Xamarin version 4.10.0448
  • Xamarin.Forms v3.0.0.482510
  • NETStandard.Library v2.0.3


Thank you for your help.

2
That happens, tends to be an accident caused by too many using directives. Navigate to the line of code that produces this error and fix it, spelling out the full name of the type. Like System.ApplicationException. Note that you'll always get the most useful help at SO by showing the code that produced the compile error.Hans Passant
Tried "using AppException = System.ApplicationException". However, still failed to compile with the same message above.C McCoy

2 Answers

1
votes

This issue occurs due to both the Syncfusion.Compression.Portable,dll ( included in Syncfusion.Xamarin.SfPdfViewer package) and mscorlib.dll contains the same fully-qualified type System.ApplicationException. This ambiguity issue has been fixed recently in our projects and the fix will be included in our next release, which will be rolled out in the end of July 2018.

Workaround: However we have found the workaround to resolve this issue from our side. As said in this link, we request you to extern alias for the Syncfusion.Compression.Portable assembly and make use of the required class in your application.

Steps to resolve this issue: • Add the following code snippet in your csproj file where the alias “compression” set for the Syncfusion.Compression.Portable assembly.

<Target Name="ChangeAliasesOfStrongNameAssemblies" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
    <ItemGroup>
      <ReferencePath Condition="'%(FileName)' == 'Syncfusion.Compression.Portable'">
        <Aliases>compression</Aliases>
      </ReferencePath>
    </ItemGroup>
  </Target>

• In ApplicationException used classes, add the extern alias compression; at the top of the file and make use of the desired ApplicationException in the class file.

extern alias compression;
using System;
using Xamarin.Forms;
namespace App1
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
            {
                InitializeComponent();
                try {}          

                // To use the netstandard dll ApplicationException
                catch(global::System.ApplicationException ee1) {}

                // To use the compression dll ApplicationException
                catch (compression::System.ApplicationException ee2)   {}
             }
      }
}

Below we have shared the simple sample link demonstrate the changes for your reference.

Sample Link: http://www.syncfusion.com/downloads/support/directtrac/general/ze/App1243042706.zip

I work for Syncfusion.

0
votes

Found a workaround. Since good practice is to derive meaningful exceptions from Exception, I created one and used it in place of where I was using ApplicationException. This removed the ambiguity and solution then compiled.

public class ClaimWriterException : Exception
{
    public ClaimWriterException()
    {
    }

    public ClaimWriterException(string message)
        : base(message)
    {
    }

    public ClaimWriterException(string message, Exception inner)
        : base(message, inner)
    {
    }
}