- Home /
Problem syntax C# => JS
Hello,
I have this code in C# :
 public static void Main(string[] args)
 {
     XmlSerializer deserializer = new XmlSerializer(typeof(Address));
     TextReader reader = new StreamReader(@"D:\myXml.xml");
     object obj = deserializer.Deserialize(reader);
     Address XmlData = (Address)obj;
     reader.Close();
 }
And i made it in JS :
 public static function Main(args :String) {
     var deserializer : XmlSerializer = new XmlSerializer(typeof(Adress));     
     var reader : TextReader = new StreamReader(Application.dataPath +"XML.xml");     
     var obj : object = deserializer.Deserialize(reader);
     var XmlData : Address =(Address)obj;     
     reader.Close(); 
 }
But this ligne give me an error:
 var XmlData : Address = (Address)obj;
Assets/Script/Adress.js(18,50): UCE0001: ';' expected. Insert a semicolon at the end.
I don't understand why, please someone for help me ?
Will something change if you declare var XmlData : Adress; on one line and assign its value on another line ins$$anonymous$$d of doing it all in one line?
@ZyTr0N, youre right, the unity script is called Adress.js and if the class wasn't specified, it would generate out to a type called Adress, plus you can see where deserializer is declared it uses Adress and not Address.
Thank you ! But have new problem now,
Assets/Address.js(17,27): BCE0018: The name 'object' does not denote a valid type ('not found'). Did you mean 'UnityEditorInternal.Object$$anonymous$$emoryInfo'?
 import System.Collections.Generic;
 import System.Xml;
 import System.IO;
 import System.Xml.Serialization;
 
 
 public class Address
 {
     public var HouseNo : int;
     public var StreetName : String;
     public var City : String;
     
     public static function $$anonymous$$ain(args : String)
     {
     var deserializer : XmlSerializer = new XmlSerializer(typeof(Address));
         var reader : TextReader = new StreamReader(Application.dataPath + "X$$anonymous$$L.xml");
         var obj : object = deserializer.Deserialize(reader);
         var XmlData : Address;
         XmlData = obj as Address;
         reader.Close();
     }
 }
Your answer
 
 
             Follow this Question
Related Questions
Stuff-is-going-wacky! Checklist - Compiler-Errors, Syntax-Errors 5 Answers
Error: Cannot cast from source type to destination type 2 Answers
Error CS8025? 1 Answer
How Do I deActivate One Sphere ? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                