- Home /
Getting a Build error for Windows Phone 8 Platform, It's working fine in PC
Error building Player: Exception: Error: method System.Void System.IO.File::AppendAllText(System.String,System.String)
doesn't exist in target framework. It is referenced from Assembly-CSharp.dll at System.Void CSVReader::SaveScoreToCsv(Score).
Error: method System.String[] System.IO.File::ReadAllLines(System.String)
doesn't exist in target framework. It is referenced from Assembly-CSharp.dll at System.Void CSVReader::ReadDescp(System.String).
Error: method System.String[] System.IO.File::ReadAllLines(System.String)
doesn't exist in target framework. It is referenced from Assembly-CSharp.dll at System.Void CSVReader::ReadGeneralSetting().
Code for CSVReader is as following::
using UnityEngine; using System.Collections; using System.Collections.Generic; using System.IO; using System.Text; using System; using System.Linq; using UnityEngine.UI;
public class CSVReader : MonoBehaviour { public TextAsset QuestionMSTxt; public TextAsset scoreSettingText;
public static GeneralSettings generalSettings;
string[] lines = null;
public static IList<MultipleQuestionAnswer> MCQList;
public static ScoreSettings scoreSettings;
public static GameDiscription GameDiscription;
public Text TitleText;
public Text DescriptionText;
public GameObject HomeScreen;
public GameObject UsernameInputContainer;
void Awake()
{
ReadGeneralSetting();
ReadGameDescription();
if (GameDiscription != null)
{
TitleText.text = GameDiscription.heading;
DescriptionText.text = GameDiscription.description;
}
}
void Start()
{
if (QuestionMSTxt != null)
{
ReadquestionnaireCSV(FindCSV("MSQuestions.csv", QuestionMSTxt));
}
if (scoreSettingText != null)
{
ReadScoreSettingsCSV(FindCSV("ScoreSettings.csv", scoreSettingText));
}
}
private string[] InitializeQuestions()
{
if (Application.platform == RuntimePlatform.WindowsPlayer)
{
int tmpIndex = Application.dataPath.LastIndexOf('/');
if (tmpIndex > 0)
{
string tmpPath = Application.dataPath.Substring(0, tmpIndex);
tmpPath += "/Configs/MSQuestions.csv";
if (File.Exists(tmpPath))
{
StreamReader sr = new StreamReader(File.OpenRead(tmpPath));
lines = sr.ReadToEnd().Split('\n');
sr.Close();
}
}
}
else
{
lines = QuestionMSTxt.text.Split('\n');
}
if (lines == null)
{
Debug.Log("Couldnt find Questionaire in EXE. Loading default");
lines = QuestionMSTxt.text.Split('\n');
}
return lines;
}
string[] FindCSV(string path, TextAsset asset)
{
if (Application.platform == RuntimePlatform.WindowsPlayer)
{
Debug.Log(" FIND CSV : " + path);
Debug.Log(generalSettings.configPath + path);
if (File.Exists(generalSettings.configPath + path))
{
Debug.Log("in general settings");
StreamReader sr = new StreamReader(File.OpenRead(generalSettings.configPath + path));
lines = sr.ReadToEnd().Split('\n');
sr.Close();
}
else
{
int tmpIndex = Application.dataPath.LastIndexOf('/');
string tmpPath = Application.dataPath.Substring(0, tmpIndex);
tmpPath += "/Configs/" + path;
Debug.Log(tmpPath + "in else");
if (File.Exists(tmpPath))
{
Debug.Log("in ifd;lakj");
StreamReader sr = new StreamReader(File.OpenRead(tmpPath));
lines = sr.ReadToEnd().Split('\n');
sr.Close();
}
}
}
else
{
lines = asset.text.Split('\n');
}
if (lines == null)
{
Debug.Log("Couldnt find File in EXE. Loading default");
lines = asset.text.Split('\n');
}
return lines;
}
void ReadScoreSettingsCSV(string[] data)
{
scoreSettings = new ScoreSettings();
List<string[]> stringData = new List<string[]>();
foreach (string s in data)
{
stringData.Add(s.Split(','));
}
int.TryParse(stringData[1][1], out scoreSettings.missionTimeScore);
int.TryParse(stringData[2][1], out scoreSettings.missionTimerScore);
int.TryParse(stringData[3][1], out scoreSettings.MapPuzzle);
int.TryParse(stringData[4][1], out scoreSettings.JigSawPuzzle);
int.TryParse(stringData[5][1], out scoreSettings.WindowsPuzzle);
int.TryParse(stringData[6][1], out scoreSettings.Questions);
}
private void ReadquestionnaireCSV(string[] data)
{
MCQList = new List<MultipleQuestionAnswer>();
for (int i = 1; i < data.Length; i++)
{
string[] fields = data[i].Split(',');
if (fields.Length <= 1)
{
}
else
{
MultipleQuestionAnswer _mtmp = new MultipleQuestionAnswer();
if (fields[0].Length > 0)
{
_mtmp.Question = fields[0];
_mtmp.Answer = new List<string>();
if (fields[1].Length > 0)
{
_mtmp.CorrectAnswer = fields[1];
for (int j = 1; j < fields.Length; j++)
{
_mtmp.Answer.Add(fields[j]);
}
MCQList.Add(_mtmp);
}
}
}
}
}
//TODO update score. Writing dummy value for now
public static void SaveScoreToCsv(Score scoreDetails)
{
var csv = new StringBuilder();
csv.AppendLine(scoreDetails.scoreBreakdown);
if (Application.platform == RuntimePlatform.WindowsPlayer)
{
string path = null;
if (!CSVReader.generalSettings.useLocal)
{
path = CSVReader.generalSettings.configPath + "/Scores.csv";
}
else
{
int tmpIndex = Application.dataPath.LastIndexOf('/');
string tmpPath = Application.dataPath.Substring(0, tmpIndex);
tmpPath += "/Configs/Scores.csv";
path = tmpPath;
}
try
{
File.AppendAllText(path, csv.ToString());
}
catch (Exception e)
{
Debug.Log("Error saving to scores");
}
}
}
public void ReadGameDescription()
{
if (Application.platform == RuntimePlatform.WindowsPlayer)
{
var tmpPath = generalSettings.configPath + "Description.txt";
if (File.Exists(tmpPath))
{
ReadDescp(tmpPath);
}
else
{
int tmpIndex = Application.dataPath.LastIndexOf('/');
tmpPath = Application.dataPath.Substring(0, tmpIndex);
tmpPath += "/Configs/Description.txt";
generalSettings.useLocal = true;
if(File.Exists(tmpPath))
ReadDescp(tmpPath);
}
}
}
void ReadDescp(string path) {
string[] descriptions = System.IO.File.ReadAllLines(path);
GameDiscription = new GameDiscription();
GameDiscription.heading = descriptions[0];
var totalDesc = "";
for (int i = 1; i < descriptions.Length; i++)
{
totalDesc += descriptions[i];
}
GameDiscription.description = totalDesc;
}
public void PlayBtnClicked()
{
HomeScreen.SetActive(false);
UsernameInputContainer.SetActive(true);
}
public void ReadGeneralSetting() {
if (Application.platform == RuntimePlatform.WindowsPlayer)
{
int tmpIndex = Application.dataPath.LastIndexOf('/');
if (tmpIndex > 0)
{
string tmpPath = Application.dataPath.Substring(0, tmpIndex);
tmpPath += "/Configs/Settings.csv";
if (File.Exists(tmpPath))
{
string[] descriptions = System.IO.File.ReadAllLines(tmpPath);
generalSettings = new GeneralSettings();
var desc = descriptions[0].Split(',');
int.TryParse(desc[1], out generalSettings.timeOut);
desc = descriptions[1].Split(',');
desc[1] = desc[1].Replace(@"\", "\\");
generalSettings.configPath = desc[1];
desc = descriptions[2].Split(',');
int.TryParse(desc[1], out generalSettings.lobbyWaitTime);
}
}
}
if (generalSettings == null)
{
generalSettings = new GeneralSettings();
generalSettings.timeOut = 60;
generalSettings.configPath = "/Configs/";
generalSettings.lobbyWaitTime = 100;
generalSettings.useLocal = true;
}
Debug.Log("Config Path: " + generalSettings.configPath);
}
} Thanks in advance Jash
Your answer
Follow this Question
Related Questions
Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers
Unity 5 Windows Phone 8.1 Build Error 0 Answers
XCode Swift Compiler Error Use of Unresolved Identifier "UnitySendMessage" how to fix? 2 Answers
How can I stop the variable values reverting to its default values after being built? 1 Answer