Wednesday, October 10, 2012

Password Hasher

Simple utility for those who want to hash their password on the basis of PBKDF2 algorithm. Link -> download

Tuesday, September 18, 2012

Missing an assembly reference....

Sometimes, while working in MS.NET you add the reference of the project or the assembly and when you build the solution you still get the following errors:
1. Error    507    Metadata file '..\bin\Debug\YYY.dll' could not be found.
2. Error    74    The type or namespace name 'XXX' does not exist in the namespace 'YYY' (are you missing an assembly reference?).

So just to avoid a lot of scratching your heads, the issue involved here is the mismatch of the target framework property of the dll or project for which the reference has been added:

 Solution: Select the project and Go to property page. On "Application" tab select the "Target Framework" as set in the calling project as shown in screenshot below:

HibernateException – A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance


I believe most of us have encountered this error while working with NHibernate. This error comes due to the way NHibernate works and the way we developers habitual of coding :) Doing retrieval and updation of a parent object in the same transaction confuses NHibernate about what to do with the 2 child collections available in the session for the updated parent object and thus this error is thrown. To explain further, let us take an example:

There is an object DOCUMENT with cascade="all-delete-orphan" settings with child collection of PARAGRAPH with one-to-many relationship between them.

If the parent is detached and is then updated then the following lines of code will work:
public void setParagraph(Set dSet)
{    
    this.paragraphs = dSet;

In case DOCUMENT is not fetched and updated in the same transaction then below code lines works:

public void setParagraph(Set<Paragraph> dSet)
{    
    // this.paragraphs = dSet; //This will override the set that Hibernate is tracking.
    this.paragraphs.Clear();
    this.paragraphs.Add(dSet);

}

Monday, August 20, 2012

NHibernate:Could not execute native bulk manipulation query...

While working on one of the project for fine tuning the NHibernate queries and functional flow I got to know about the error "could not execute native bulk manipulation query:"

To avoid this error one has to remember the following things:
  1. While executing tasks which requires bulk manipulation of data like update, delete, it is suggested to use the HQL instead of SQL.
  2. While using HQL be cautious to use the createQuery of NHibernate session.
  3. Do not forget to use the ExecuteUpdate();
Hope this will save your precious time for coding :)

Friday, August 17, 2012

Unable to automatically step into the server. The remote procedure could not be debugged. This usually indicates that debugging has not been enabled on the server


I was trying to step into a service using the nettcp remote client and trying to debug service functions however I keep on getting the message : "Unable to automatically step into the server. The remote procedure could not be debugged. This usually indicates that debugging has not been enabled on the server...."

Solution: Add the following entry in the service.exe.config and client config file within section:

Restart the service after adding this entry.
 


Wednesday, August 8, 2012

The .Net Framing mode being used is not supported by.....

We did install one service for exporting the document in different file formats. That service was working fine till the time the deployment wasn't messed up the deployment guy. Suddenly the following exception started coming from production:  
Exception Details: System.ServiceModel.ProtocolException: The .Net Framing mode being used is not supported by 'net.tcp://localhost:86/SomeService'. See the server logs for more details.

Solution: If you ever face such situation then it is advisable to please do check the parameter transferMode which shall have the same setting on the client and on the server side, which could be either transferMode="Streamed" or transferMode="Buffered"... and try again with that operation. It shall work.

Monday, August 6, 2012

The time allotted to this operation may have been a portion of a longer timeout. This may be because the service is still processing the operation or because the service was unable to send a reply message...

This request operation sent to net.tcp://XXX.XX.XX.XX:YY/Service did not receive a reply within the configured timeout (00:00:10). The time allotted to this operation may have been a portion of a longer timeout. This may be because the service is still processing the operation or because the service was unable to send a reply message. Please consider increasing the operation timeout (by casting the channel/proxy to IContextChannel and setting the OperationTimeout property) and ensure that the service is able to connect to the client....

There may be times when you might have received this kind of error in production environment. The reason as the problem states is some operation happening at the server side which is taking longer than expected. To solve this issue set the entries as follows (time set shall be in accordance with the specific requirement.)


closeTimeout="00:01:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
transactionFlow="false" transferMode="Streamed" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10" maxReceivedMessageSize="2147483647">

maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483647"  maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"
/>

Happy Coding!!!

Monday, July 23, 2012

Cannot create a service reference with namespace XXX becuase the name is already in use by an existing service reference, folder or file

If you get the above error when trying to add a WCF service reference that you have previously deleted then try:
  • deleting the Service References.DeviceService.Reference.cs.dll file you'll find under obj\Debug\TempPE. 
  • deleting the service folder you'll still find under Service References on disk, even though you deleted the reference in Visual Studio.
  • commenting out all references to the service's namespace in your code
  • rebuilding

Wednesday, July 18, 2012

Could not find default endpoint element that references contract...

I created a WCF service today after a long time and I hosted it using a Windows service. While doing so I created the wcf proxy client and its config settings were generated. Then I need to use this client in my web application to call the service methods to do some work. When I did that I got the error "Could not find default endpoint element that references contract....". 

Solution: To get this error resolved one has to add the section with all the contents from proxy's app.config file to the web.config file of the web application.

Wednesday, September 9, 2009

Abstract Class v/s Interface

While designing software systems we often come across the situation where we need to decide on having interfaces or abstract class. To help on this following are few points which can be think upon to arrive at an informed decision:

1. Interfaces are the contracts which contain the signature/declaration of the functions which are forced to be implemented by the deriving classes. Abstract class needs atleast one function that remains abstract and all other functions can be implemented in the abstract class itself.

2. Interfaces are strongly coupled design and abstract class provides more flexibility in terms of implementation. Abstract classes may also provide members that have already been implemented. Therefore, you can ensure a certain amount of identical functionality with an abstract class, but cannot with an interface.

3. You should use abstract class when there is certain implementation uncertain to its subclass and other part of the behavior is same for all of the subclass.

4. Abstract classes should be used primarily for objects that are closely related, whereas interfaces are best suited for providing common functionality to unrelated classes.

5. Abstract classes are helpful while designing large functional units and interfaces shall be used while designing small, concise bits of functionality.

6. In case the requirement is to provide common, implemented functionality across all implementations of your component, use abstract classes. Abstract classes allow you to partially implement your class, whereas interfaces contain no implementation for any members.