Reputation: 765
I have a normal Class Library with a function that converts a Byte Array to an Image.
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:
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");
}
}
}
}
My project is targeting:
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?
Upvotes: 1
Views: 1954
Reputation: 942040
using System.Drawing;
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.
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.
Don't use sledgehammers.
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.
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 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.
Upvotes: 2