Out of Box Compile Run Time Fails Silverlight 5 VS2012

Jan 8, 2013 at 3:49 PM
Edited Jan 8, 2013 at 3:53 PM

I can't this to work under Silverlight 5;

I'm incorporating the source code into my solution as a silverlight project.

I can step through the Newtonsoft source but it conks out too deep for me.

 

I tried StreamReaders, TextReaders, LineReaders, StringReaders.

The problem is somewhere. Builds and Links just fine.

 

using System;
using System . Collections . Generic;
using System.Diagnostics;
using System . Linq;
using System . Net;
using System . Windows;
using System . Windows . Controls;
using System . Windows . Documents;
using System . Windows . Input;
using System . Windows . Media;
using System . Windows . Media . Animation;
using System . Windows . Shapes;
using System . IO;
using Newtonsoft . Json . Linq;
using Newtonsoft . Json . Converters;
using Newtonsoft . Json . Schema;

namespace SilverlightApplication5
    {
    public partial class MainPage : UserControl
        {
        public MainPage ( )
            {
            InitializeComponent ( );
            }
        private string samplePath=@"C:\Users\karron\Documents\Visual Studio 11\Projects\SilverlightApplication5\SilverlightApplication5\test.json";
        private String ChromePreferencesPath=@"C:\Users\karron\AppData\Local\Google\Chrome\User Data\Default\Preferences";
        private String LocalChromePreferencesPath=@"C:\Users\karron\Documents\Visual Studio 11\Projects\SilverlightApplication5\SilverlightApplication5\Default\Preferences";
        private void Button_Click_1 ( object sender , RoutedEventArgs e )
            {
            #region BUGEROOS
            Debug .WriteLine("{0}", ChromePreferencesPath);
#if SILVERLIGHT
            Debug . WriteLine ( "compiled with {0} defined" , "SILVERLIGHT" );
#endif
#if DEBUG
            Debug . WriteLine ( "compiled with {0} defined" , "DEBUG" );
#endif
#if TRACE
            Debug . WriteLine ( "compiled with {0} defined" , "TRACE" );
#endif
            #endregion
            if ( Application . Current . HasElevatedPermissions == false )
                {
                Debug.WriteLine("no permission elevation");
                return;
                }
            if ( Application . Current . IsRunningOutOfBrowser == false )
                {
                Debug . WriteLine ( "should be out of browser" );
                return;
                }
            //Stream FS = File . Open ( ChromePreferencesPath , FileMode . Open );
            Stream FS = File . Open ( samplePath , FileMode . Open );
            StreamReader SR = new StreamReader(FS);
            String AllLines= SR . ReadToEnd ( ) ;
            String[] EachLine = AllLines . Split ( '\n' );
            //StringReader sR=new StringReader(AllLines);


            List<string> list = Newtonsoft . Json . JsonConvert . DeserializeObject<List<string>> ( SR.Read().ToString() );

            foreach ( string item in list )
                {
                Console . WriteLine ( item );
                }

            

            SR.Close();
            FS.Close();
            }
        }
    }

 

Stepping into

DeserializeObject
causes all sorts of exceptions.

I'm abandoning this project to read and set Chrome/Chromium
Preferences JASON file until I can get this running OOB. I have
not tested Silverlight 4 or .net 4.5.  I gave it a small test file 
appended.

 

compiled with SILVERLIGHT definedcompiled with DEBUG definedcompiled with TRACE definedA first chance exception of type 'System.InvalidOperationException' occurred in Newtonsoft.JsonA first chance exception of type 'System.ArgumentException' occurred in Newtonsoft.JsonA first chance exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.JsonA first chance exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.JsonStep into: Stepping over method without symbols 'MS.Internal.JoltHelper.FireEvent'

 

{
    root: [
        {
            "__type": "BannerElement",
            "Id": 1,
            "Title": "Politics",
            "Text": "Some Text",
            "ImageFile": "/Religion-in-Politics--DM1.1.jpg",
            "ReadMoreUrl": "http://google.com",
            "SortOrder": 0,
            "Disabled": false
        },
        {
            "__type": "BannerElement",
            "Id": 2,
            "Title": "God",
            "Text": "Some Text",
             "ImageFile": "/Religion-in-Politics--DM1.1.jpg",
            "ReadMoreUrl": "http://google.com",         
            "SortOrder": 1,
            "Disabled": false
        }
    ]
}
Dec 3, 2013 at 7:37 PM
Edited Dec 3, 2013 at 7:40 PM
I am having a similar problem.

I used "Manage NuGet Packages" from the right click context menu of my VS2010 project.
The Package manager states the package is installed and the packages.config file contains:
<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Newtonsoft.Json" version="5.0.8" targetFramework="sl50" />
</packages>
But when I compile the following code:
using System;
using System.Runtime.CompilerServices;
using TypeSafeEnumeration.Serialization;
using Newtonsoft.Json;

[assembly: InternalsVisibleTo("Newtonsoft.Json.Silverlight, PublicKey=002400000480000094000000060200000024000052534131000400000100010087da393a57d74c3aa82fedc3140ae7be9fa8d33ecbbb3554cb9e1a81cad162316cc8f1db3e7d897de2e43f82bd7a598b78c27534fa02b2cbae8070e2d66059c42dfb26705d1f310076130ef55fe148c3590b0e5f7652ccc6c56c749aee15fd7960d5070f2f65a910277ec676bb571a9a278d6c04f5850f78b5bc99ac22f0ecbe, AllInternalsVisible = true")]
[assembly: InternalsVisibleTo("Newtonsoft.Json.Net35,       PublicKey=002400000480000094000000060200000024000052534131000400000100010087da393a57d74c3aa82fedc3140ae7be9fa8d33ecbbb3554cb9e1a81cad162316cc8f1db3e7d897de2e43f82bd7a598b78c27534fa02b2cbae8070e2d66059c42dfb26705d1f310076130ef55fe148c3590b0e5f7652ccc6c56c749aee15fd7960d5070f2f65a910277ec676bb571a9a278d6c04f5850f78b5bc99ac22f0ecbe, AllInternalsVisible = true")]

namespace TypeSafeEnumeration
{
  [JsonConverter(typeof(JsonDotNetSerializer))]
  public partial class Enumeration<T>
  {
    /// <summary>
.
.
.
}
Visual Studio Intellisense tells me that:
Newtonsoft.Json;
is unresolved and I (as you would expect) get a compilation error of:
Error   2
The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
C:\CognexWorkSpace\TAF_Tools\src\TypeSafeEnumeration.Common\Enumeration.Serialization.cs
I don't have any problems with the NuGet Managed references for any of my .NET 3.5 projects that are within the same solution.

Does the reference in packages.config need to be something different or is the name space for the silverlight project need to be something other than Newtonsoft.Json?