Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ben06feb · Jul 22, 2018 at 12:15 PM · iosxmlserializerdeserialization

XML Decentralization not working in Unity iOS build which working in Windows

I am getting details for setting up UI and message through XML placed in a custom folder of the build. Its working fine in Windows build, not in iOS. I am attaching the Script used.

XML Operation

 using System.IO;
 using System.Xml.Serialization;
 using UnityEngine;
 using System.Xml;
 
 public class XMLOperations
 {
     public static void Serialize(object item, string path)
     {
         XmlSerializer serializer = new XmlSerializer(item.GetType());
         StreamWriter writer = new StreamWriter(path);
         serializer.Serialize(writer.BaseStream, item);
         writer.Close();
     }
 
     public static T Deserialize<T>(string path)
     {
         XmlSerializer serializer = new XmlSerializer(typeof(T));
         StreamReader reader = new StreamReader(path);
         T deserialized = (T)serializer.Deserialize(reader.BaseStream);
         reader.Close();
         Debug.Log(deserialized);
         return deserialized;
     }
 }

Extract details of XML

 using System.Xml.Serialization;
 using System.IO;
 using System.Text;
 
 [XmlRoot("WelcomePage")]
 public class WelcomePage
 {
     [XmlElement("Background")]
     public GenericDetails background;
     [XmlElement("MotionBand")]
     public GenericDetails motionBand;
     [XmlElement("DefaultLogo")]
     public GenericDetails defaultLogo;
     [XmlElement("WelcomeMessage")]
     public GenericDetails welcomeMessage;
     [XmlElement("VisitName")]
     public GenericDetails visitName;
     [XmlElement("VisitorName")]
     public GenericDetails[] visitorName;
     [XmlElement("Date")]
     public GenericDetails date;
     [XmlElement("Location")]
     public GenericDetails location;
     [XmlElement("CustomerLogo")]
     public GenericDetails customerLogo;
 }
 
 public class GenericDetails
 {
     [XmlElement("ImagePath")]
     public string path;
     [XmlElement("Rect")]
     public string rect;
     [XmlElement("BGColor")]
     public string bgColor;
     [XmlElement("TextAlignment")]
     public string alignment;
     [XmlElement("TextColor")]
     public string textColor;
     [XmlElement("BGTransparency")]
     public float bgTransparency;
     [XmlElement("MaxFontSize")]
     public int maxFontSize;
 }
 
 public class WelcomePageSetup
 {
     public WelcomePageSetup(string url)
     {
         if (!File.Exists(url))
         {
             if (!Directory.Exists(Path.GetDirectoryName(url)))
                 Directory.CreateDirectory(Path.GetDirectoryName(url));
 
             File.WriteAllText(url, WelcomeLayout._main.welcomePageDetails, Encoding.UTF8);
         }
     }
 }

XML File with details

 <?xml version="1.0" encoding="utf-8"?>
 <WelcomePage>
 
   <Background>
     <Rect>1232,0,688,1080</Rect>
     <BGColor>#000000</BGColor>
     <BGTransparency>0.7</BGTransparency>
   </Background>
 
   <MotionBand>
     <ImagePath>/UI/Images/MotionBand.png</ImagePath>
     <Rect>1842,0,78,1080</Rect>
   </MotionBand>
 
   <DefaultLogo>
     <ImagePath>/UI/Images/DefaultLogo.png</ImagePath>
     <Rect>1497,23,320,60</Rect>
   </DefaultLogo>
   
   <WelcomeMessage>
     <Rect>1272,942,557,126</Rect>
     <TextAlignment>mc</TextAlignment>
     <TextColor>#F0AB00</TextColor>
     <MaxFontSize>55</MaxFontSize>
   </WelcomeMessage>
      
   <VisitName>
     <Rect>1272,810,557,123</Rect>
     <TextAlignment>ml</TextAlignment>
     <TextColor>#ffffff</TextColor>
     <MaxFontSize>35</MaxFontSize>
   </VisitName>
 
   <!--Visitor name - we can have 5 visitor name display at a time-->
   <!--Visitor name 1-->
   <VisitorName>
     <Rect>1272,715,557,65</Rect>
     <TextAlignment>ml</TextAlignment>
     <TextColor>#ffffff</TextColor>
     <MaxFontSize>35</MaxFontSize>
   </VisitorName>
 
   <!--Visitor name 2-->
   <VisitorName>
     <Rect>1272,635,557,65</Rect>
     <TextAlignment>ml</TextAlignment>
     <TextColor>#ffffff</TextColor>
     <MaxFontSize>35</MaxFontSize>
   </VisitorName>
 
   <!--Visitor name 3-->
   <VisitorName>
     <Rect>1272,555,557,65</Rect>
     <TextAlignment>ml</TextAlignment>
     <TextColor>#ffffff</TextColor>
     <MaxFontSize>35</MaxFontSize>
   </VisitorName>
 
   <!--Visitor name 4-->
   <VisitorName>
     <Rect>1272,475,557,65</Rect>
     <TextAlignment>ml</TextAlignment>
     <TextColor>#ffffff</TextColor>
     <MaxFontSize>35</MaxFontSize>
   </VisitorName>
 
   <!--Visitor name 5-->
   <VisitorName>
     <Rect>1272,395,557,65</Rect>
     <TextAlignment>ml</TextAlignment>
     <TextColor>#ffffff</TextColor>
     <MaxFontSize>35</MaxFontSize>
   </VisitorName>
 
   <Date>
     <Rect>1272,190,557,48</Rect>
     <TextAlignment>ml</TextAlignment>
     <TextColor>#ffffff</TextColor>
     <MaxFontSize>30</MaxFontSize>
   </Date>
   
   <Location>
     <Rect>1272,140,557,48</Rect>
     <TextAlignment>ml</TextAlignment>
     <TextColor>#F0AB00</TextColor>
     <MaxFontSize>30</MaxFontSize>
   </Location>
 
   <CustomerLogo>
     <Rect>1272,274,140,70</Rect>
   </CustomerLogo>
  
 </WelcomePage>

Calling it through script and path

 using UnityEngine;
 using UnityEngine.UI;
 using System.IO;
 using System.Collections.Generic;
 using System;
 using System.Collections;
 
 public class WelcomeLayout : MonoBehaviour
 {
     public static WelcomeLayout _main;
     public WelcomePage welcomePage;
 
     public RectTransform background;
     public RectTransform motionBand;
     public RectTransform defaultLogo;
     public RectTransform welcomeMessage;
     public RectTransform visitName;
     public RectTransform date;
     public RectTransform location;
     public RectTransform[] visitorName;
     public RectTransform customerLogo;
     
     public Image backgroundBG;
     public Image motionBandImg;
     public Image defaultLogoImg;
     public Image customerLogoImg;
 
     public Text welcomeMessageTxt;
     public Text visitNameTxt;
     public Text dateTxt;
     public Text locationTxt;
     public Text[] visitorNameTxt;
  
     public GameObject[] visitorNameGObj;
 
     string path_base;
     string filePath;
 
     public GameObject welcomeScreenSet;
 
     public bool welcomeScreenDisplayTimer;
     public float welcomeTimer;
     public bool checkOnce;
 
     public bool displayVisiorNameNewSet;
     public float displayVisitorTimer;
     public float displayDuration;
     int displayFrom;
 
     public string currentTime;
     public string currentDay;
 
     public string currentTestTime;
 
     WelcomePageSetup welcomePageSetup;
     
     private void Awake()
     {
         _main = this;
     }
 
     private void Start()
     {
         path_base = Application.dataPath + "/Resources";
 
         path_base = Application.persistentDataPath+ "/Resources";
 #endif
 
         filePath = path_base + "/WelcomeScreenTemplate.xml";
 
         FileInfo file = new FileInfo(filePath);
 
         if (file.Exists)
         {
             Debug.Log("welcome xml available");
         }
         else
         {
             Debug.Log("welcome xml not available - create xml file");
             welcomePageSetup = new WelcomePageSetup(filePath);
         }
 
         if (file.Exists)
         {
             welcomePage = XMLOperations.Deserialize<WelcomePage>(filePath);
         }
     }
 
     //Setup welcome page using XML details
     public void SetWelcomeLayout(string visit, string loc, string day, string welcome, List<string> visitor, string logo)
     {
         //Set BG
         SetRectTransform(welcomePage.background.rect, background);
         SetColor(backgroundBG, welcomePage.background.bgColor, welcomePage.background.bgTransparency);
 
         //Set motion band
         SetSpriteOnImage(motionBandImg, path_base + welcomePage.motionBand.path);
         SetRectTransform(welcomePage.motionBand.rect, motionBand);
 
         //Set default logo
         SetSpriteOnImage(defaultLogoImg, path_base + welcomePage.defaultLogo.path);
         SetRectTransform(welcomePage.defaultLogo.rect, defaultLogo);
 
         //Set Welcome message
         welcomeMessageTxt.text = welcome;
         SetRectTransform(welcomePage.welcomeMessage.rect, welcomeMessage);
         SetColor(welcomeMessageTxt, welcomePage.welcomeMessage.textColor);
         AlignTextAndMaxFont(welcomeMessageTxt, welcomePage.welcomeMessage.alignment, welcomePage.welcomeMessage.maxFontSize);
 
         //Set visit name
         //byte[] bytes = Encoding.Default.GetBytes(visit);
         //visit = Encoding.UTF8.GetString(bytes);
         visitNameTxt.text = visit.ToUpper();
         SetRectTransform(welcomePage.visitName.rect, visitName);
         SetColor(visitNameTxt, welcomePage.visitName.textColor);
         AlignTextAndMaxFont(visitNameTxt, welcomePage.visitName.alignment, welcomePage.visitName.maxFontSize);
 
         //Set date
         //dateTxt.text = day;
         currentDay = day;
         SetRectTransform(welcomePage.date.rect, date);
         SetColor(dateTxt, welcomePage.date.textColor);
         AlignTextAndMaxFont(dateTxt, welcomePage.date.alignment, welcomePage.date.maxFontSize);
 
         //Set location
         locationTxt.text = loc;
         SetRectTransform(welcomePage.location.rect, location);
         SetColor(locationTxt, welcomePage.location.textColor);
         AlignTextAndMaxFont(locationTxt, welcomePage.location.alignment, welcomePage.location.maxFontSize);
 }

}

Please do check the script and help me out to resolve the issue. Its working fine in standalone builds, I can edit the XML details, its reflecting the UI. In iOS build its not de-serializing, the function with XML details got error because of details not de-serializing and retrieved.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ben06feb · Jul 22, 2018 at 12:26 PM 0
Share

Exception in iOS - Xcode

welcome xml available WelcomeLayout:Start()

(Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)

NotSupportedException: /Users/builduser/buildslave/unity/build/External/il2cpp/il2cpp/libil2cpp/icalls/mscorlib/System.Reflection.Emit/AssemblyBuilder.cpp(20) : Unsupported internal call for IL2CPP:AssemblyBuilder::basic_init - System.Reflection.Emit is not supported.

at System.Reflection.Emit.AssemblyBuilder..ctor (System.Reflection.AssemblyName n, System.String directory, System.Reflection.Emit.AssemblyBuilderAccess access, System.Boolean corlib_internal) [0x00000] in :0

at System.AppDomain.DefineDynamicAssembly (System.Reflection.AssemblyName name, System.Reflection.Emit.AssemblyBuilderAccess access, System.String dir, System.Security.Policy.Evidence evidence, System.Security.PermissionSet requiredPermissions, System.Security.PermissionSet optionalPermissions, System.Security.PermissionSet refusedPermissions, System.Boolean isSynchronized) [0x00000] in :0

at System.AppDomain.DefineDynamicAssembly (System.Reflection.AssemblyName name, System.Reflection.Emit.AssemblyBuilderAccess access) [0x00000] in :0

at System.Xml.Serialization.TempAssembly.GenerateRefEmitAssembly (System.Xml.Serialization.Xml$$anonymous$$apping[] xml$$anonymous$$appings, System.Type[] types, System.String defaultNamespace, System.Security.Policy.Evidence evidence) [0x00000] in :0

at System.Xml.Serialization.TempAssembly..ctor (System.Xml.Serialization.Xml$$anonymous$$apping[] xml$$anonymous$$appings, System.Type[] types, System.String defaultNamespace, System.String location, System.Security.Policy.Evidence evidence) [0x00000] in :0

at System.Xml.Serialization.XmlSerializer.GenerateTempAssembly (System.Xml.Serialization.Xml$$anonymous$$apping xml$$anonymous$$apping, System.Type type, System.String defaultNamespace) [0x00000] in :0

at System.Xml.Serialization.XmlSerializer..ctor (System.Type type, System.String defaultNamespace) [0x00000] in :0

at X$$anonymous$$LOperations.Load[T] (System.String path) [0x00000] in :0

at WelcomeLayout.Start () [0x00000] in :0

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ben06feb · Jul 22, 2018 at 01:06 PM

I have switched the API compatibility level to .NET Standard 2.0 from 4.x, its working

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

118 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

XMLSerializer 0 Answers

Json Parsing iOS with depth of json is 6. 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Error while deserializing an xml file 2 Answers

[SOLVED] XML Deserialization of a single XML file into multiple objects 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges