C# examples issues

I see some changes were made recently to the C# bindings, but I still can’t get the PlayGif example to run.

There are issues with some of the others, but I managed to work around them. I thought I would post here rather than making a GitHub issue, as I guess it is probably known (Or it could just be an issue my end). Here is what works and what doesn’t:

  • BoxesBoxesBoxes - works
  • FontExample - not tried
  • MatrixRain - missing System.Threading
    This seems to be due to the Console.CancelKeyPresscode -if I comment that out, it works
  • MinimalExample - works
  • PlayGIF - missing System.Collections.Concurrent
  • PulsingBrightness - missing System.Threading (as per MatrixRain)
    Otherwise works
  • Rotating3DCube - missing System.Threading (as per MatrixRain)
    inconsistent variable name - leds rather than matrix as other examples use
    Otherwise works

The only one I really care about though is PlayGif - would love to see this working.

I am mainly curious if it will play a stream (As created with the -O flag of the led-image-viewer util), or could easily be modified to do so.

I am not sure anyone maintains it tbh. It’s possible they were broken after a recent PR was merged.

See if undoing the changes in here fixes it commit/5d48ef8c1b1dd31222353e79688fed04a60007e0

Please have a look at Master Bug: C# (used to track C# PRs and issues) · Issue #1828 · hzeller/rpi-rgb-led-matrix · GitHub which talks about recent C# changes and needs.
Long story short, it needs patches from C# users, so feel free to contribute

OK, so I made some progress on this, I did make some comments on the issue, but I am wary of spamming the issue, so I will post here.

TLDR, it seems like the reason that some of the examples are giving a FileNotFoundException (eg for System.Collections.Concurrent), even though the required DLLs are in the folder is that the library is dropping privs

I was running as root.

I just tried switching to a non-root user (dietpi), but dotnet was installed as root, so dietpi could not run it.

So I tried logging in as dietpi instad, re-installing dotnet (it was installed as root), re-building the library, and trying again, and still the same issue.

However, I did set up dotnet as a “global” install - one copy in /usr/local/share/dotnetand configured things such that dietpi could access this one copy of dotnet.

I am wondering if that is maybe the issue, but at this point I have been trying to fix this for 10 hours when I could have been coding, and I am a bit demoralized.

Can anyone maybe try and see if they get the same issue with PlayGif? Curious if it’s just me.

To eliminate potential issue relating to perms, and just always in general, always run rgbmatrix programs as root with sudo

If you are really deeply stuck, just keep pasting your error messages into AI until it solves it, lol.

Root AND sudo? Hadn’t tried that.

I just did, and it does not fix the problem with the C# PlayGif example.

Has anyone else gotten the C# PlayGif example to work?

Does anyone know if it is possible via the C# bindings to set the --led-no-drop-privs option? I think this not being set is what is causing the issue.

I spent 8 hours with AI and it could not work it out.

Obviously it would be utterly clueless to the fact that privs are being dropped.

I used AI to show me how to log the privs:

UserLogger.LogUser("Before maxtrix initialization:");
using var matrix = new RGBLedMatrix(32, 2, 1);
UserLogger.LogUser("After maxtrix initialization:");

Result:

root@DietPi:~/rpi-rgb-led-matrix/bindings/c#/examples/PlayGIF/bin/Debug/net8.0/linux-arm64/publish# sudo ./PlayGIF
Before maxtrix initialization:: User=root, UID=0, EUID=0
Suggestion: to slightly improve display update, add
        isolcpus=3
at the end of /boot/cmdline.txt and reboot (see README.md)
After maxtrix initialization:: User=daemon, UID=1, EUID=1
Unhandled exception. System.TypeInitializationException: The type initializer for 'SixLabors.ImageSharp.Configuration' threw an exception.
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Collections.Concurrent, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

It’s defo dropping privs

SUCCESS!!!

I created a new copy of the library in /home/deamon, rebuilt, chowned everything in that path to daemon and the PlayGif C# sample works!!

So, it’s true, the privs are breaking it.

1 Like

Hmm, after all this, seems like I maybe am a dummy… You do seem to be able to pass --led-no-drop-privs' to PlayGif???

I swear I tried it before…

--led-no-drop-privs is a universal option. All flags prefixed with --led are. As long as the program is internally calling rgb_matrix::ParseOptionsFromFlags within the executional pathway, it should be supported by all programs including C# samples. That happens in most programs at the top of the main method when they instantiate RGBMatrix and Canvas objects.

EDIT: Actually, just from my quick search of the codebase, it is possible you discovered a bug with the C# bindings. But you’ll have to confirm that with the maintainer or by yourself. But here’s what I see:

Here in the C++, it collects the led-no-drop-privs option as expected.

Here in the C# bindings in these two files, I don’t see this flag being consumed.

So it’s quite possible the bindings for C# have become out-of-date. The last commit for the files was 2 years, ago in C#. For the C++ file, it was 3 weeks ago.

Just from my own experience, I find in terms of quality you will see it goes C++ -> Python -> C# in terms of what’s supported best.

But you may have your issue happening there, and it would require filing a bug to fix it. Preferably linked with this:

I am not quite sure what you are saying here - is this currently supported via the bindings?

And is this still not only allowing you to set this option via command-line arguments?

IMHO, there needs to be a way to control this without having to pass command-line arguments.