【问题标题】:Xamarin.iOS does not recognize the 'Bitmap' type from the referenced System.Drawing.CommonXamarin.iOS 无法从引用的 System.Drawing.Common 中识别“位图”类型
【发布时间】:2018-08-20 21:01:30
【问题描述】:

使用 Windows 上的 Visual Studio 15.8.1(使用 Parallels 在 Mac 上运行),我使用 Xamarin.iOS 创建了一个 iOS 应用程序,目标是 iOS 11.4。为了构建应用程序,我在运行最新 Xamarin 11.14.0.11 的 macOS 上设置了构建代理。

然后我创建了一个新的 .netstandard 2.0 库,它引用了 Microsoft 的 NuGet 包 System.Drawing.Common

在那个库中,我添加了以下类:

using System.Drawing;

namespace library
{
    public class SomeClass
    {
        private readonly Bitmap m_bitmap;

        public SomeClass(Bitmap bitmap)
        {
            m_bitmap = bitmap;
        }
    }
}

该库随后被 iOS 项目引用,一切正常。

在iOS项目的ViewController中,我添加了以下代码,使用了之前的类,并添加了对System.Drawing.Common包的引用,以便能够使用Bitmap类:

public partial class ViewController : UIViewController
{
    private SomeClass m_someClass;

    public ViewController (IntPtr handle) : base (handle)
    {
        m_someClass = new SomeClass(new System.Drawing.Bitmap());
    }

    // ...
}

现在,它无法构建,我收到以下错误:

错误 CS0234:类型或命名空间名称“位图”不存在于 命名空间“System.Drawing”(您是否缺少程序集 参考?)

错误 CS7069:对类型“位图”的引用声称它是 在'System.Drawing.Common'中定义,但找不到

问题

我关注了the answer to that question。一切都是最新的(macOS 上的 Visual Studio 和 Xamarin)。我尝试手动将 System.Drawing.Common 从包的 .netstandard20 复制到输出,并将 DLL 作为参考直接添加到项目中。我从来没有任何工作。

应该怎么做?

【问题讨论】:

  • 你能分享一个重现的解决方案吗?
  • @AlexGhiondea-MSFT 好吧,我在问题中提出的所有内容都是重现步骤。我的实际解决方案涉及更多项目,但我已经能够通过两个描述的项目重现问题:具有指定类的 .netstandard 2.0 项目,由 Xamarin.iOS 应用程序引用。它们都引用了 System.Drawing.Common NuGet 包(仅此而已......没有手动添加其他 DLL)。
  • 谢谢!我能够得到当地的复制品。看起来您正在 Mono 存储库中对此进行跟进:github.com/mono/mono/issues/10310
  • @AlexGhiondea-MSFT 是的。我最初在 SO 上提出问题后几个小时向 CoreFX 团队打开了这个错误,但被重定向到单声道团队。

标签: c# xamarin xamarin.ios .net-standard-2.0


【解决方案1】:
  1. 点击项目参考文件夹
  2. 点击添加参考
  3. 在 .NET 选项卡中,您将找到 System.Drawing
  4. 单击确定。这将添加对System.Drawing 的引用

【讨论】:

猜你喜欢
  • 2016-09-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-10
  • 1970-01-01
  • 2018-07-26
  • 1970-01-01
相关资源
最近更新 更多