Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compliation Error While referencing iTextSharp Dll in mono for android

I get the following error while referencing the iTextSharp dll

C:\Program Files\MSBuild\Novell\Novell.MonoDroid.Common.targets(2,2): Error: Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile?

File name: 'System.Drawing.dll'

at Monodroid.Tuner.MonoDroidResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)

at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(List`1 assemblies, AssemblyDefinition assembly)

at Xamarin.Android.Tasks.ResolveAssemblies.Execute() (Dashmate)

Also I tried to add System.Drawing.dll , but it still did not resolve the error.

Guess the System.Drawing within the Mono.Android.dll is conflicting with the System.Drawing.dll which is being referenced by the iTextSharp

like image 695
Surya2089 Avatar asked Aug 11 '12 05:08

Surya2089


2 Answers

I got this reply from the Development team of Xamarin

You cannot use System.Drawing.dll which is available only in full .NET profile. Mono for Android supports only its mobile-based profile which is almost the same as Silverlight

So, I guess that we could not use Third Party dll's which has the "System.Drawing" Class :(

like image 116
Surya2089 Avatar answered Nov 18 '22 09:11

Surya2089


The error is telling you that the (managed) linker is not able to load an assembly. This assembly is needed to satisfy some references required by the code you're linking. Without it the linker is not able to rewrite a smaller valid (i.e. working) assembly.

In this case it looks like iTextSharp compiled against desktop framework assemblies (i.e. the 2.0.0.0 version is the hint, Mono for Android versions would be 2.1.x).

In general the solution to such problems is to recompile the project (iTextSharp in this case) against the assemblies that Mono for Android provides. That way all references will be against M4A assemblies and the linker will be able to process them (since nothing will be missing from them, otherwise it would fail at compile time).

Note that it might not be possible to re-compile, from source, iTextSharp if it depends on too many things from System.Drawing.dll.

Also I tried to add System.Drawing.dll , but it still did not resolve the error.

Using desktop assemblies is unlikely to work (as they depend on different assemblies, with different types...).

Furthermore the System.Drawing.dll shipped with Windows (or Mono) would not work with Mono for Android since they depend on GDI+ (or libgdiplus for Mono) which is not part of Android.

Guess the System.Drawing within the Mono.Android.dll is conflicting with the System.Drawing.dll which is being referenced by the iTextSharp

There is no assembly conflict since Mono for Android does not ship with a System.Drawing.dll assembly. However some types (e.g. Rectangle[F], Point[F] and Size[F]) are included (in another assembly) that uses the System.Drawing.* namespaces since they are helpful (and well known) to .NET developers.

like image 2
poupou Avatar answered Nov 18 '22 07:11

poupou