Search code examples
c#.netwindowsbluetoothmaui

How to use the m2 namespace in the Package Manifest of a MAUI Windows App?


I want to use Bluetooth in my Windows MAUI app.

For this, I have to specify the device capabilities to the Package Manifest: https://learn.microsoft.com/en-us/uwp/schemas/appxpackage/how-to-specify-device-capabilities-for-bluetooth

I try this with this with the following content in my Package.appxmanifest file:

<Package
    xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
    xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
    xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
    xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
    xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest"
    IgnorableNamespaces="uap rescap">

    ...

    <Capabilities>
        <rescap:Capability Name="runFullTrust" />
        <m2:DeviceCapability Name="bluetooth" />
        <m2:DeviceCapability Name="bluetooth.rfcomm">
            <m2:Device Id="any">
                <m2:Function Type="serviceId:BA020AC9-7BDB-41CB-9B26-93A285E0066B" />
            </m2:Device>
        </m2:DeviceCapability>
    </Capabilities>

</Package>

On starting my app, I get this error message (translated by myself from German):

DEP0700: Error while registering the app. [0x80080204]
Error 0xC00CE014: Validation issue in the app manifest:
The app manifest needs to be valid, related to the schema:
Line 40, Colomn 6.
Hint:
The given scheme for MaxVersionTested does recognize XML fields with the http://schemas.microsoft.com/appx/2013/manifest-Namespace. Make sure, that MaxVersionTested is given correctly.
Reason: The content of the element '{http://schemas.microsoft.com/appx/2013/manifest}DeviceCapability' is not guilty to the parent element '{http://schemas.microsoft.com/appx/manifest/foundation/windows10}Capabilities'.
Expected: {http://schemas.microsoft.com/appx/manifest/foundation/windows10}CapabilityChoice, {http://schemas.microsoft.com/appx/manifest/foundation/windows10}CustomCapabilityChoice, {http://schemas.microsoft.com/appx/manifest/foundation/windows10}DeviceCapability.

The same manifest worked with a native Android App, but not with the MAUI app, but both are using the TargetFramework "net8.0-android34.0".


Solution

  • You don't have to use the m2 namespace. You can check the official document about DeviceCapability (package schema for Windows 8). So you can just use the following code:

    <Capabilities>
            <rescap:Capability Name="runFullTrust" />
            <DeviceCapability Name="bluetooth" />
            <DeviceCapability Name="bluetooth.rfcomm">
                <Device Id="any">
                    <Function Type="serviceId:BA020AC9-7BDB-41CB-9B26-93A285E0066B" />
                </Device>
            </DeviceCapability>
        </Capabilities>
    

    And remove the xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest".