可移植类库-引用"MarshalByRefObject"类型声称它在"mscorlib"中定义,但找不到 [英] Portable class library - Reference to type 'MarshalByRefObject' claims it is defined in 'mscorlib', but it could not be found

查看:325
本文介绍了可移植类库-引用"MarshalByRefObject"类型声称它在"mscorlib"中定义,但找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个普通的类库,具有将字节数组转换为图像的函数.

I have a normal Class Library with a function that converts a Byte Array to an Image.

现在,我已经删除了该类库,并创建了一个具有相同名称的可移植类库,现在该代码似乎不再起作用,并且在"FromStream"功能上给我一个错误:

Now I've deleted that Class Library and created a Portable Class Library with the same name and now the code does not seem to work anymore and gives me an error on the "FromStream"-function:

关于类型'MarshalByRefObject'的引用声称它是在'mscorlib'中定义的,但找不到它

Reference to type 'MarshalByRefObject' claims it is defined in 'mscorlib', but it could not be found

using System;
using System.Drawing;
using System.IO;

namespace App.Converters
{
    public static class Converter
    {
        public static Image ToImage(this byte[] byteArray)
        {
            try
            {
                return Image.FromStream(new MemoryStream(byteArray));
            }
            catch
            {
                throw new FormatException("Data is not an image");
            }
        }
    }
}

我的项目的目标是:

  • .NET Framework 4.5
  • ASP.NET Core 1.0
  • Windows 8
  • Windows Phone 8.1
  • Xamarin.Android
  • Xamarin.iOS
  • Xamarin.iOS(经典)

这是因为我所针对的框架之一不支持"something"吗?那为什么VS让我使用它并在自动完成中显示它?

Is this because "something" is not supported in one of the frameworks I'm targeting? Then why does VS let me use and show it in auto-complete?

推荐答案

 using System.Drawing;

这可能与您获得此错误消息的操作有关.您使用了大锤将指令识别出来.我们必须对此进行猜测,但是您可能采用的方法之一是使用项目">添加引用">浏览"按钮>从c:\ windows \ microsoft.net子目录中选择System.Drawing.dll. 似乎可以正常工作.

That's probably a bit more relevant to what you did to get this error message. You used a sledgehammer to get that using directive recognized. We have to guess at it, but one way you might have done that is with Project > Add Reference > Browse button > pick System.Drawing.dll from the c:\windows\microsoft.net subdirectory. Seems to work just fine.

大概是您在mscorlib.dll上使用了类似的大锤来识别MarshalByRefObject.尽管由于IDE可以告诉它无效,这很难完成,但mscorlib.dll已包含在参考集中.也许您是手动编辑项目文件的,很难猜到.

And presumably you used a similar kind of sledgehammer on mscorlib.dll to get MarshalByRefObject recognized. Although that's much harder to do since the IDE can tell that is not valid, mscorlib.dll is already included in the reference set. Maybe you edited the project file by hand, hard to guess.

不要使用大锤.

一个PCL项目已经引用了您可能使用的所有框架程序集.它们没有在项目的引用"节点中单独列出,而是折叠在单个".NET"节点中.

A PCL project already has a reference to all of the framework assemblies you can possibly use. They are not listed individually in the References node of your project, they are collapsed in the single ".NET" node.

这样做不会使您的生活痛苦不堪,它可以确保您不会意外使用所选目标之一上没有的班级.花了数周时间编写代码,在开发人员机器上对其进行完美测试之后,现在尝试在手机上运行,​​从而避免了在最坏的时间发现问题. Kaboom,不能工作.上一条小河,没有桨,损失了数周.

This isn't done to make your life miserable, it ensures that you cannot accidentally use a class that is not available on one of the targets you selected. Saves you from finding out at the worst possible time, after you've spent weeks writing the code, testing it to perfection on your dev machine and now try to run it on a phone. Kaboom, can't work. Up a creek, no paddle, weeks lost.

System.Drawing仅在台式机上可用.同样,MBRO仅在CLR的完整版本上可用,而.NETCore版本不可用. MBRO无法正常工作,需要远程处理,该功能是从.NETCore剪切而来的,使其成为核心".您将必须找到另一种方法来完成您想做的事情.没有指导,问题还不够详细.

System.Drawing is only available on desktop machines. And likewise, MBRO is only available on the full version of the CLR, not the .NETCore version. Can't work, MBRO requires remoting, a feature that was cut from .NETCore to make it "core". You'll have to find another way to accomplish what you want to do. No guidance, the question isn't detailed enough.

这篇关于可移植类库-引用"MarshalByRefObject"类型声称它在"mscorlib"中定义,但找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆