简体   繁体   English

无法加载文件或程序集“ System.Private.CoreLib…”

[英]Could not load file or assembly 'System.Private.CoreLib…'

I have a Xamarin.Forms app which targets .net standard 1.4. 我有一个针对.net标准1.4的Xamarin.Forms应用。 On the UWP app which has minimum version 14393 (and targets 16299) I get the following exception from the Microsoft Store (though on my computer it runs fine even from the appxbundle file): 在最低版本为14393(目标为16299)的UWP应用上,我从Microsoft Store获得以下异常(尽管在我的计算机上,即使从appxbundle文件运行也很好):

Note the main points: 注意要点:

  1. The error occurs on Xamarin.Forms.Forms.Init(e); 该错误发生在Xamarin.Forms.Forms.Init(e); in OnLaunched . OnLaunched
  2. The error itself is Could not load file or assembly 'System.Private.CoreLib...' . 错误本身是Could not load file or assembly 'System.Private.CoreLib...'

System.IO.FileNotFoundException: Could not load file or assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. System.IO.FileNotFoundException:无法加载文件或程序集“ System.Private.CoreLib,版本= 4.0.0.0,区域性=中性,PublicKeyToken = b03f5f7f11d50a3a”或其依赖项之一。 The system cannot find the file specified. 该系统找不到指定的文件。 File name: 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 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 文件名:System.ModuleHandle.ResolveType(RuntimeModule模块,Int32 typeToken,IntPtr * typeInstArgs,Int32 typeInstCount,IntPtr * methodInstArgs,System.Private.CoreLib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a' ,ObjectHandleOnStack类型),位于System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule模块,Int32 typeToken,RuntimeTypeHandle [] typeInstantiationContext,RuntimeTypeHandle [] methodInstantiationContext),位于System.Reflection.RuntimeModule.ResolveType(Int32元数据令牌,Type [] genericTypeArguments,Type [] System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord,MetadataImport作用域,Assembly和lastAptcaOkAssembly,RuntimeModule装饰模块,MetadataToken装饰令牌,RuntimeType attributeFilterType,布尔值mustBeInheritable,Object []属性,IList派生属性,RuntimeType&AttributeType,IRuntimeMethodInfo和ctorHa,Boolean , 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.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit) at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit) at Xamarin.Forms.Internals.Registrar.RegisterAll(Type[] attrTypes) at Xamarin.Forms.Forms.Init(IActivatedEventArgs launchActivatedEventArgs, IEnumerable`1 rendererAssemblies) at PasswordManager.UWP.App.d__1.MoveNext() ,System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule装饰模块,Int32装饰型MetadataToken,Int32 pcaCount,RuntimeType属性过滤器类型,布尔值mustBeInheritable,IList派生属性,布尔型isDecoratedTargetSecurityTransparent)在System.Reflection.CustomAttribute.Assembly,RuntimeAssembly在Xamarin.Forms的Xamarin.Forms.Internals.Registrar.RegisterAll(Type [] attrTypes)的System.Attribute.GetCustomAttributes(Assembly元素,类型attributeType,布尔型继承)处的System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType,Boolean继承) .Forms.Init(IActivatedEventArgs launchActivatedEventArgs,IEnumerable`1 rendererAssemblies)在PasswordManager.UWP.App.d__1.MoveNext()

Any ideas what this might mean, and how to solve it? 有什么想法可能意味着什么,以及如何解决?

Given that your package has both UWP and Desktop components, you will need to use the VS Packaging Project for creating the .appxupload file for Store submission. 鉴于您的软件包同时具有UWP和Desktop组件,您将需要使用VS包装项目来创建.appxupload文件以提交商店。

For more info/examples, look here: 有关更多信息/示例,请参见此处:

https://stefanwick.com/2018/04/06/uwp-with-desktop-extension-part-1/ https://stefanwick.com/2018/04/06/uwp-with-desktop-extension-part-1/

https://blogs.windows.com/buildingapps/2017/12/04/extend-desktop-application-windows-10-features-using-new-visual-studio-application-packaging-project/ (see example #3) https://blogs.windows.com/buildingapps/2017/12/04/extend-desktop-application-windows-10-features-using-new-visual-studio-application-packaging-project/ (请参见示例#3)

The Store no longer accepts packages with mixed UWP and Desktop .NET binaries that have not been created with the proper packaging project. 应用商店不再接受使用正确的打包项目尚未创建的,带有混合UWP和Desktop .NET二进制文件的软件包。 This is to ensure the UWP binaries get the proper .NET native compile in the cloud (which is not applicable to the Desktop .NET binaries). 这是为了确保UWP二进制文件在云中获得正确的.NET本机编译(不适用于Desktop .NET二进制文件)。 In your case what happened is that the .NET native compile was skipped in the Store, resulting in an invalid package as the declared dependencies don't match the content of the package. 在您的情况下,发生的情况是在存储中跳过了.NET本机编译,导致了一个无效的程序包,因为声明的依赖项与程序包的内容不匹配。 We should improve our error detection here, so that we notify you right at submission time that your package is not good and needs more work. 我们应该在此处改进错误检测功能,以便我们在提交时立即通知您您的软件包不好,需要做更多的工作。

If your Win32 EXE is not built in VS and you just want to include the binary in your UWP project you should still use the Packaging project. 如果Win32 EXE不是VS内置的,而您只想在UWP项目中包含二进制文件,则仍应使用Packaging项目。 Make sure the Win32 EXE gets dropped into a subfolder of the package. 确保Win32 EXE放入软件包的子文件夹中。 See screenshot below for this type of project structure. 有关此类项目结构,请参见下面的屏幕截图。

在此处输入图片说明

When I encountered this problem it was solved quite simply - avoid serializing generic collections. 当我遇到此问题时,解决方法非常简单-避免序列化通用集合。 It seems to work best to convert your collection to a typed array with ToArray() before serializing. 似乎最好在序列化之前使用ToArray()将您的集合转换为类型化的数组。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure Function:System.Private.CoreLib:无法加载文件或程序集“System.ComponentModel.Annotations...” - Azure Function: System.Private.CoreLib: Could not load file or assembly 'System.ComponentModel.Annotations…' 无法加载文件或程序集“System.Private.CoreLib,Version=4.0.0.0,Culture=neutral,PublicKeyToken=7cec85d7bea7798e” - Could not load file or assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' System.TypeLoadException:无法从程序集“System.Private.CoreLib”加载类型“System.Object”,因为父级不存在 - System.TypeLoadException: Could not load type 'System.Object' from assembly 'System.Private.CoreLib' because the parent does not exist .Net Standard 4.7.1 在序列化期间无法加载 System.Private.CoreLib - .Net Standard 4.7.1 Could not load System.Private.CoreLib during serialization Azure函数:system.private.corelib:执行函数时发生异常 - Azure Function : system.private.corelib : exception while executing function UWP App RequestRestartAsync在System.Private.Corelib中引发异常 - UWP App RequestRestartAsync Throws Exception in System.Private.Corelib Asp Core新项目引发与“ System.Private.CoreLib”有关的异常 - Asp Core new project throws exceptions related to “System.Private.CoreLib” 无法加载文件或程序集'System.Private.ServiceModel,版本 = 4.1.2.4 - Could not load file or assembly 'System.Private.ServiceModel, Version=4.1.2.4 无法加载文件或程序集“系统” - Could not load file or assembly 'System 无法加载一种或多种请求的类型。 无法加载文件或程序集“Microsoft.VisualStudio.Coverage.CoreLib.Net - Unable to load one or more of the requested types. Could not load file or assembly 'Microsoft.VisualStudio.Coverage.CoreLib.Net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM