Windows Runtime activatable class in Windows 10

Windows Runtime activatable class in Windows 10

本文关键字:Windows in activatable Runtime class      更新时间:2023-10-16

当我尝试为WinRT注册一个可激活的类时,我得到了一个错误。这是在Visual Studio 2015中的c#通用应用程序(UAP)中,在Windows 10上。

以前,您可以在包中注册可激活的类。Appxmanifest文件如下:

<Extension Category="windows.activatableClass.inProcessServer">
    <InProcessServer>
        <Path>myCode.dll</Path>
        <ActivatableClass ActivatableClassId="myNS.MyNativeClass" ThreadingModel="both" />
    </InProcessServer>
</Extension>

但是Visual Studio不喜欢这样。它违反了UAP项目的appxmanifest文件的模式:

Validation error. error C00CE169: App manifest validation error: The app manifest must be valid as per schema: Line 42, Column 20, Reason: 'windows.activatableClass.inProcessServer' violates enumeration constraint of 'windows.backgroundTasks windows.preInstalledConfigTask windows.updateTask windows.restrictedLaunch'. The attribute 'Category' with value 'windows.activatableClass.inProcessServer' failed to parse.  TextSecure  C:Users123DocumentsGitHubVisualStudioMyProjMyProjbinx86DebugAppxManifest.xml  

那么如何从UAP项目中使用Windows Runtime组件呢?如果不注册它,就会得到typeloadeexception。

您把Extensions元素放在了Application元素还是Package元素的什么地方?如果将其放在Application元素中,则会出现此错误。你应该把in放到Package元素中。

例如:

<?xml version="1.0" encoding="utf-8"?>
<Package
  xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
  xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
  xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
  IgnorableNamespaces="uap mp">
  <Capabilities>
    <Capability Name="internetClient" />
  </Capabilities>
  <Extensions>
    <Extension Category="windows.activatableClass.inProcessServer">
      <InProcessServer>
        <Path>yourdll.dll</Path>
      </InProcessServer>
    </Extension>
  </Extensions>
</Package>