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

我有一个针对.net标准1.4的Xamarin.Forms应用程序。 在具有最低版本14393(和目标16299)的UWP应用程序上,我从Microsoft Store获得以下exception(尽管在我的计算机上它甚至可以从appxbundle文件运行良好):

注意要点:

  1. Xamarin.Forms.Forms.Init(e);发生错误Xamarin.Forms.Forms.Init(e);OnLaunched
  2. 错误本身是Could not load file or assembly 'System.Private.CoreLib...'

System.IO.FileNotFoundException:无法加载文件或程序集’System.Private.CoreLib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a’或其依赖项之一。 该系统找不到指定的文件。 文件名:System.ModuleHandle.ResolveType的’System.Private.CoreLib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a’(RuntimeModule模块,Int32 typeToken,IntPtr * typeInstArgs,Int32 typeInstCount,IntPtr * methodInstArgs,Int32 methodInstCount ,ObjectHandleOnStack类型)在System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule模块,Int32 typeToken,RuntimeTypeHandle [] typeInstantiationContext,RuntimeTypeHandle [] methodInstantiationContext)处于System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken,Type [] genericTypeArguments,Type [] genericMethodArguments)at at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord,MetadataImport范围,Assembly&lastAptcaOkAssembly,RuntimeModule decoratedModule,MetadataToken decoratedToken,RuntimeType attributeFilterType,Boolean mustBeInheritable,Object [] attributes,IList derivedAttributes,RuntimeType&attributeType,IRuntimeMethodInfo&ctor,Boolean&ctorHasParameters ,System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule,Int32 decoratedMetadataToken,Int32 pcaCount,RuntimeType attributeFilterType,Boolean mustBeInheritable,IList derivedAttributes,Boolean isDecoratedTargetSecurityTransparent),System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly,RuntimeType caType)at at System.Reflection.CustomAttribute.GetCustomAttributes(,Boolean&isVarArg)at System.Attribute.GetCustomAttributes(Assembly element,Type attributeType,Boolean inherit)的System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType,Boolean inherit)位于Xamarin.Forms的Xamarin.Forms.Internals.Registrar.RegisterAll(Type [] attrTypes) PasswordManager.UWP.App.d__1.MoveNext()中的.Forms.Init(IActivatedEventArgs launchActivatedEventArgs,IEnumerable`1 rendererAssemblies)

任何想法可能意味着什么,以及如何解决它?

鉴于您的软件包同时具有UWP和桌面组件,您将需要使用VS Packaging Project为Store提交创建.appxupload文件。

有关更多信息/示例,请查看此处:

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/ (参见示例#3)

Store不再接受具有未使用正确打包项目创建的混合UWP和Desktop .NET二进制文件的程序包。 这是为了确保UWP二进制文件在云中获得正确的.NET本机编译(这不适用于Desktop .NET二进制文件)。 在您的情况下,发生的事情是在Store中跳过.NET本机编译,导致无效的包,因为声明的依赖项与包的内容不匹配。 我们应该在这里改进我​​们的错误检测,以便我们在提交时通知您包裹不好并且需要更多工作。

如果您的Win32 EXE不是在VS中构建的,并且您只想在UWP项目中包含二进制文件,那么您仍应使用Packaging项目。 确保Win32 EXE被放入包的子文件夹中。 有关此类项目结构,请参见下面的屏幕截图

在此处输入图像描述

当我遇到这个问题时,它很简单地解决了 – 避免序列化generics集合。 在序列化之前,最好将您的集合转换为带有ToArray()的类型化数组。