Click here to Skip to main content
15,887,416 members
Home / Discussions / C#
   

C#

 
GeneralRe: [CAUSE]: Not Getting Proper Output From Compiled EXE File Pin
Wendelius18-Sep-15 21:31
mentorWendelius18-Sep-15 21:31 
GeneralRe: [CAUSE]: Not Getting Proper Output From Compiled EXE File Pin
Bastar Media18-Sep-15 21:41
Bastar Media18-Sep-15 21:41 
General[SOLVED]: Not Getting Proper Output From Compiled EXE File Pin
Bastar Media18-Sep-15 21:38
Bastar Media18-Sep-15 21:38 
GeneralRe: [SOLVED]: Not Getting Proper Output From Compiled EXE File Pin
Wendelius18-Sep-15 21:42
mentorWendelius18-Sep-15 21:42 
GeneralRe: [SOLVED]: Not Getting Proper Output From Compiled EXE File Pin
Bastar Media18-Sep-15 21:47
Bastar Media18-Sep-15 21:47 
QuestionNancyFx in OWIN and Windows Service host Pin
LIttle_Cat17-Sep-15 20:25
LIttle_Cat17-Sep-15 20:25 
AnswerRe: NancyFx in OWIN and Windows Service host Pin
Richard Andrew x6418-Sep-15 18:00
professionalRichard Andrew x6418-Sep-15 18:00 
QuestionREST Web API Query JSON Deserialization Pin
FMG Tech17-Sep-15 17:10
FMG Tech17-Sep-15 17:10 
Can someone please help explain this error I am receiving?

I am attempting to query a REST API Webservice
When I attempt to use Newtonsoft.Json.Linq

It is being called from a button click here is the following code used

private void SearchCmd_Click(object sender, EventArgs e)
    {
        try
        {
            myDataGrid.DataSource = GetRESTData("//private//");
        }
        catch (WebException webex)
        {
            MessageBox.Show("Exception Error Detected ({0})", webex.Message);
        }

    }


    private JArray GetRESTData(string uri)
    {
        {
            var wRequest = (HttpWebRequest)WebRequest.Create(uri);
            var wResponse = (HttpWebResponse)wRequest.GetResponse();
            var reader = new StreamReader(wResponse.GetResponseStream());
            string s = reader.ReadToEnd();
            serviceTagInput.Text = s;
            return JsonConvert.DeserializeObject<JArray>(s);
        }
    }



The error received is
The error throws InvalidCastException in NewtownSoft.Json.Dll

System.InvalidCastException was unhandled
HResult=-2147467262
Message=Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'Newtonsoft.Json.Linq.JArray'.
Source=Newtonsoft.Json
StackTrace:
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) in c:\Development\Releases\Json\Working\Newtonsoft.Json\Src\Newtonsoft.Json\JsonConvert.cs:line 805
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value) in c:\Development\Releases\Json\Working\Newtonsoft.Json\Src\Newtonsoft.Json\JsonConvert.cs:line 742
at DellWFApi.Form1.GetRESTData(String uri) in C:\Users\user\Documents\Visual Studio 2015\Projects\DellWFApi\DellWFApi\Form1.cs:line 55
at DellWFApi.Form1.dellSearchCmd_Click(Object sender, EventArgs e) in C:\Users\user\Documents\Visual Studio 2015\Projects\DellWFApi\DellWFApi\Form1.cs:line 37
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at DellWFApi.Program.Main() in C:\Users\user\Documents\Visual Studio 2015\Projects\DellWFApi\DellWFApi\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
AnswerRe: REST Web API Query JSON Deserialization Pin
Richard MacCutchan17-Sep-15 23:30
mveRichard MacCutchan17-Sep-15 23:30 
GeneralRe: REST Web API Query JSON Deserialization Pin
FMG Tech18-Sep-15 6:34
FMG Tech18-Sep-15 6:34 
GeneralRe: REST Web API Query JSON Deserialization Pin
Richard MacCutchan18-Sep-15 6:49
mveRichard MacCutchan18-Sep-15 6:49 
GeneralRe: REST Web API Query JSON Deserialization Pin
FMG Tech18-Sep-15 15:16
FMG Tech18-Sep-15 15:16 
QuestionEdit SVG text elements of XHTML page with C# Pin
Bartosz Jarmuż17-Sep-15 4:16
Bartosz Jarmuż17-Sep-15 4:16 
Questionc# RSA security Pin
Member 1198796116-Sep-15 20:11
Member 1198796116-Sep-15 20:11 
AnswerRe: c# RSA security Pin
Eddy Vluggen16-Sep-15 22:54
professionalEddy Vluggen16-Sep-15 22:54 
QuestionIn visual studio do you know what the name of this control ? Pin
Member 245846716-Sep-15 16:29
Member 245846716-Sep-15 16:29 
AnswerRe: In visual studio do you know what the name of this control ? Pin
Richard MacCutchan16-Sep-15 21:43
mveRichard MacCutchan16-Sep-15 21:43 
AnswerRe: In visual studio do you know what the name of this control ? Pin
Eddy Vluggen16-Sep-15 22:50
professionalEddy Vluggen16-Sep-15 22:50 
AnswerRe: In visual studio do you know what the name of this control ? Pin
BillWoodruff17-Sep-15 0:11
professionalBillWoodruff17-Sep-15 0:11 
GeneralRe: In visual studio do you know what the name of this control ? Pin
Member 245846717-Sep-15 23:26
Member 245846717-Sep-15 23:26 
AnswerRe: In visual studio do you know what the name of this control ? Pin
ngoj17-Sep-15 2:43
ngoj17-Sep-15 2:43 
GeneralRe: In visual studio do you know what the name of this control ? Pin
Pete O'Hanlon17-Sep-15 2:55
mvePete O'Hanlon17-Sep-15 2:55 
GeneralRe: In visual studio do you know what the name of this control ? Pin
ngoj17-Sep-15 3:14
ngoj17-Sep-15 3:14 
QuestionDeclarations using var Pin
JBHowl16-Sep-15 1:54
JBHowl16-Sep-15 1:54 
AnswerRe: Declarations using var Pin
Eddy Vluggen16-Sep-15 2:16
professionalEddy Vluggen16-Sep-15 2:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.