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.

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.

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…

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.