search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Instance of JsonData can't be cast to String

Asked by Mobiz
11 years ago.

I implemented what u have done in MVC 3 Razor Event Calendar and SQL Server Tutorial (C# and VB.NET),but i am getting an error "Instance of JsonData can't be cast to String" . what is the reason for this.

I created a index.cshtml in 'cal' folder and in calcontroller i gave the actionresult for index. in calendarcontroller i implemented what all things that u have given(ie. backend,class dpc etc).

Pls give me a solution

Comment posted by the_muton
11 years ago.

Hi,
Same problem here : in a C#/ASP.NET (3.5) project, I use the Month Calendar, and when I focus an event (or when I click on it), I obtain an "InvalidCastException" in the file JsonData.cs :

public static explicit operator String (JsonData data)
{
if (data == null)
{
return null;
}

switch (data.type)
{
case JsonType.Int:
return data.inst_int.ToString();
case JsonType.Long:
return data.inst_long.ToString();
case JsonType.Double:
return data.inst_double.ToString();
case JsonType.String:
return data.inst_string;
case JsonType.Boolean:
return data.inst_boolean.ToString();
case JsonType.None:
case JsonType.Object:
case JsonType.Array:
default:
throw new InvalidCastException("Instance of JsonData can't be cast to String.");
}
}

because the JSon data parameter is an Array.

I get this error with the DayPilot 7.2.2765.0, and also in the DayPilot solution provided.
When I used the Demo version 7.1.2739.1 in my project, I didn't have the error...

Answer posted by the_muton
11 years ago.

Hi all,

I solved the issue here : I just added the line

case JsonType.Array:
return data[0].ToString ();
default:

at the end of the method, I regenerated the dll and it worked well...
Strange that this bug was in the latest version, and not before...

I hope this helped!

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.