Xamarin跨平台UWP项目编译失败:System.Private.CoreLib加载异常求助
Xamarin UWP项目编译失败:程序集加载及Resx文件错误
错误详情
共出现20个编译错误,其中10个为程序集加载失败错误:
Severity Code Description Project File Line Suppression State Error Loading assembly "C:\Users\<username>\.nuget\packages\runtime.win10-x64.microsoft.netcore.universalwindowsplatform\6.2.14\runtimes\win10-x64\lib\uap10.0.15138\System.Threading.Thread.dll" failed. System.IO.FileNotFoundException: Could not load file or assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified. File name: 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit) at System.Attribute.GetCustomAttribute(Assembly element, Type attributeType, Boolean inherit) at System.Reflection.CustomAttributeExtensions.GetCustomAttribute[T](Assembly element) at Microsoft.Build.Tasks.ProcessResourceFiles.ReadAssemblyResources(String name, String outFileOrDir)
另外10个为Resx文件无效错误,推测与程序集加载问题相关:
Error Invalid Resx file. String reference not set to an instance of a String. Parameter name: suffix Mobile.UWP C:\Users\<username>\.nuget\packages\runtime.win10-x64.microsoft.netcore.universalwindowsplatform\6.2.14\runtimes\win10-x64\lib\uap10.0.15138\System.Private.Uri.dll
环境配置
当前使用的Visual Studio版本信息:
Microsoft Visual Studio Enterprise 2022 Version 17.5.5 VisualStudio.17.Release/17.5.5+33627.172 Microsoft .NET Framework Version 4.8.04084 Installed Version: Enterprise Visual C++ 2022 00476-80000-00000-AA235 Microsoft Visual C++ 2022 ADL Tools Service Provider 1.0 This package contains services used by Data Lake tools ASA Service Provider 1.0 ASP.NET and Web Tools 17.5.320.55692 ASP.NET and Web Tools Azure App Service Tools v3.0.0 17.5.320.55692 Azure App Service Tools v3.0.0 Azure Data Lake Tools for Visual Studio 2.6.5000.0 Microsoft Azure Data Lake Tools for Visual Studio Azure Functions and Web Jobs Tools 17.5.320.55692 Azure Functions and Web Jobs Tools Azure Stream Analytics Tools for Visual Studio 2.6.5000.0 Microsoft Azure Stream Analytics Tools for Visual Studio C# Tools 4.5.2-3.23171.7+d17f741546fad2786cbd6394d08619544e53a36d C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools. Cookiecutter 17.0.22336.2 Provides tools for finding, instantiating and customizing templates in cookiecutter format. Entity Framework Core Power Tools 2.5 Adds useful design-time EF Core DbContext features to the Visual Studio Solution Explorer context menu. Extensibility Message Bus 1.4.3 (main@2a4517a) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration. Microsoft Azure Hive Query Language Service 2.6.5000.0 Language service for Hive query Microsoft Azure Stream Analytics Language Service 2.6.5000.0 Language service for Azure Stream Analytics Microsoft Azure Tools for Visual Studio 2.9 Support for Azure Cloud Services projects Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines Mono Debugging for Visual Studio 17.5.9 (11975e6) Support for debugging Mono processes with Visual Studio. Node.js Tools 1.5.50105.3 Commit Hash:882de61a7c99ae988d4c62029301292a3e0b1d56 Adds support for developing and debugging Node.js apps in Visual Studio NuGet Package Manager 6.5.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/ Python - Profiling support 17.0.22336.2 Profiling support for Python projects. Python with Pylance 17.0.22336.2 Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers. Razor (ASP.NET Core) 17.5.2.2316603+9f1b6856460af1e592d387ebef416eadddac453f Provides languages services for ASP.NET Core Razor. SQL Server Data Tools 17.2.40120.0 Microsoft SQL Server Data Tools Test Adapter for Boost.Test 1.0 Enables Visual Studio's testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory. Test Adapter for Google Test 1.0 Enables Visual Studio's testing tools with unit tests written for Google Test. The use terms and Third Party Notices are available in the extension installation directory. ToolWindowHostedEditor 1.0 Hosting json editor into a tool window TypeScript Tools 17.0.20105.2003 TypeScript Tools for Microsoft Visual Studio Visual Basic Tools 4.5.2-3.23171.7+d17f741546fad2786cbd6394d08619544e53a36d Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Visual F# Tools 17.5.0-beta.23053.5+794b7c259d9646a7eb685dad865aa27da7940a21 Microsoft Visual F# Tools Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio. VisualStudio.DeviceLog 1.0 Information about my package VisualStudio.Mac 1.0 Mac Extension for Visual Studio VSPackage Extension 1.0 VSPackage Visual Studio Extension Detailed Info Xamarin 17.5.0.173 (d17-5@33e727c) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android. Xamarin Designer 17.5.3.46 (remotes/origin/d17-5@e4dd80b2bb) Visual Studio extension to enable Xamarin Designer tools in Visual Studio. Xamarin Templates 17.5.41 (ba80d05) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms. Xamarin.Android SDK 13.2.0.0 (d17-5/797e2e1) Xamarin.Android Reference Assemblies and MSBuild support. Mono: 6dd9def Java.Interop: xamarin/java.interop/main@149d70fe SQLite: xamarin/sqlite/3.40.0@fdc1e34 Xamarin.Android Tools: xamarin/xamarin-android-tools/main@9f02d77 Xamarin.iOS and Xamarin.Mac SDK 16.2.0.5 (7738c90c9) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
已知情况
- 项目覆盖Android/iOS/UWP,过去一年可正常编译,数周前UWP项目突然无法编译
- 办公室另一位开发者可正常编译该项目,未发现两台电脑配置差异
- 已搜索三周未找到有效解决方案
解决方案建议
- 清理本地NuGet缓存并重新还原:打开Visual Studio的「工具」→「NuGet包管理器」→「包管理器设置」,选择清除所有NuGet缓存;右键解决方案选择「还原NuGet包」
- 删除项目编译输出文件夹并重新生成:手动删除UWP项目下的
bin和obj文件夹,然后右键项目选择「重新生成」 - 检查并统一NuGet包版本:右键UWP项目→「管理NuGet包」,确认
Microsoft.NETCore.UniversalWindowsPlatform包版本与同事一致,若不一致则调整为相同版本并重新还原 - 修复Visual Studio安装:打开Visual Studio Installer,选择当前安装的VS版本,点击「修改」→「修复」,修复完成后重启VS重试编译
- 复制同事的NuGet包缓存:将同事本地
C:\Users\<username>\.nuget\packages\runtime.win10-x64.microsoft.netcore.universalwindowsplatform\6.2.14文件夹复制到自己的对应路径下 - 检查UWP项目目标版本:右键UWP项目→「属性」→「应用」,确认目标版本和最低版本与同事的配置一致
内容的提问来源于stack exchange,提问作者Gary H
相关产品推荐
相关产品推荐

