gpt4 book ai didi

c# - System.Runtime.CompilerServices.Unsafe 在 Xamarin Forms 中产生意外行为

转载 作者:太空宇宙 更新时间:2023-11-03 20:56:47 26 4
gpt4 key购买 nike

我构建了一个完整的 Xamarin From 应用程序。当我将构建模式更改为 Release 时,我收到此错误消息:

Severity Code Description Project File Line Suppression State Error The "LinkAssemblies" task failed unexpectedly. Mono.Linker.MarkException: Error processing method: 'System.Void Microsoft.Extensions.Primitives.InplaceStringBuilder::Append(System.String,System.Int32,System.Int32)' in assembly: 'Microsoft.Extensions.Primitives.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.Void System.Runtime.CompilerServices.Unsafe::CopyBlockUnaligned(System.Void*,System.Void*,System.UInt32) at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference) at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference) at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body) at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
at Mono.Linker.Steps.MarkStep.ProcessQueue() --- End of inner exception stack trace --- at Mono.Linker.Steps.MarkStep.ProcessQueue() at Mono.Linker.Steps.MarkStep.ProcessEntireQueue() at Mono.Linker.Steps.MarkStep.Process() at Mono.Linker.Steps.MarkStep.Process(LinkContext context) at Mono.Linker.Pipeline.Process(LinkContext context) at MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context) at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res) at Xamarin.Android.Tasks.LinkAssemblies.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() EClinicForDoctor.Android

在网上搜索后,我找到了这个solution其中说:

此问题的解决方法是确保您拥有支持的最新 Android SDK 版本,并将目标框架设置为使用最新安装的平台。还建议您将目标 Android 版本设置为使用目标框架版本,并将最低 Android 版本设置为 API 15 或更高版本。这被认为是受支持的配置。

因此我更新了 Android SDK,设置了目标框架并将最低 Android 版本设置为 API 15。

enter image description here enter image description here enter image description here

但是,我仍然得到同样的错误。另一个解决方案说我应该更新 NuGet 包。我发现 System.Runtime.CompilerServices.Unsafe 包的版本是 4.3.0,并且有一个针对此包的更新。更新包时,错误不再出现,但出现另一个问题。当应用程序部署时,它运行和停止时没有任何错误消息。手机只是退出应用程序而不显示任何错误消息。当包 System.Runtime.CompilerServices.Unsafe 的版本高于 4.3.0 时,会发生这种情况。我试图删除包,同样的问题再次发生。我该如何解决这个问题?

最佳答案

我现在已经在几个不同的位置看到了这个问题弹出窗口。围绕它进行了一些讨论,如下所示:https://github.com/xamarin/xamarin-android/issues/1196

这个 Github 问题还列出了一些(可能的)解决方案,反馈最积极的似乎是这个:

Here's a functioning workaround. It's hacky and ugly but works with minimum fuss. Put this in an XML file and <Import> it in your Android csproj file at the end. It works at least for System.Buffers

<!-- Workaround for https://github.com/xamarin/xamarin-android/issues/1162 -->
<Project>
<Target Name="ReplaceRefAssemblies" AfterTargets="_ResolveAssemblies">
<ItemGroup>
<ResolvedAssembliesFixedWindows Include="@(ResolvedAssemblies->Replace('\ref\','\lib\'))" />
<ResolvedAssembliesFixedUnix Include="@(ResolvedAssemblies->Replace('/ref/','/lib/'))" />
<ResolvedAssembliesFixed Include="@(ResolvedAssembliesFixedWindows)" Condition="@(ResolvedAssembliesFixedWindows) != @(ResolvedAssemblies)" />
<ResolvedAssembliesFixed Include="@(ResolvedAssembliesFixedUnix)" Condition="@(ResolvedAssembliesFixedUnix) != @(ResolvedAssemblies)" />
<ResolvedAssemblies Remove="@(ResolvedAssemblies)" />
<ResolvedAssemblies Include="@(ResolvedAssembliesFixed)" />
</ItemGroup>
</Target>
</Project>

另一个使用上面的 XML 并说:

  1. I've just copied the content from the link above and saved as UnsafeFix.xml file in the Android project folder.
  2. Then just added: <Import Project="UnsafeFix.xml" /> at the end of android .csproj file, just before
  3. Cleared everything, recompiled and it finally worked!

关于c# - System.Runtime.CompilerServices.Unsafe 在 Xamarin Forms 中产生意外行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49731480/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com