UWP project in Visual Basic utilizing Dispatcher build correctly but not in .NET Framework 4.8.1

73 views Asked by At

I’m running Visual Studio (2022 (64-bit) – Version 17.6.3) and I have a correctly built UWP project in Visual Basic utilizing a dispatcher for handling Events, as shown in the code below. The UWP program executes perfectly.

I then converted the same code to the latest .NET Framework 4.8.1 and found that everything seems to map correctly in the new build except for the dispatcher code.

The UWP build is based on the following references:

C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\XamlCompiler\Microsoft.UI.Xaml.Markup.winmd

The beginning of UWP code looks like this:

Imports Windows.Devices.Enumeration
Imports Windows.Devices.Bluetooth.GenericAttributeProfile
Imports System.Text
Imports Windows.Storage.Streams
Imports System.Threading

Public NotInheritable Class MainPage
    Dim BleDevices As New ObservableCollection(Of DeviceInformation)()
    Dim BleServices As New ObservableCollection(Of GattDeviceService)()
    Dim BleCharacteristic As New ObservableCollection(Of GattCharacteristic)()

    WithEvents GetBleDev As New GetBleDevice(Dispatcher)

With the cursor hovering over the last declaration text “New GetBleDevice(..” this reference text is shown: enter image description here

and hovering over “(Dispatcher)” shows: enter image description here

Here CoreDispatcher points to: Assembly Windows.Foundation.UniversalApiContract, Version=14.0.0.0, Cul-ture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime

namespace Windows.UI.Core

The code for the GetBleDevice Class looks like this:

Imports Windows.Devices.Bluetooth
Imports Windows.Devices.Enumeration
Imports Windows.UI.Core

Public Class GetBleDevice
    Private ReadOnly KnownDevices As New ObservableCollection(Of DeviceInfor-mation)()
    Private deviceWatcher As DeviceWatcher

    Public Event GetBleDevices(DevicesBle As ObservableCollection(Of DeviceInfor-mation))

    Private ReadOnly dispatcher As CoreDispatcher

    Public Sub New(iDispatcher As CoreDispatcher)
        dispatcher = iDispatcher
    End Sub

Up till here the UWP code build and executes correctly.

I converted the same code to the latest .NET Framework 4.8.1 (because 4.8 result in a bunch of errors) and found that everything seems to map correctly in the new build except for the dispatcher code. References are made to:

enter image description here

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.8.1\WindowsBase.dll C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.22621.0\Windows.winmd C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Runtime.WindowsRuntime\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.WindowsRuntime.dll where the two last items should map to the latest 4.8.1 version “Windows SDK (10.0.22621) for Windows 11, Version 22H2”, according to the download.

The beginning of the .NET Framework 4.8.1 code looks like this:

'Imports System.Collections.ObjectModel
'Imports System.Windows.Forms.VisualStyles.VisualStyleElement
Imports Windows.Devices.Enumeration
Imports Windows.Devices.Bluetooth.GenericAttributeProfile
Imports System.ServiceModel
'Imports Windows.Storage.Streams
'Imports System.Threading

Public Class Form1
    Dim BleDevices As New ObservableCollection(Of DeviceInformation)()
    Dim BleServices As New ObservableCollection(Of GattDeviceService)()
    Dim BleCharacteristic As New ObservableCollection(Of GattCharacteristic)()

    WithEvents GetBleDev As New GetBleDevice(Dispatcher)

Hovering over the last declaration line “New GetBleDevice(..” shows this reference text: enter image description here i.e. not Windows.UI.Core.CoreDispatcher as in UWP Now, hovering over “(Dispatcher)” yields: enter image description here

In this case CoreDispatcher points to: Assembly Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime namespace Windows.UI.Core which is different from the reference in the UWP-program above.

No correct build is done due to lack of the “Dispatcher” declaration. I tried to make a reference to “Win-dows.Foundation.UniversalApiContract” in the .NET Framework reference setup and excluded “Sys-tem.Runtime.WindowsRuntime.dll” and/or “Windows.winmd” in different combinations but, that yields a copious amount of new errors.

Does anyone know how to work around this problem and provide a solution hint? Is it a flaw in “System.Runtime.WindowsRuntime.dll”, “Windows.winmd” or any other reference object?

0

There are 0 answers