Hi, I’m working on creating a series of screens as a UI for users to navigate using the SCM20260D processor with TinyCLR in Visual Studio 2022. All referenced NuGet packages are on version 2.2.0.4200. I worked towards this goal by modifying the screen behavior in the SCM20260D Dev board demo code located here: GitHub - ghi-electronics/TinyCLR-Samples: Sample projects and demos for TinyCLR OS.
My modifications include replacing icons as the primary method of moving between screens with buttons, however, occasionally when pressing a button I get the following exception:
#### Exception System.NotSupportedException - CLR_E_NOT_SUPPORTED (1) ####
#### Message:
#### System.Drawing.Internal.Bitmap::Flush [IP: 0000] ####
#### System.Drawing.Graphics::Flush [IP: 001c] ####
#### GHIElectronics.TinyCLR.UI.Bitmap::Flush [IP: 000c] ####
#### GHIElectronics.TinyCLR.UI.Media.MediaContext::RenderMessageHandler [IP: 010a] ####
#### GHIElectronics.TinyCLR.UI.Threading.Dispatcher::PushFrameImpl [IP: 0054] ####
#### GHIElectronics.TinyCLR.UI.Threading.Dispatcher::PushFrame [IP: 0018] ####
#### GHIElectronics.TinyCLR.UI.Threading.Dispatcher::Run [IP: 0006] ####
#### GHIElectronics.TinyCLR.UI.Application::Run [IP: 0066] ####
#### MR_200.Program::Main [IP: 0147] ####
Exception thrown: 'System.NotSupportedException' in GHIElectronics.TinyCLR.Drawing.dll
[Default DispatcherException Handler] Exception caught: System.NotSupportedException
However, nowhere in my code do I call the flush function from System.Drawing.Internal.Bitmap, and in fact I am not using a bitmap at all since I removed icons altogether for this project, so I was hoping I could get further insight into what’s going on. Here is an example button press that is causing the error reliably:
private Button lightButton;
public MainMenuWindow(string text, int width, int height) : base(text, width, height)
{
...
this.lightButton = new Button()
{
Child = new GHIElectronics.TinyCLR.UI.Controls.Text(Resources.GetFont(Resources.FontResources.droid_reg24), "Light")
{
ForeColor = Colors.Black,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
},
Width = 400,
Height = 50,
};
this.lightButton.Click += this.LightButtonClick;
}
//turn flashlight on or off when light button is pressed
private void LightButtonClick(object sender, RoutedEventArgs e)
{
if (e.RoutedEvent.Name.CompareTo("TouchUpEvent") == 0 && MainWindow.touchDebounce == 0)
{
MainWindow.touchDebounce = 200;
MainWindow.buzzer.Start();
Thread.Sleep(10);
MainWindow.buzzer.Stop();
if (MainWindow.FlashLight1.Read() == GpioPinValue.Low)
{
MainWindow.FlashLight1.Write(GpioPinValue.High);
MainWindow.FlashLight2.Write(GpioPinValue.High);
}
else
{
MainWindow.FlashLight1.Write(GpioPinValue.Low);
MainWindow.FlashLight2.Write(GpioPinValue.Low);
}
}
}
All buttons are added correctly, Flashlight1 and Flashlight2 are defined as follows in the main window:
//flashlights
FlashLight1 = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PI9);
FlashLight1.SetDriveMode(GpioPinDriveMode.Output);
FlashLight1.Write(GpioPinValue.Low);
FlashLight2 = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PJ7);
FlashLight2.SetDriveMode(GpioPinDriveMode.Output);
FlashLight2.Write(GpioPinValue.Low);
The click button should simply toggle the lines hooked up to flashlight LED’s from high to low and vice versa when pressed, which it does, but it always outputs this error as well. The oddest part is that in the click button code, if I put the following, it does not triggered the exception:
private void LightButtonClick(object sender, RoutedEventArgs e)
{
if (e.RoutedEvent.Name.CompareTo("TouchUpEvent") == 0 && MainWindow.touchDebounce == 0)
{
MainWindow.touchDebounce = 200;
MainWindow.buzzer.Start();
Thread.Sleep(10);
MainWindow.buzzer.Stop();
if (MainWindow.FlashLight1.Read() == GpioPinValue.Low)
{
MainWindow.FlashLight1.Write(GpioPinValue.High);
MainWindow.FlashLight2.Write(GpioPinValue.High);
}
else
{
MainWindow.FlashLight1.Write(GpioPinValue.Low);
MainWindow.FlashLight2.Write(GpioPinValue.Low);
}
Thread.Sleep(1000);
}
}
I have been trying to figure out how to fix this issue for a few days now and would greatly appreciate knowing if it is an internal library issue or if there is any guidance that anyone has in how to deal with it, as a not supported exception referencing a function that I am not calling is a bit confusing, especially for a function that is simply changing a Gpio Pinout value. Thank you for your time.
EDIT: I do want to note that I also occasionally see this error when hitting a button to go back to the last screen I was on, for example when exiting a menu.
EDIT 2: did more testing and even if I comment out the entire function within the click button aside from the if statement for event routing and touch screen debounce timing, I still get the exception output.