Friday, September 23, 2011

Check required fields in de-serialization of WCF objects

You can set IsRequired = True and EmitDefaultValue = False.

This will tell Wcf runtime to serialize data member but do not serialize default values, i.e. do not serialize null values for reference types, 0 for integers, etc.In effect, a runtime exception will be thrown if the data member has not been assign a value during serialization. If we do not set EmitDefaultValue toFalse CLR will set it to zero (default for integer) automatically.

Wednesday, July 6, 2011

Issues With File System Watcher And Large Amount of Files

File System Watcher notifies exactly at the moment when a file or directory is created, changed or deleted, without having to do polling on that directory.

But There is a problem when handling a large amount of files through the File System Watcher.
  • There is a fixed buffer allocated to each file system watcher (Default size of the buffer is 4 KB).
  • This Buffer is used to store the details such as file location for each file that raises an event.
  • When a large number of files raise an event then this buffer gets full.
  • So there is a possibility of missing some file information.
So the Solution for this problem is,
  • Do not write the proceeding logic in the handler instead the handler simply queues the file in a work queue.
  • Queue is processed by an entirely independent thread.
  • So the actual work done by the handler is just queuing and the control moves out of the handler thus releasing the buffer.
Code Example

  • In Main

  • Event Handler

  • Process




References :- http://csharp-codesamples.com/2009/02/file-system-watcher-and-large-file-volumes/

Unity configuration section with generic type

To use a Unity configuration section with generic types all you have to remember is the
` sign as the sign for a generic type in the configuration file.

  • Code


  • Configuration file



References :- http://stackoverflow.com/questions/3486837/unity-2-0-registering-generic-types-via-xml