Monday, 1 April 2013

Cannot compare elements of type 'System.Collections.Generic.List

We may get an exception when we are working with lamda expression as follows.

Cannot compare elements of type 'System.Collections.Generic.List`1'. Only primitive types, enumeration types and entity types are supported.
The solution to resolve this issue is, make sure don't have any null condition checks in the where clause.

Sunday, 24 March 2013

Get Bin Directory Path using C# for web application as well as class library

We may get the requirement while coding in C# like we need to get the bin path  of class library or Web application.

the following is the sample code which works for class library as well as web application.

string binPath = Path.GetDirectoryName((new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).LocalPath)

Friday, 15 March 2013

Application pool always getting stopped

I have a problem like SecurityTokenServiceApplicationPool always getting stopped when I am opening Sharepoint manager 2013.
After research for this problem on google and gone through the EventViewer and found that this is the problem with the user credentials for the applicationpool running under the specified user. Password for my user got expired.

Solution: Make sure password for the user is correct and it is not expired. If it is expired please update with new password.

Monday, 24 December 2012

Xml Serialization Behavior

Xml Serializer behaves differently based on the datatype and the behaviour of the property(Nullable/Not Nullable). Some time we may get confusion on why the xml serializer throwing an exception. Find the below table contains when the xml serializer throws an exception or when the object is instantiated.


Data Type

Property Behavior

Tag removed

i:nil="true"

Empty Tag

Invalid Content

Comments

Int, decimal

Nullable

Null

Null

Exception

Exception

Not Nullable

0

Exception

Exception

Exception

DateTime

Nullable

Null

Null

Exception

Exception

DateTime should be the following format, otherwise throws an exception
1) yyyy-MM-ddTHH:mm:ss
2)yyyy-MM-dd
3)HH:mm:ss

Not Nullable

0001-01-01T00:00:00

Exception

Exception

Exception

Collections

-NA-

Initialized new object with collection count as zero

Initialized new object with collection count as zero

Initialized new object with collection count as zero

Initialized new object with collection count as zero

Decorate property with [XmlElement(IsNullable=true)] attribute to set the property as null instead of initializing new object

Csharp Object

-NA-

Null

Initialized to New Object

Initialized to New Object

Initialized to New Object

Decorate property with [XmlElement(IsNullable=true)] attribute to set the property as null instead of initializing new object

Enum

Nullable

Null

Null

Exception

Exception

Not Nullable

Initialized with firt enum element

Exception

Exception

Exception

Sunday, 30 September 2012

'Microsoft' is undefined

When I am trying to access the Windows Azure Mobile Services in the Windows 8 Metro App, I got the following exception.
0x800a1391 - JavaScript runtime error: 'Microsoft' is undefined windows azure mobile services
I searched the google to find the solution for this problem, but I did not found any solution. I tried many ways of referring script files. Finally I got the solution. The mistake what I did was only referring MobileSerivces.js in the groupedItems.html page where I am using grid layout in my metro application.

Solution:

Refer MobileServices.js in the default.html page as well.

Tuesday, 10 July 2012

Could not load type 'System.Web.Http.Dependencies.IDependencyScope'

I am working on one Asp.Net WebApi project along with 5 members in my team. We are using
Asp.net MVC4  Beta for the WebApi project. Everything is working for me fine. Suddenly one day I got the latest version of code from TFS and try to run the application. The solution build succeed, but the application throwing the following exception.
Could not load type 'System.Web.Http.Dependencies.IDependencyScope' from assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
The same application is running in my other teammates. I researched around one day, but did not found any solution that why this dll is not loading run time even though the dll is present in the bin folder.  One of my team mate told that Asp.Net MVC4 is updated from beta to release version. I updated that in my system then the application is working fine. There was mismatch in the team communicatin about this updatation I lost my one day. If any one get this exception try to update the WebApi to release candidate.

Tuesday, 5 June 2012

Date Comparision in Entity Framework

When we are writing linq expression in Entity framework as follows
context.GetQuery<TaxLocExtract>().Where(
tle => tle.EffectiveDate.Date == effectiveDate.Date).ToList();
then we will get the following exception
The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
the solution to resolve is System.Data.Objects.EntityFunctions.TruncateTime() is used. the sample query as follows.
context.GetQuery<TaxLocExtract>().Where(
tle => System.Data.Objects.EntityFunctions.TruncateTime(tle.EffectiveDate) == System.Data.Objects.EntityFunctions.TruncateTime(effectiveDate)).ToList();
I hope this solution helps.