Following the docs at the Getting Started page (although without newer language features), I have the following code:
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
public class Test
{
public void CreateImage()
{
using (Image<Rgba32> image = new Image<Rgba32>(100, 100))
{
// code
}
}
}
I'm seeing both cases of Rgba32
underlined with the error message:
The type 'SixLabors.ImageSharp.PixelFormats.Rgba32' must be valid unmanaged type (simple numeric, 'bool', 'char', 'void', enumeration type or non-generic struct type with all fields of unmanaged types at any level of nesting) in order to use it as a type argument for 'TPixel' parameter.
As far as I can see the above code is equivalent and complete re the example code. Does there need to be some extra configuration in relation to unmanaged types to get this to work?
(This looks maybe related to this VB issue on GitHub, but my Project is C# 7.0 / .Net Standard 2.0)
This turns out to have been a language version problem.
The Project was set to the default of "C# major latest version" in Advanced Build Settings (being 7.0 in VS2017).
Changing it to "C# 7.3" fixed the error message and allowed the build to succeed.
(Guessing that it relates to the unmanaged
constraint added in that version - it's not mentioned by name in the version history, but is in this blog post.)