Misleading exception with .NET DataContractJsonSerializer() – A bug reported to http://connect.microsoft.com/

December 3, 2013
Please find below the complete text from connect.microsoft:
Note: Just copy pasted ¬†as is, so that you may not be finding formatted nicely. ūüôā
Description
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:http://schemas.datacontract.org/2004/07/DerivedClasses’ 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.
[/Exception]

Details

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?

Compatibility

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

English

Operating System

Windows 7

Operating System Language

English

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”.

Locale

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
Lakshminarayanan.R

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.

Thanks,
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(http://support.microsoft.com)
Advertisements

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!

http://www.asp.net/vnext/overview/latest/release-notes#TOC10

ASP.NET MVC 5:

Tutorial available for Getting Started with ASP.NET MVC 5.
http://www.asp.net/mvc/tutorials/mvc-5/introduction/getting-started

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

http://aspnet.codeplex.com/wikipage?title=MVC

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

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

2012 in review – My WordPress posts!

December 31, 2012

The WordPress.com stats helper monkeys prepared a 2012 annual report for this blog.

Here’s an excerpt:

600 people reached the top of Mt. Everest in 2012. This blog got about 10,000 views in 2012. If every person who reached the top of Mt. Everest viewed this blog, it would have taken 17 years to get that many views.

Click here to see the complete report.

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

Example:
< 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: http://vibrantcode.com/blog/2012/4/10/whats-new-in-razor-v2.html/

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

Daily life – The real fact!

August 4, 2012

Daily life - The real fact!

RowID or RowNumber for each rows in SQLServer!

April 15, 2012

Yesterday when I¬†was interviewing candidates for one of our requirement, I asked a simple select query to write that “how to get, only the last two rows of an Employee table?”

The answer were ( only from few ūüė¶ ) : SELECT TOP 2 * FROM Employee ORDER BY EmployeeId DESC (Provided EmployeeId INT, PrimaryKey)

Then, just i altered the question with “we don’t have an “INT” datatype for EmployeeId column, but¬†UniqueIdentifier (GUID) as well, so now how would you get the last 2 rows?

Some of them were tried to use ROW_NUMBER(), but as that requires OVER(ORDER BY <Column> DESC), and the primary key is with GUID, so they got blocked!

But here is one solution I had, and with that I was asking them: ūüôā

SELECT TOP 2 *, %%physloc%% AS PhysLoc FROM Employee ORDER BY PhysLoc DESC

Ref:

http://www.codeproject.com/Articles/159785/Physical-location-of-a-row-in-SQL-Server

 

DENALI (SQLServer 2012):

The special thing is that, we have got the cool and long waiting stuff ¬†“SEQUENCE” in DENALI as it is in ORACLE. That helps great for the above question, with the elegant solution.

Here you go…

CREATE SEQUENCE RowId
    AS int
    START WITH 1
    INCREMENT BY 1 ;

SELECT TOP 2 *, NEXT VALUE FOR RowId AS NewId FROM Employee ORDER BY NewId DESC

Ref:

http://www.sqlservercentral.com/articles/sequence/88422/

http://msdn.microsoft.com/en-us/library/ff878058(v=sql.110).aspx

 

Hope this helps!

Focus

April 13, 2012

Delete a TFS task

April 13, 2012

Simply i was trying to create a sample task in TFS, its done successfully. Then tried to delete from there as it is a live one , and everybody would be looking into it. But, searching the options in TFS for long, i felt tired and¬†nervousness. Finally, started googling and got few forums with no direct stuffs told. So thought of giving the stuff simple and humble ūüôā

First of all, we need the exe file Witadmin.exe for deleting the tasks in TFS.

Where it resides? Р C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE  (you have to check the folder, depending upon the system type you have)

Initially, I was searching underneath C:\Program Files (x86)\Microsoft Team Foundation Server 2010 Power Tools, and got confused.

Here is the list of available commands with Witadmin:

Possible options:

So, finally, your command would look like…

>witadmin destroywi /Collection:http://%5BServerName%5D:8080/tfs/id:%5BId%5D

Note: Text kept inside “[]” differs as its provided to you. Also provided the permission to delete ūüėČ

Hope, this helps! ūüôā

Error ‚ÄúNo Transport‚ÄĚ Calling WCF REST action using jQuery

January 8, 2012

This issue has eaten up some of my time, trying myself to figure it out for the solution. Because, the following snippet worked great in FireFox. Only the boss “IE” was the killer there :).

var¬†url¬†=¬†‘http://localhost:35461/SampleApp.svc/get/Do/123;&#8217;;

        $.ajax({
            url: url,
            dataType: 'json',
            type: "GET",
            error: function (xhr, ajaxOptions, thrownError) {
                //debugger;
                $('#GetDiv').html("error");
            },
            success: function (model) {
                //debugger;
                $("#GetDiv").html(model.Echo);
            }
        });

Finally, after a bit of googling, I have got some references, that helped great.

Gotchas:

“…..We need to enable¬†cross-domain requests in environments that do not support….”

Cors¬†is equal to true if a browser can create an¬†XMLHttpRequest¬†object and if thatXMLHttpRequest¬†object has a¬†withCredentials¬†property. To enable cross-domain requests in environments that do not support cors yet but do allow cross-domain¬†XHRrequests (windows gadget, etc), set¬†$.support.cors = true;”

Hence, the solution is……..

Add the following, in your client. It works like a charm.
jQuery.support.cors = true;

[Cors – Cross-Origin Resource Sharing]

There were some references to use dataType: ‘jsonp’, but that is a different story. I will write some later, what needs to be done if we say dataType: ‘jsonp’

Hope this helps someone…!