RadWebCam doesn't function on .NET Core app

1 Answer 157 Views
WebCam
DA
Top achievements
Rank 1
DA asked on 10 Sep 2021, 03:20 PM | edited on 10 Sep 2021, 04:43 PM

No video is shown when the camera starts and calling the TakeSnapshot method results in an exception in PresentationCore.CriticalFromVisual, with the message "parameter v cannot be null'.  

I've provided a simple test app that reproduces the problem. Platform is Windows 10, and the app is a .NET 5.0 WPF app using the latest Telerik UI for WPF nuget package. I have tried AnyCPU, x64 and x86 and the behavior is the same for all configurations, both release and debug. 

I have tested on a desktop machine with a Logitech 910 webcam and on a Surface Pro 3 using the internal camera. The identical code works fine on WPF .NET Framework 4.7.2 on both devices.

Project file is attached. 

Here is the window xaml:

 

<Window x:Class="cameratest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:cameratest"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        mc:Ignorable="d"
        Title="MainWindow"
        Height="450"
        Width="800">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Button Width="80"
                Margin="4"
                HorizontalAlignment="Left"
                Click="OnSnapClick">Snap</Button>
        <telerik:RadWebCam Grid.Row="1"
                           x:Name="radWebCam" />
    </Grid>
</Window>


And the code behind:


using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Media.Imaging;
using Telerik.Windows.Controls;
using Telerik.Windows.MediaFoundation;

namespace cameratest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            radWebCam.SnapshotTaken += RadWebCamOnSnapshotTaken;
            radWebCam.CameraError += RadWebCamOnCameraError;
        }

        private void RadWebCamOnCameraError(object sender, CameraErrorEventArgs e)
        {
            Debug.WriteLine(e.Error.Message);
        }

        private void RadWebCamOnSnapshotTaken(object sender, SnapshotTakenEventArgs e)
        {
            BitmapSource snapshot = e.Snapshot;
        }

        private void OnSnapClick(object sender, RoutedEventArgs e)
        {
            radWebCam.TakeSnapshot();
        }
    }
}

 

Modifying the app to disable auto start and initialize and state the camera manually results in the same problem.

 

 

1 Answer, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 13 Sep 2021, 07:00 PM

Hello David Anderson,

The missing video is not shown because of the added package(Telerik.UI.for.WPF.NetCore), which contains NoXaml dlls. These assemblies contain no XAML code, so the element is not displayedbecause there aren't any templates to visualize the control. The exception thrown in the TakeSnapshot method occurs because it relies on an element in the template which cannot be loaded since the template is missing.

That said, if you want to use the NoXaml assemblies, an additional NuGet package needs to be added for the theme. And then it needs to be merged in the App.xaml file.

If the aforementioned approach is not preferred, what I could suggest is to add the Telerik.UI.for.WPF.NetCore.Xaml package instead, which has a default theme set(Office Black). You could also change the theme freely via the StyleManager.

That said, could you try these approaches and see which one is preferred?

Regards,
Stenly
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

DA
Top achievements
Rank 1
commented on 14 Sep 2021, 02:59 PM

Thanks for the quick turnaround, I somehow missed the documentation on NoXaml packages. Adding those packages did indeed fix the problem, thank you!
Tags
WebCam
Asked by
DA
Top achievements
Rank 1
Answers by
Stenly
Telerik team
Share this question
or