sgen TypeLoadException in Visual Studio for Mac when trying to build Xamarin.iOS app

2

When compiling our app on MacOS in Visual Studio (version 7.0.1 build 24), I'm presented with the error:

/Library/Frameworks/Mono.framework/Versions/5.0.1/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(5,5): Error MSB6006: "sgen.exe" exited with code 1. (MSB6006) (SyncWebClientLight)

If I start a build in Visual Studio 2015 Pro (with VS2015 connecting to the Mac and compiling it there), then I can debug etc. This would be great, except that I can't generate an archive for submission into the App Store from VS2015 (for whatever reason, the "Archive" menu option is greyed out)

Is there a way to disable sgen.exe in Visual Studio for Mac (some msbuild switch or something?) Might that help?

Update 1:

VS 2015 gives the following error:

Could not load file or assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)   SyncWebClientLight  C:\projects\mWORKSPACE\trunk\Source\SyncWebClientLight\SGEN

So that's a little more information, at least.

Update 2:

Target GenerateSerializationAssemblies:
    /Library/Frameworks/Mono.framework/Versions/5.0.1/lib/mono/4.5/sgen.exe /assembly:/Users/mj/Documents/projects/mWORKSPACE/Source/SyncWebClientLight/obj/iPhoneSimulator/Release/SBW.SyncWebClientLight.dll /proxytypes /reference:/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/mscorlib.dll /reference:/Users/mj/Documents/projects/mWORKSPACE/Release/SBW.Sync.dll /reference:/Users/mj/Documents/projects/mWORKSPACE/Debug/SBW.SystemBase.dll /reference:/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/System.Core.dll /reference:/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/System.Data.dll /reference:/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/System.dll /reference:/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/System.Web.Services.dll /reference:/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/System.Xml.dll /reference:/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Xamarin.iOS.dll 

    Unhandled Exception:
    System.TypeLoadException: Could not load type of field 'SyncWebClientLight.ClientPackageController:_syncDef' (2) due to: Could not load file or assembly 'SBW.Sync, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. assembly:SBW.Sync, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null type:<unknown type> member:<none>
      at (wrapper managed-to-native) System.RuntimeType:GetConstructors_native (System.RuntimeType,System.Reflection.BindingFlags)
      at System.RuntimeType.GetConstructors_internal (System.Reflection.BindingFlags bindingAttr, System.RuntimeType reflectedType) [0x00008] in <ffb99659fc1c47faa4d5f883014d08aa>:0 
      at System.RuntimeType.GetConstructorCandidates (System.String name, System.Reflection.BindingFlags bindingAttr, System.Reflection.CallingConventions callConv, System.Type[] types, System.Boolean allowPrefixLookup) [0x00034] in <ffb99659fc1c47faa4d5f883014d08aa>:0 
      at System.RuntimeType.GetConstructorImpl (System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Reflection.CallingConventions callConvention, System.Type[] types, System.Reflection.ParameterModifier[] modifiers) [0x00000] in <ffb99659fc1c47faa4d5f883014d08aa>:0 
      at System.Type.GetConstructor (System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Type[] types, System.Reflection.ParameterModifier[] modifiers) [0x00032] in <ffb99659fc1c47faa4d5f883014d08aa>:0 
      at System.Xml.Serialization.TypeScope.GetConstructorFlags (System.Type type, System.Exception& exception) [0x00000] in <3a4ce9be61fd46ab845a4d68f2905e06>:0 
      at System.Xml.Serialization.TypeScope.ImportTypeDesc (System.Type type, System.Reflection.MemberInfo memberInfo, System.Boolean directReference) [0x00444] in <3a4ce9be61fd46ab845a4d68f2905e06>:0 
      at System.Xml.Serialization.TypeScope.GetTypeDesc (System.Type type, System.Reflection.MemberInfo source, System.Boolean directReference, System.Boolean throwOnError) [0x00050] in <3a4ce9be61fd46ab845a4d68f2905e06>:0 
      at System.Xml.Serialization.TypeScope.GetTypeDesc (System.Type type, System.Reflection.MemberInfo source, System.Boolean directReference) [0x00000] in <3a4ce9be61fd46ab845a4d68f2905e06>:0 
      at System.Xml.Serialization.ModelScope.GetTypeModel (System.Type type, System.Boolean directReference) [0x00017] in <3a4ce9be61fd46ab845a4d68f2905e06>:0 
      at System.Xml.Serialization.ModelScope.GetTypeModel (System.Type type) [0x00000] in <3a4ce9be61fd46ab845a4d68f2905e06>:0 
      at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Type type, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x00014] in <3a4ce9be61fd46ab845a4d68f2905e06>:0 
      at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Type type) [0x00000] in <3a4ce9be61fd46ab845a4d68f2905e06>:0 
      at Driver.Run (System.String[] args) [0x00110] in <eeaf85d64a8c4c2eb792db70e13a9f1e>:0 
      at Driver.Main (System.String[] args) [0x00005] in <eeaf85d64a8c4c2eb792db70e13a9f1e>:0 
    [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type of field 'SyncWebClientLight.ClientPackageController:_syncDef' (2) due to: Could not load file or assembly 'SBW.Sync, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. assembly:SBW.Sync, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null type:<unknown type> member:<none>
      at (wrapper managed-to-native) System.RuntimeType:GetConstructors_native (System.RuntimeType,System.Reflection.BindingFlags)
      at System.RuntimeType.GetConstructors_internal (System.Reflection.BindingFlags bindingAttr, System.RuntimeType reflectedType) [0x00008] in <ffb99659fc1c47faa4d5f883014d08aa>:0 
      at System.RuntimeType.GetConstructorCandidates (System.String name, System.Reflection.BindingFlags bindingAttr, System.Reflection.CallingConventions callConv, System.Type[] types, System.Boolean allowPrefixLookup) [0x00034] in <ffb99659fc1c47faa4d5f883014d08aa>:0 
      at System.RuntimeType.GetConstructorImpl (System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Reflection.CallingConventions callConvention, System.Type[] types, System.Reflection.ParameterModifier[] modifiers) [0x00000] in <ffb99659fc1c47faa4d5f883014d08aa>:0 
      at System.Type.GetConstructor (System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Type[] types, System.Reflection.ParameterModifier[] modifiers) [0x00032] in <ffb99659fc1c47faa4d5f883014d08aa>:0 
      at System.Xml.Serialization.TypeScope.GetConstructorFlags (System.Type type, System.Exception& exception) [0x00000] in <3a4ce9be61fd46ab845a4d68f2905e06>:0 
      at System.Xml.Serialization.TypeScope.ImportTypeDesc (System.Type type, System.Reflection.MemberInfo memberInfo, System.Boolean directReference) [0x00444] in <3a4ce9be61fd46ab845a4d68f2905e06>:0 
      at System.Xml.Serialization.TypeScope.GetTypeDesc (System.Type type, System.Reflection.MemberInfo source, System.Boolean directReference, System.Boolean throwOnError) [0x00050] in <3a4ce9be61fd46ab845a4d68f2905e06>:0 
      at System.Xml.Serialization.TypeScope.GetTypeDesc (System.Type type, System.Reflection.MemberInfo source, System.Boolean directReference) [0x00000] in <3a4ce9be61fd46ab845a4d68f2905e06>:0 
      at System.Xml.Serialization.ModelScope.GetTypeModel (System.Type type, System.Boolean directReference) [0x00017] in <3a4ce9be61fd46ab845a4d68f2905e06>:0 
      at System.Xml.Serialization.ModelScope.GetTypeModel (System.Type type) [0x00000] in <3a4ce9be61fd46ab845a4d68f2905e06>:0 
      at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Type type, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x00014] in <3a4ce9be61fd46ab845a4d68f2905e06>:0 
      at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Type type) [0x00000] in <3a4ce9be61fd46ab845a4d68f2905e06>:0 
      at Driver.Run (System.String[] args) [0x00110] in <eeaf85d64a8c4c2eb792db70e13a9f1e>:0 
      at Driver.Main (System.String[] args) [0x00005] in <eeaf85d64a8c4c2eb792db70e13a9f1e>:0 
    /Library/Frameworks/Mono.framework/Versions/5.0.1/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(3366,5): error MSB6006: "sgen.exe" exited with code 1.
Done building target "GenerateSerializationAssemblies" in project "SyncWebClientLight.csproj" -- FAILED.

The Type is there though: I can drill down to its reference in VS4mac, the project SBW.Sync compiles fine, SyncWebClientLight is referencing the correct assembly.

It would be nice if I knew where it was loading the assembly from (is there a fuslogvw.exe in mono?)

ios
xamarin
visual-studio-2015
xamarin.ios
visual-studio-mac
asked on Stack Overflow Jun 2, 2017 by Matt Jacobsen • edited Jan 16, 2019 by Erik A

3 Answers

1

So, it seems that Visual Studio for Mac doesn't understand the csproj/msbuild flag:

<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>

And sgen is the thing that won't let me get on with my work day. So let's replace sgen with our own version that does nothing!

sgen is located on my Mac at:

/Library/Frameworks/Mono.framework/Versions/5.0.1/lib/mono/4.5

I made a simple .NET console app in VS4mac that does nothing, and copied it to that dir, replacing the original sgen.exe

I can now compile my assembly, resulting in a warm feeling of bliss marred only slightly by the worry that I've done something I probably shouldn't have.

If anyone knows how to fix this properly, I'd be much obliged.

answered on Stack Overflow Jun 6, 2017 by Matt Jacobsen
1

That helped me figure out what's going on. This is a msbuild vs xbuild bug:

xbuild WebServicesNotWorking.sln /p:Configuration=Release (Works)
msbuild WebServicesNotWorking.sln /p:Configuration=Release (Your error).

Resolution:

  1. Use XS instead of VSfM
  2. Uncheck Preferences -> Projects -> Build -> Build with MSBuild instead of xbuild (I don't recommend this as it may affect other things)
  3. Build the project with xbuild and check in the output for now.
answered on Stack Overflow Oct 9, 2017 by Mayank Kumar • edited Oct 9, 2017 by Yaseen Ahmad
0

This is a partial answer to your question, it provides the solution for your general problem (submitting to the App Store), but not the one that you have mentioned in the title of the question.

It is possible to use Visual Studio for Windows and to create the package to be submitted (and use Apple's Application Loader to submit it). You need to set the build configuration to Ad-Hoc (not Debug or Release), build platform to iPhone, set your certificates and click Rebuild All, then .ipa file will be generated on both your Windows and Mac and you can use it to submit it to the Store.

See more on Xamarin site https://developer.xamarin.com/guides/ios/deployment,_testing,_and_metrics/app_distribution/app-store-distribution/publishing_to_the_app_store/

answered on Stack Overflow Jun 6, 2017 by Ivan Ičin

User contributions licensed under CC BY-SA 3.0