在为Android Mono引用iTextSharp Dll时出现编译错误

6
在引用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)

此外,我尝试添加了 System.Drawing.dll ,但仍无法解决错误。

猜想 Mono.Android.dll 中的 System.Drawing 与 iTextSharp 引用的 System.Drawing.dll 相冲突。
2个回答

3

我从Xamarin的开发团队收到了以下回复:

您不能使用仅在完整.NET框架中提供的System.Drawing.dll。Mono for Android仅支持其基于移动设备的框架配置文件,几乎与Silverlight相同。

所以,我猜我们不能使用具有"System.Drawing"类的第三方dll :(


2
错误告诉你,(托管)链接器无法加载程序集。此程序集是需要满足代码中所链接的一些引用的。如果没有它,链接器将无法重写更小的有效(即可工作的)程序集。
在本例中,看起来iTextSharp编译成了桌面框架程序集(i.e. 2.0.0.0版本为提示,Mono for Android版本将为2.1.x)。
一般来说,这种问题的解决方案是重新编译项目(在这种情况下是iTextSharp),针对Mono for Android提供的程序集进行重新编译。这样所有的引用都将针对M4A程序集,并且链接器将能够处理它们(因为没有任何东西会从它们中丢失,否则它将在编译时失败)。
请注意,如果iTextSharp依赖于System.Drawing.dll的内容过多,则可能无法从源代码重新编译。
还试图添加System.Drawing.dll,但仍然无法解决错误。
使用桌面程序集不太可能奏效(因为它们依赖于不同的程序集,具有不同的类型...)。
此外,随Windows(或Mono)提供的System.Drawing.dll与Mono for Android不兼容,因为它们依赖于GDI+(或Mono的libgdiplus),而这不是Android的一部分。
猜测Mono.Android.dll中的System.Drawing会与被iTextSharp引用的System.Drawing.dll产生冲突。
没有程序集冲突,因为Mono for Android不提供System.Drawing.dll程序集。但是,某些类型(如Rectangle[F]、Point[F]和Size[F])包括在另一个程序集中,该程序集使用了System.Drawing.*命名空间,因为它们对.NET开发人员很有帮助(并且广泛使用)。

1
嗨,我尝试使用不同的库,这些库只引用了 System.Drawing.dll,包括我自己的自定义库,但是问题仍然存在。 此外,我尝试在应用程序中使用 System.Drawing.dll,它显示 匿名类颜色 作为类颜色在 System.Drawing.dll 和 Mono.Android.dll 的 System.Drawing 命名空间中都被声明, 因此,在引用其他 dll 时可能会出现问题,当我尝试使用没有 Drawing.dll 的 dll 时,它可以正常工作 :( - Surya2089

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接