I'm able to build the app in Windows on the latest version of VS2017 (15.9.2) for both Android and iOS, and I'm able to use the Remote iOS Simulator to run my iOS app as built on my Mac. However, when I use the same solution on my 2009 iMac on High Sierra in Visual Studio for Mac, I get an exception on one of my .NET Standard libraries from sgen.exe when msbuild attempts to generate the serialization assemblies:
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.
To try to get past this, I commented out the class that is failing (within cs in the exception above) along with the using statements in that file related to Newtonsoft.Json. After doing this, I get the following exception:
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.
I've also tried the following:
- Changing the linker behavior from anything to not linking at all to linking everything. There was no difference.
- Setting "Generate Serialization Assembly" to "Off" in the project settings. The app built in Windows, but while loading it crashes. There does not appear to be an option to control this in Visual Studio for Mac.
- Changing all PCL projects to .NET Standard 2.0 projects and changing all Xamarin Droid or iOS projects to use PackageReferences instead of the package.config
- Adding the latest version of Newtonsoft.Json to all projects in the solution
- Updated Mono, Xamarin and VS for Mac to the latest versions
Does anybody have any ideas? Again, both iOS and Android builds seem to work in Visual Studio 2017 on Windows, but they do not on my Mac. Thanks in advance for your help!