Skip to content

Instantly share code, notes, and snippets.

@mrange
Last active April 21, 2022 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrange/78c1a10cf787ab4a01cea04ac01fe534 to your computer and use it in GitHub Desktop.
Save mrange/78c1a10cf787ab4a01cea04ac01fe534 to your computer and use it in GitHub Desktop.
VB + ImageSharp => :(

VB.NET + ImageSharp => :(

When trying out VB + ImageSharp I run into strange compiler errors.

1_ImageSharp.cs works fine in C# but the same program in VB 2_ImageSharp.vb produces the errors:

2>C:\code\2_ImageSharp.vb(7,34): error BC32044: Type argument 'Rgba32' does not inherit from or implement the constraint type '?'.
2>C:\code\2_ImageSharp.vb(7,34): error BC30649: '' is an unsupported type.

The error message is confusing and I don't know how to fix it. I can work around it by creating a C# project that creates the image and call it from VB

using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
namespace NoProblems
{
public static class Adapter
{
public static Image<Rgba32> CreateImage(int dimx, int dimy)
{
// This works wine
return new Image<Rgba32>(dimx, dimy);
}
}
}
Imports SixLabors.ImageSharp
Imports SixLabors.ImageSharp.PixelFormats
Module Problems
Public Sub CreateImage(dimx As Integer, dimy As Integer)
' This Doesn't compile
Using img = New Image(Of Rgba32)(dimx, dimy)
End Using
End Sub
End Module
@playdeezgames
Copy link

Problem comes in here:

public sealed class Image<TPixel> : Image where TPixel : unmanaged, IPixel<TPixel>

Specifically, the unmanaged constraint.
VB don't DO no unmanaged stuff.
VB is above all that.
C# is a dirty dirty person.
C# should be ashamed of themselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment