Loading

UWP(一)开发入门

异常问题总结

  1. Your project file doesn't list 'win10' as a "RuntimeIdentifier". You should add 'win10' to the "RuntimeIdentifiers" property in your project file and then re-run NuGet restore

    尝试一:Add this: <RuntimeIdentifier>win</RuntimeIdentifier> to your project file, for example after element TargetFrameworkVersion. Make sure the element name is singular. RuntimeIdentifiers on the other hand is used in the new csproj format

    尝试二:通过VS Installer重新安装UWP。

  2. 通过UWP调用Win32,在.Net Framework中报错:“必须添加对程序集"Windows.Foundation.FoundationContract, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime"”的引用。并且,无法找到此程序集,且Reshaper工具也无法添加。另外,微软Samples中可用的源代码,引用中的Windows有黄色感叹号。

    尝试一:It seems there are some issue with your 16299 and 15063 SDK file, you can try to open the file explorer and go to the corresponding file location to see whether the SDK is existed.

    The path should be: C:\Program Files (x86)\Windows Kits\10\References\10.0.15063.0(10.0.16299.0)\Windows.Foundation.FoundationContract\3.0.0.0\

    Otherwise, you can try to download and install the SDK version again from the Windows SDK and emulator archive.

    If this still can not work, please also try to update the Microsoft.NETCore.UniversalWindowsPlatform Nuget to the latest version then restart your VS, clean and rebuild your app again. By the way, please also provide your device OS version and OS build to help me look into this issue.

    ---Update---

    Another workaround is that you can declare the contents of the ResourceDictionary after the <ResourceDictionary.ThemeDictionaries></ResourceDictionary.ThemeDictionaries> tag pair. This will prevent the crash from triggering.

    尝试二:打开报错的csproj文件,找到Windows引用项,如下:

    <Reference Include="Windows">
    <HintPath>D:\Windows Kits\10\UnionMetadata\10.0.16299.0\Windows.winmd</HintPath>
    </Reference>
    

    黄色感叹号,一般是找不到指定文件,右键属性看到路径(Path)为空也证明了这一点。因此,使用Everything搜索windows.winmd文件,找到合适版本的文件,替换成此文件的路径,保存csproj文件即可。注意,这里发现,ApplicationData.Current.LocalSettings.Values不能引用Windows.Foundation.UniversalApiContract,这是错误的引用。

  3. 通过UWP调用Win32,UWP工程找不到:Windows.ApplicationModel.FullTrustProcessLauncher,且在添加引用-Universal Windows-扩展下面无法找到Windows Desktop Extensions for the UWP引用。

    解决:Missing Windows Desktop Extension SDK for UWP。For random reason your Windows SDK can be installed to wrong directory. For me it is C:\Program Files (x86)\Microsoft Platform SDK. Right path is C:\Program Files (x86)\Windows Kits\10 I just made symbol link。

    mklink /j “C:\Program Files (x86)\Windows Kits\10” “C:\Program Files (x86)\Microsoft Platform SDK”
    

    注意,此方案或可解决2.的问题。

  4. .Net Framework工程使用Windows.ApplicationModel.AppService.AppServiceConnection.OpenAsync()报错:“IAsyncOperation<AppServiceConnectionStatus>”不包含“GetAwaiter”的定义,并且找不到可接受类型为“IAsyncOperation<AppServiceConnectionStatus>”的第一个参数的扩展方法“GetAwaiter”(是否缺少针对“System”的 using 指令?)。

    解决:查看微软Samples中可用的源代码,发现相比缺少了System.Runtime.WindowsRuntime。打开项目文件,添加如下代码即可解决。

    <Reference Include="System.Runtime.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
       <HintPath>$(SystemDrive)\Windows\Microsoft.NET\Framework\v4.0.30319\System.Runtime.WindowsRuntime.dll</HintPath>
    </Reference>
    
  5. 调用StorageFile.GetFileFromPathAsync(filePath)报错:System.UnauthorizedAccessException:“拒绝访问。 (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))”。

    解决:编辑Package.appxmanifest,在<Capabilities>中添加 <rescap:Capability Name="broadFileSystemAccess" />

  6. 未完待续...

posted @ 2021-02-01 17:15  NLNet  阅读(506)  评论(0编辑  收藏  举报