Xamarin.android ";链接组件“;Xamarin Android中的任务意外失败

Xamarin.android ";链接组件“;Xamarin Android中的任务意外失败,xamarin.android,Xamarin.android,我正在尝试使用RESTAPI发布数据。这个应用程序过去运行得很完美,但现在我已经添加了执行POST的代码,我遇到了一个新的错误。有没有人能帮我解释一下哪里出了问题,并提出一个替代方案,让我成功地完成POST请求 以下是我尝试在发布配置中启用链接器的情况下构建应用程序时遇到的错误: Error The "LinkAssemblies" task failed unexpectedly. Xamarin.Android.XamarinAndroidException: error XA2

我正在尝试使用RESTAPI发布数据。这个应用程序过去运行得很完美,但现在我已经添加了执行POST的代码,我遇到了一个新的错误。有没有人能帮我解释一下哪里出了问题,并提出一个替代方案,让我成功地完成POST请求

以下是我尝试在发布配置中启用链接器的情况下构建应用程序时遇到的错误:

Error       The "LinkAssemblies" task failed unexpectedly.
Xamarin.Android.XamarinAndroidException: error XA2006: Reference to metadata item 'System.Runtime.InteropServices.StandardOleMarshalObject' (defined in 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') from 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' could not be resolved. ---> Mono.Cecil.ResolutionException: Failed to resolve System.Runtime.InteropServices.StandardOleMarshalObject
   at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
   at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
   at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
   at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
   at Mono.Linker.Steps.MarkStep.InitializeType(TypeDefinition type)
   at Mono.Linker.Steps.MarkStep.InitializeAssembly(AssemblyDefinition assembly)
   at Mono.Linker.Steps.MarkStep.Initialize()
   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()
   --- End of inner exception stack trace ---
   at Xamarin.Android.Diagnostic.Error(Int32 code, Exception innerException, String message, Object[] args)
   at Xamarin.Android.Tasks.LinkAssemblies.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() GimcoIOT.Andriod
错误“链接程序集”任务意外失败。
Xamarin.Android.XamarinAndroidException:错误XA2006:引用“System.Windows.Forms,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”中的元数据项“System.Runtime.InteropServices.StandardOleMarshalObject”(定义于“System.Windows.Forms,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089'无法解析。-->Mono.Cecil.ResolutionException:未能解析System.Runtime.InteropServices.StandardOleMarshalObject
位于Mono.Linker.Steps.MarkStep.MarkType(类型引用)
在MonoDroid.Tuner.MonoDroid.markstep.MarkType(类型引用)
位于Mono.Linker.Steps.MarkStep.MarkType(类型引用)
在MonoDroid.Tuner.MonoDroid.markstep.MarkType(类型引用)
位于Mono.Linker.Steps.MarkStep.InitializeType(类型定义类型)
在Mono.Linker.Steps.MarkStep.InitializeAssembly(AssemblyDefinition assembly)处
在Mono.Linker.Steps.MarkStep.Initialize()中
位于Mono.Linker.Steps.MarkStep.Process(LinkContext)
在Mono.Linker.Pipeline.Process(LinkContext)上
在MonoDroid.Tuner.Linker.Process(LinkerOptions选项、LinkContext和context)
在Xamarin.Android.Tasks.LinkAssemblies.Execute()中
---内部异常堆栈跟踪的结束---
在Xamarin.Android.Diagnostic.Error(Int32代码,异常innerException,字符串消息,对象[]args)
在Xamarin.Android.Tasks.LinkAssemblies.Execute()中
位于Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ItaskeExecutionHost.Execute()
在Microsoft.Build.BackEnd.TaskBuilder.d_u26.MoveNext()gimciot.Andriod

看起来您可能在Xamarin.Android应用程序中添加了对桌面.NET程序集的引用。
System.Windows.Forms
命名空间在Xamarin.Android配置文件中不可用。(即使当您禁用链接时应用程序成功构建,理论上,当它尝试运行引用
System.Windows.Forms
命名空间的代码时,它在运行时仍然会失败。)

要解决此问题,您需要从Xamarin.Android项目中删除对desktop.NET程序集的引用,并确保根据Xamarin.Android配置文件或支持的PCL配置文件编译所有其他引用的程序集

如报告中所述:

Android与为不同配置文件编译的现有程序集不兼容。您必须重新编译源代码以生成针对Xamarin.Android概要文件的程序集(正如您需要重新编译源代码以分别针对Silverlight和.NET 3.5)

(可移植类库是此规则的特殊例外。)



如果当前正在使用
System.Windows.Forms
命名空间中的类型来执行POST请求,则需要切换到其他类型。例如,中的一个
PostAsync()
方法可能工作得很好。

看起来您可能在Xamarin.Android应用程序中添加了对桌面.NET程序集的引用。
System.Windows.Forms
命名空间在Xamarin.Android配置文件中不可用。(即使当您禁用链接时应用程序成功构建,理论上,当它尝试运行引用
System.Windows.Forms
命名空间的代码时,它在运行时仍然会失败。)

要解决此问题,您需要从Xamarin.Android项目中删除对desktop.NET程序集的引用,并确保根据Xamarin.Android配置文件或支持的PCL配置文件编译所有其他引用的程序集

如报告中所述:

Android与为不同配置文件编译的现有程序集不兼容。您必须重新编译源代码以生成针对Xamarin.Android概要文件的程序集(正如您需要重新编译源代码以分别针对Silverlight和.NET 3.5)

(可移植类库是此规则的特殊例外。)



如果当前正在使用
System.Windows.Forms
命名空间中的类型来执行POST请求,则需要切换到其他类型。例如,中的一个
PostAsync()
方法可能会很好地工作。

我的帖子代码中没有错误。在发布模式下执行时,我的帖子代码中没有错误。在发布模式下执行时,我收到此错误