Xamarin Apps建立在VS2017而非Mac的VS上

时间:2018-11-27 23:05:17

标签: visual-studio xamarin json.net visual-studio-mac sgen

我可以在Windows上针对Android和iOS在最新版本的VS2017(15.9.2)上构建该应用程序,并且可以使用远程iOS模拟器来运行基于我的iOS应用程序苹果电脑。但是,当我在Visual Studio for Mac的High Sierra上的2009 iMac上使用相同的解决方案时,当msbuild尝试生成序列化程序集时,我从sgen.exe获得了一个.NET Standard库的异常:

Unhandled Exception:     
System.TypeLoadException: Could not load type of field '<TYPENAME>+<>c__DisplayClass3_0:obj' (0) due to: Could not load file or assembly 'Newtonsoft.Json,
 Version=12.0.0.0,
 Culture=neutral,
 PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies.    

为了解决这个问题,我注释掉了失败的类(在上面的例外中的cs中),以及该文件中与Newtonsoft.Json相关的using语句。完成此操作后,出现以下异常:

Unhandled Exception:     System.NullReferenceException: Object reference not set to an instance of an object    
at System.Xml.Serialization.XmlSerializationWriterCodeGen.FindXmlnsIndex (System.Xml.Serialization.MemberMapping[] members) [0x00014] in <9e212f4dac634c83bb98a320d2c5ec4d>:0     
at System.Xml.Serialization.XmlSerializationWriterCodeGen.WriteStructMethod (System.Xml.Serialization.StructMapping mapping) [0x00359] in <9e212f4dac634c83bb98a320d2c5ec4d>:0     
at System.Xml.Serialization.XmlSerializationWriterCodeGen.GenerateMethod (System.Xml.Serialization.TypeMapping mapping) [0x00024] in <9e212f4dac634c83bb98a320d2c5ec4d>:0     
at System.Xml.Serialization.XmlSerializationCodeGen.GenerateReferencedMethods () [0x0001b] in <9e212f4dac634c83bb98a320d2c5ec4d>:0     
at System.Xml.Serialization.XmlSerializationWriterCodeGen.GenerateEnd () [0x00000] in <9e212f4dac634c83bb98a320d2c5ec4d>:0     
at System.Xml.Serialization.TempAssembly.GenerateAssembly (System.Xml.Serialization.XmlMapping[] xmlMappings,  System.Type[] types,  System.String defaultNamespace,  System.Security.Policy.Evidence evidence,  System.Xml.Serialization.XmlSerializerCompilerParameters parameters,  System.Reflection.Assembly assembly,  System.Collections.Hashtable assemblies) [0x003a7] in <9e212f4dac634c83bb98a320d2c5ec4d>:0     
at System.Xml.Serialization.XmlSerializer.GenerateSerializer (System.Type[] types,  System.Xml.Serialization.XmlMapping[] mappings,  System.CodeDom.Compiler.CompilerParameters parameters) [0x000cb] in <9e212f4dac634c83bb98a320d2c5ec4d>:0     
at Driver.Run (System.String[] args) [0x0042c] in <4ef54e9b09fa46d8995a283d81fa42c0>:0     
at Driver.Main (System.String[] args) [0x00005] in <4ef54e9b09fa46d8995a283d81fa42c0>:0      [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object    
at System.Xml.Serialization.XmlSerializationWriterCodeGen.FindXmlnsIndex (System.Xml.Serialization.MemberMapping[] members) [0x00014] in <9e212f4dac634c83bb98a320d2c5ec4d>:0     
at System.Xml.Serialization.XmlSerializationWriterCodeGen.WriteStructMethod (System.Xml.Serialization.StructMapping mapping) [0x00359] in <9e212f4dac634c83bb98a320d2c5ec4d>:0     
at System.Xml.Serialization.XmlSerializationWriterCodeGen.GenerateMethod (System.Xml.Serialization.TypeMapping mapping) [0x00024] in <9e212f4dac634c83bb98a320d2c5ec4d>:0     
at System.Xml.Serialization.XmlSerializationCodeGen.GenerateReferencedMethods () [0x0001b] in <9e212f4dac634c83bb98a320d2c5ec4d>:0     
at System.Xml.Serialization.XmlSerializationWriterCodeGen.GenerateEnd () [0x00000] in <9e212f4dac634c83bb98a320d2c5ec4d>:0     
at System.Xml.Serialization.TempAssembly.GenerateAssembly (System.Xml.Serialization.XmlMapping[] xmlMappings,  System.Type[] types,  System.String defaultNamespace,  System.Security.Policy.Evidence evidence,  System.Xml.Serialization.XmlSerializerCompilerParameters parameters,  System.Reflection.Assembly assembly,  System.Collections.Hashtable assemblies) [0x003a7] in <9e212f4dac634c83bb98a320d2c5ec4d>:0     
at System.Xml.Serialization.XmlSerializer.GenerateSerializer (System.Type[] types,  System.Xml.Serialization.XmlMapping[] mappings,  System.CodeDom.Compiler.CompilerParameters parameters) [0x000cb] in <9e212f4dac634c83bb98a320d2c5ec4d>:0     
at Driver.Run (System.String[] args) [0x0042c] in <4ef54e9b09fa46d8995a283d81fa42c0>:0     
at Driver.Main (System.String[] args) [0x00005] in <4ef54e9b09fa46d8995a283d81fa42c0>:0      /Library/Frameworks/Mono.framework/Versions/5.16.0/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(3553, 5): error MSB6006: "sgen.exe" exited with code 1. Done building target "GenerateSerializationAssemblies" in project "<PROJECTNAME>.csproj" -- FAILED.

我也尝试了以下方法:

  • 将链接器行为从任何内容更改为完全不链接,改为链接所有内容。没有区别。
  • 在项目设置中将“生成序列化程序集”设置为“关”。该应用程序内置于Windows,但在加载时崩溃。在Visual Studio for Mac中似乎没有控制它的选项。
  • 将所有PCL项目更改为.NET Standard 2.0项目,并将所有Xamarin Droid或iOS项目更改为使用PackageReferences而不是package.config
  • 将最新版本的Newtonsoft.Json添加到解决方案中的所有项目中
  • 将Mac版Mono,Xamarin和VS更新到最新版本

有人有什么想法吗?同样,iOS和Android版本似乎都可以在Windows的Visual Studio 2017中使用,但在我的Mac上却不能。预先感谢您的帮助!

0 个答案:

没有答案