UWP IoT Core应用加载System.Runtime.WindowsRuntime程序集失败求助
Hey there, let's work through this System.IO.FileNotFoundException you're facing with your Windows IoT Core UWP app. It sounds like you've already tackled most compatibility issues targeting build 16299, so let's zero in on that missing System.Runtime.WindowsRuntime assembly.
1. Verify NuGet Package Compatibility for UWP
First, let's check those NuGet packages throwing related warnings:
- Open the NuGet Package Manager for your project, and review each flagged package. Ensure they explicitly support UWP (Windows 10.0.16299 or higher). Many .NET Framework-specific packages depend on the desktop version of
System.Runtime.WindowsRuntime, which doesn't align with UWP's runtime. - Try updating these problematic packages to their latest UWP-compatible versions. If a package doesn't support UWP, look for a UWP-native alternative that provides the same functionality.
2. Add Assembly Binding Redirect (If Needed)
UWP doesn't typically require binding redirects, but mixing .NET Framework code can sometimes break this. Here's how to fix version mismatches:
- If your project doesn't have an
App.configfile, add one by right-clicking the project → Add → New Item → Application Configuration File. - Paste this configuration, adjusting the
newVersionto match the actual version ofSystem.Runtime.WindowsRuntimein your project (check via References → Framework assemblies):<configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Runtime.WindowsRuntime" publicKeyToken="b77a5c561934e089" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.10.0" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration> - Note: The
newVersionvalue corresponds to the version included with Windows 10 Build 16299—double-check your project's references to confirm the exact number.
3. Confirm Project Target/Minimum Version Settings
Make sure your project is properly aligned with the IoT Core version you're targeting:
- Right-click your UWP project → Properties → Application tab.
- Set both Target version and Minimum version to Windows 10 Fall Creators Update (10.0; Build 16299) (or a higher compatible version). This ensures the runtime pulls the correct assemblies for your environment.
4. Clean, Rebuild, and Clear NuGet Cache
Corrupted build artifacts or cached packages often cause assembly loading issues:
- Go to Build → Clean Solution to remove existing build files.
- Delete the
binandobjfolders in your project directory manually—this ensures no leftover incompatible files remain. - Clear your NuGet cache: Open Tools → NuGet Package Manager → Package Manager Settings → General → Clear All NuGet Cache(s).
- Finally, rebuild your solution and test again.
5. Audit the .NET Framework Code for UWP Incompatibilities
Take a close look at the .NET Framework code you've integrated:
- Check for APIs exclusive to desktop .NET (e.g., certain
System.IOsynchronous methods, WPF-specific types). Replace these with UWP-native equivalents—for example, useWindows.StorageAPIs instead of desktopSystem.IOfor file operations, or switch to async UWP methods where possible. - Remove any unnecessary references to desktop-only assemblies that might be pulling in the wrong version of
System.Runtime.WindowsRuntime.
内容的提问来源于stack exchange,提问作者Jacob

