Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I ran the build it was fine, but when i try to test in the emulator it throws an excetion stating

this "An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll but

was not handled in user code" what does this mean.
I have already 366 Devotion.json in MyDevotions folder located in my project
xaml.cs
C#
public partial class MainPage : PhoneApplicationPage
    {

        private List<devotion> devotions;

        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();

            // as this will be expensive to populate
            // you only want to do it once when the app starts
            devotions = new List<devotion>();
            AddDevotions();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            DateTime dt = DateTime.Now;
            int month = dt.Month;
            int year = dt.Year;
            int index;

            if (DateTime.IsLeapYear(year) || (month <= 2))
            {
                index = dt.DayOfYear - 1; // list is indexed from 0
            }
            else
            {
                index = dt.DayOfYear; // add a day
            }

            textblock.Text = devotions[index].Message; // or some other property
        }

        private void AddDevotions()
        {
            for (int i = 1; i <= 366; i++)
            {
                string filePath = "MyDevotions/Devotions" + i.ToString() + ".json";
                Devotion d = ReadJsonFile(filePath);
                devotions.Add(d);
            }
        }

        public Devotion ReadJsonFile(string JsonfilePath)
        {
            Devotion d = null;

            using (StreamReader r = new StreamReader(JsonfilePath))
            {
                string json = r.ReadToEnd();
                d = JsonConvert.DeserializeObject<devotion>(json);
            }
            return d;
        }

Thank you in advance and reply soon
Posted
Updated 19-Jan-15 0:38am
v2
Comments
[no name] 19-Jan-15 7:11am    
Have you checked for each and every iteration whether any file is missing or not?
Member 10627743 19-Jan-15 7:54am    
I corrected the file path it shows another error below

+ $exception {Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'DevotionJson.Devotion' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<t> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path '', line 1, position 1.
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureArrayContract(JsonReader reader, Type objectType, JsonContract contract)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
at DevotionJson.MainPage.ReadJsonFile(String JsonfilePath)
at DevotionJson.MainPage.AddDevotions()
at DevotionJson.MainPage..ctor()} System.Exception {Newtonsoft.Json.JsonSerializationException}

What is the solution to this
Member 10627743 20-Jan-15 9:27am    
Thank you i have fixed it
[no name] 20-Jan-15 23:14pm    
Excellent. Post your fix as a solution so that it will be helpful to others.
George Swan 19-Jan-15 7:34am    
It means that your app is requesting a file that cannot be found. It could be that the JsonfilePath string is not a valid filepath

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900