Archive

Archive for September, 2014

Stack overflow error while disposing object – C#

September 27, 2014 Leave a comment

I have a class “ABC” which implements “IDisposable” interface and having below Dispose method.

Public Class ABC : IDisposable {

public void Dispose()       {

this.Dispose(true);

}

}

When I run the application I was getting “Stack Overflow” error because the Dispose() method getting called recursively and went in to an infinite loop.

Fix :

  • Prevent the Dispose() recursive call by using flag and the logic is as below

 private bool disposed = false;

public void Dispose() {

this.Dispose(true);

GC.SuppressFinalize(this);

}

protected virtual void Dispose(bool disposing) {

if (this.disposed) {

return;

}

this.disposed = true;

}

🙂

Categories: Misc Tags: , ,

The security timestamp is invalid because its creation time is in the future – Error CRM

September 24, 2014 Leave a comment

I was getting below exception when I try to create records from my console application using CRM Organization Service.

The security timestamp is invalid because its creation time (2014-09-24T08:51:00.583Z) is in the future. Current time is 2014-09-24T08:45:58.432Z and allowed clock skew is 00:05:00].

Reason :

  • There was difference in Time settings between CRM Front end server and CRM DB Server.

Fix :

  • In our case CRM Front end server and CRM DB Server time zones were different.
  • Also sometimes check if the “Windows Time” service is running on machines. (To check go to Run -> Services.msc)
  • FYI, “Windows Time” service maintains date and time synchronization on all client and servers on the network.

Same scenario would sometimes cause below exception too

Message security verification failed

🙂

Make your WCF service’s Operation/Method Fire and Forget

September 10, 2014 Leave a comment

There are cases when an operation has no returned values and the client does not care about the success or failure of the invocation.

To support this sort of fire-and-forget invocation, WCF offers one-way operations.

It’s simple to implement. We just need to add “IsOneWay” property to ‘true’ to the [OperationContract] property.

[ServiceContract]

interface IWCFContract

{

[OperationContract(IsOneWay = true)]

void HelloWorld()

}

Note : The Operation Contract must have a “void” return type without any outgoing parameters.

Refer this article for more.

🙂

Categories: Misc Tags: , ,

HTTP Error 404.17 – hosting Service in IIS

September 6, 2014 Leave a comment

Recently when I hosted a web service project in IIS and browse that, I got below error.

HTTP Error 404.17 – Not Found

The requested content appears to be script and will not be served by the static file handler.

HTTP Error 404.17

HTTP Error 404.17

Fix :

  • In my case I missed a simple step, My Web service Application Pool set to .Net 2.0
  • Since I built web application .Net 4.0 framework, changing Application Pool .Net Framework to v4.0 solved my problem
Application Pool

Application Pool

Note :

  • Sometimes issue might caused by missing of ASP.Net framework.
  • So install ASP.Net framework by running aspnet_regiis.exe I command using Visual Studio Command Prompt.

🙂

Expecting element from namespace encountered with name namespace – Error DataContractSerializer

September 2, 2014 Leave a comment

I have a REST  enabled WCF service with Method GetFruits() which return list of Fruit objects serialized in XML format.

My ‘Fruit’ class defined as below

   [DataContract]

public class Fruit   {

string name = string.Empty;

[DataMember]

public string Name       {

get { return name; }

set { name = value; }

}

}

I built a Client Web application and try to execute the ‘GetFruits’ and get the Fruit collection.

I got the result XML but when I try to DeSerialize XML to List<Fruit> I got below error

Reason

  • Namespace of ‘Fruit’ class at Service and Client are not matching

Fix

  • Add ‘Namespace’ tag to ‘Fruit’ class in both Client & Server.

[DataContract(Namespace = “ABC”)]

public class Fruit

{}

Check Entities attribute type – CRM Late Binding

September 2, 2014 Leave a comment

Recently somebody posted a question in my blog, whether there is a way to determine the entities ‘Attribute Type’ instead of making Organization service call and read the metadata. 

Assume you have a Plug-in you made a ‘Retrieve’ call using Late Binding and, you got Entity object. 

Below is easy way to determine type of each attribute using ‘is’ operator.

Entity.Attributes[attributeName] is EntityReference

Or

Entity.Attributes[attributeName] is Money

Or

Entity.Attributes[attributeName] is OptionSetValue

🙂

Categories: CRM Tags: , ,