Archive for the ‘ASP.NET’ Category

Misleading exception with .NET DataContractJsonSerializer() – A bug reported to

December 3, 2013
Please find below the complete text from
Note: Just copy pasted ¬†as is, so that you may not be finding formatted nicely. ūüôā
I was working for serializing C# object into JSON using DataContractJsonSerializer(). Whenever the KnownType in not specified in the base class or passed into the constructor of DataContractJsonSerializer(), I have got the following exception.[Exception]
An unhandled exception of type ‘System.Runtime.Serialization.SerializationException’ occurred in System.Runtime.Serialization.dllAdditional information: Type ‘DerivedClasses.CustomerResponse’ with data contract name ‘CustomerResponse:’ is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types – for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.


Visual Studio/Visual Studio Online/Team Foundation Server/.NET Framework Tooling Version

.NET Framework 4.5.1

What category (if any) best represents this feedback?


Steps to reproduce

1). Have a base class and derived class
2). Don’t mark the base class with [KnownType] attribute
3). Populate derived object with required data
4). Try serializing derived object to JSON using DataContractJsonSerializer(), by passing the typeof(base class)

Product Language


Operating System

Windows 7

Operating System Language


Actual results

Issues with the exception:The exception what we are getting is as same as for “DataContractSerializer”.

So, this exception message is misleading by saying
1). “Consider using a DataContractResolver”, though DataContractJsonSerializer() is not supporting DataContractResolver.
2). or by adding them to the list of known types passed to “DataContractSerializer”

Expected results

The above two points in “Actual results” section needs to be removed from the exception and to be corrected with specific to “DataContractJsonSerializer”.


English Connect
Posted by laks_win on 12/2/2013 at 10:49 AM

Hi Team,I have got one more issue on the same Misleading exception with DataContractJsonSerializer() for passing the object which has “Cyclic References”. Actually DataContractJsonSerializer() doesn’t support it, but shows the exception that is specific to DataContractSerializer(). So, please have a check for this issue too.

Thanks and regards

Posted by Microsoft on 11/8/2013 at 2:39 PM

Hi Laks_win.Thank you for the feedback on WCF. This is a good suggestion and we will consider this for a future release.

Erica Mohler
Microsoft Program Manager

Posted by Microsoft on 10/29/2013 at 4:04 AM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by laks_win on 10/24/2013 at 9:54 PM
Thanks for the follow up. Just uploaded a newly created sample zip, its for your kind perusal.
Posted by Microsoft on 10/24/2013 at 6:22 AM

Thank you for submitting feedback on Visual Studio and .NET Framework. In order to efficiently investigate and reproduce this issue, we are requesting additional information outlined below.Could you please give us a demo project to demonstrate this issue so that we can conduct further research?

We look forward to hearing from you with this information.

Posted by Microsoft on 10/23/2013 at 10:50 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(

VS.NET 2013 and ASP.NET MVC 5!

July 14, 2013

Hello friends, ASP.NET MVC 5 has been bundled with VS.NET 2013 preview release. Here are few links for your reference.

VS.NET 2013:

The below url has the fantastic list of information about ASP.NET and Web Tools for Visual Studio 2013 Preview as well as the updated ASP.NET and Web Tools. Enjoy reading!


Tutorial available for Getting Started with ASP.NET MVC 5.

The ASP.NET MVC Framework is an open source web application framework that implements the model‚Äďview‚Äďcontroller (MVC) pattern.

As of now, the download is available for MVC 4 only.

Just a pointer to the title related information. ūüôā

VS.NET 2012’s new features in “MVC 4, Razor v2”

August 24, 2012

Here are two cool enhancement in Razor v2! Enjoy reading!!

1. No need to use “@href” or “@url.content” anymore for resolving the Url. We can simply use “~” as we use it in ASP.NET development

< script src=”@Url.Content(“~/Scripts/jGrowl.js”)”>

can be just simply as below
< script src=”~/Scripts/jGrowl.js”>

Note: <space> has been added after “<” in < script> for the perfect view

2. Conditional attributes:

Please refer:

Features in Visual Studio 2012 and ASPNET 4.5‚ÄĚ Free E-book

August 4, 2012

There is an E-Book available for download in Telerik’s website.¬†This e-book contains an overview of the features that would help great you as a developer :).

So, what is in this e-book you ask? Well…..

  • JavaScript Intellisense
  • CSS Intellisense
  • ASP.NET and Web API (overview and CRUD operations)
  • Strongly Typed Data Binding
  • Page Inspector (new debugging tool)
  • Etc

Here you go…

Free E-book: Time-Saving VS11 and ASP.NET 4.5 Features You¬†Shouldn’t¬†Miss

Pagination / Sorting not works in Custombinding enabled Telerik mvc grid ( v 2011.2.712 ) !

September 19, 2011

I experienced this issue in my development and lost some time figuring out!

Problem description:

Let‚Äôs say I have start date & end date and go button for the search and the search result will get displayed in the MVC grid. If I fire rebinding from JavaScript with both the date values, the grid would populate fine. But if I go for sorting/pagination, the “gridcommand” object holds only pagesize and pageno and misses the filter values for start & end date and grid goes with the default data population. But it worked fine with the previous version 2010.3.1318.

The solution is here:

‚ÄúThe additional parameter values passed through Grid’s client-side rebind method are not presisted on subsequent rebinds‚ÄĚ

In previous version, as a side effect of another issue, when additional value is passed through the rebind client-side method, it was persisted during the subsequent rebinds. In order to achieve same behavior with current version, the DataBinding event should be use to re-assign the value.

Here you go for the examples:

Hope, it helped!

ASP.NET MVC 4 Preview Released

September 18, 2011

Hope, the following notes and links would help great!

It installs side-by-side with ASP.NET MVC 3, so get started using it today!

Top Features

  • Refreshed and modernized default project templates
  • New mobile project template
  • Many new features to support mobile apps
  • Recipes to customize code generation
  • Enhanced support for asynchronous methods
  • Read the full feature list in the release notes

Software Requirements

The ASP.NET MVC 4 runtime components require the .NET Framework 4. The ASP.NET MVC 4 components for Visual Studio require either Visual Studio 2010 with Service Pack 1 or Visual Web Developer Express 2010 with Service Pack 1.

For reference:

Glimpse, debugging server from client side!

June 28, 2011

What is Glimpse (= a glance)?

At its core Glimpse allows you to debug your web site or web service right in the browser. Glimpse allows you to “Glimpse” into what’s going on in your web server. In other words what Firebug is to debugging your client side code, Glimpse is to debugging your server within the client.

“What Firebug is for the client, Glimpse does for the server… in other words, a client side Glimpse into whats going on in your server.”

Plugins available for Winforms & MVC:

WebForms MVC
  • Config – Summary of important stuff in your web.config
  • Environment – Details of the server environment
  • Request – What the server received in the request
  • Server – Web server variables available for the request
  • Session – Is using session, what is being stored
  • Trace – Trace output for the request
  • Bindings – How MVC is binding the data
  • Execution – What the execution pipeline looks like
  • MetaData – MetaData associated with your View Model
  • Routes – How routes are being evaluated
  • Views – How MVC is finding the view that is being rendered

Steps to install & use:

Sample firebug like window:

Hope, you would enjoy reading!

NULL check results differently in LINQ To SQL (L2S) and LINQ To EF (L2E)

February 14, 2011

Here are some interesting gotchas i would like to share that are all confirmed with @jimwooley and @julielerman

As i learnt that L2S & L2E uses different parser to generate the TSQL, thought of checking them mainly with “null” in SELECT & WHERE clause respectively. Surprisingly, i got great differences and listed them here.


I have used Table ‚ÄúOrders‚ÄĚ from DB NorthWind

Example: var result = from ord in Orders select ord.ShipRegion;

In SELECT statement

LINQ SQL Equivalent
select ord.ShipRegion ?? “Lara” SELECT COALESCE([t0].[ShipRegion],@p0) AS [value]
select ord.ShipName == null ? “Lara” : ord.ShipName SELECT (CASEWHEN [t0].[ShipName] IS NULL THEN CONVERT(NVarChar(40),@p0) ELSE [t0].[ShipName] END) AS [value]
select Object.Equals(ord.ShipRegion, “Lara”) SELECT (CASEWHEN ([t0].[ShipRegion] IS NOT NULL) AND ([t0].[ShipRegion] = @p0) THEN 1 WHEN NOT (([t0].[ShipRegion] IS NOT NULL) AND ([t0].[ShipRegion] = @p0)) THEN 0 ELSE NULL END) AS [value]
select Object.Equals(ord.ShipRegion, null) SELECT (CASEWHEN [t0].[ShipRegion] IS NULL THEN 1 ELSE 0 END) AS [value]

In WHERE condition

LINQ SQL Equivalent
where Object.Equals(ord.ShipRegion, null) WHERE [t0].[ShipRegion] IS NULL
where Object.Equals(ord.ShipRegion, “Lara”) WHERE ([t0].[ShipRegion] IS NOT NULL) AND ([t0].[ShipRegion] = @p0)
where String.Equals(or.ShipRegion, “Lara”) WHERE ([t0].[ShipRegion] IS NOT NULL) AND ([t0].[ShipRegion] = @p0)
where ord.ShipRegion == (ord.ShipRegion ?? “Lara”) WHERE [t0].[ShipRegion] = (COALESCE([t0].[ShipRegion],@p0))
where ord.ShipRegion == (ord.ShipRegion == null ? “Lara” : ord.ShipRegion) WHERE [t0].[ShipRegion] = ((CASE WHEN [t0].[ShipRegion] IS NULL THEN CONVERT(NVarChar(15),@p0) ELSE [t0].[ShipRegion] END))

Note: DECLARE @p0 NVarChar(1000) = ‘Lara’ Gotchas:

  • ?? => COALESCE()
  • ? => CASE WHEN‚Ķ.END

LINQ To Entity Framework

Used a custom table: Vendor

In SELECT statement

· select (re.VendorName ?? null);
· select (re.VendorName == null ? 
"N/A" : re.VendorName);
SELECT [Extent1].[VendorName] AS [VendorName]
select (re.VendorName.Length > 0 ? 
re.VendorName : "N/A");
SELECT CASE WHEN ((LEN([Extent1].[VendorName])) > 0) THEN [Extent1].[VendorName] ELSE N’N/A’ END AS [C1]

In WHERE condition

DateTime? dt = null; 

where DateTime.Equals(res.UpdatedDateTime, dt)

  • If dt is ‚Äúnull‚ÄĚ

WHERE [Extent1].[UpdatedDateTime] IS NULL

  • If dt is ‚Äúnot null‚ÄĚ, the following exception for all primitive types:

Unable to cast the type ‘System.Nullable`1’ to type ‘System.Object’. LINQ to Entities only supports casting Entity Data Model primitive types.

String defaultVal = null;


where Object.Equals(re.VendorName, defaultVal)
WHERE [Extent1].[VendorName] = @p__linq__0
· from re in obj.Vendors
  where Object.Equals(re.VendorName, null)
      select re.VendorId;

· from re in obj.Vendors
  where (re.VendorName.Equals(null))
       select re. VendorId;
If we keep ‚Äúnull‚ÄĚ directly, then the following weird TSQL for both the LINQ: SELECT CAST(NULL AS int) AS [C1] FROM¬† ( SELECT 1 AS X ) AS [SingleRowTable1] WHERE 1 = 0
where re.VendorName.Equals(null) || re.VendorId > 0
Consider only VendorId and ignore the other ūüė¶ WHERE [Extent1].[VendorId] > 0
where (!re.VendorName.Equals(null))
Ignores WHERE keyword in TSQL generation ūüė¶
· where (re.UpdatedDateTime == 
(re.UpdatedDateTime ?? dt))

· where (re.UpdatedDateTime == 
(re.UpdatedDateTime == null ? 
dt : re.UpdatedDateTime))
WHERE [Extent1].[UpdatedDateTime] = (CASE WHEN ([Extent1].[UpdatedDateTime] IS NULL) THEN @p__linq__0 ELSE [Extent1].[UpdatedDateTime] END)


  • For both ?? and¬†? => CASE WHEN‚Ķ.END in “where” clause only, but ignored in “select” clause
  • Weird TSQL equivalent with .Equals(null)

If anybody has any special thoughts, please comment ūüôā

MVC 3 View engine Razor and comparision!

February 7, 2011

Benefits over Razor are

  1. Can be hosted outside ASP.NET
  2. Can unit test views (no need of controller or web-server)
  3. Better intellesense support on VS.NET
  4. Everything is encoded by default
  5. Executing it from a console app is possible
  6. Much cleaner
  7. There’s no need to specify the language, because it’s included in the extension
  8. No need to explicitly specify a master page
  9. No external dependencies as it has been shipped with MVC 3 (System.Web.Mvc.dll)
  10. and lot more

Below are the urls you could enjoy reading over the major 4 view engines, it’s awesome. Just including here as it would help some one over there.


Asp.Net MVC project ‚ÄúThe project type is not supported by this installation‚ÄĚ

February 7, 2011

One of my team members experienced this issue and was trying all the tricks got from googling, but those are all did not helped him great. After some time, we got a clue from one of the tips and verified System.Web.Mvc version in the project file.

<Reference Include=”System.Web.Mvc, Version=,‚Ķ>

We use VS.NET 2010. He had only System.Web.MVC 2.0 installed in his machine but the above entry was showing version 3.0. Then right away we installed MVC 3.0 and tried opening the solution. Wow…it’s worked like a charm.

Hence, if you see System.Web.Mvc Version=, make sure you have MVC 2.0 installed. Likewise if see Version=, make sure MVC 3.0 installed. That‚Äôs it ¬†ūüôā