Sunday, November 14, 2010

iPhone Button for Navigation Bar

If you are developing iPhone application and trying to use UIButton on ‘Navigation Bar’ instead of ' ‘difficult to use’ ‘Bar Button Item’, you need a button image that exactly looks like Bar Button.

As I couldn’t find the button background on net, I created it myself using Paint.NET. Here it is for  you.


Sunday, August 08, 2010

What are Characteristics of Successful Innovative Idea

I’ve been associate with an Innovation Lab from quite a some time and observing for life how a genuine ideas turn into a success. Though I’ve never been able to own a killer existing idea, I can still depict some characteristics of successful innovative idea (based on guts but without example or stories - bad bad to convince people).

  • Idea that solve problem for many.
  • Idea that have feasibility to be prototyped.  Idea that can be prototyped in short duration.
  • Idea that reasons (in term of Math, Science AND Art) why the idea can be successful. Idea should reference similar success.
  • Idea that is inline with what your associated firm is trying to do.

Wednesday, July 21, 2010

Concatenation of Styles in WPF

In order to avoid confusion and/or be inline with OOP concepts, WPF style will not allow you to concatenate multiple style in one control. Instead, you can use ‘BasedOn’ property (of Style element) to inherit from the other style. It is possible to create chain of inheritance but multiple inheritance is not supported by default. Initially I though it is not possible  until I came across this amazing link:

It shows use of MarkupExtension to enable inheritance from multiple styles (in actual, your triggers and setters will be merged. Duplicates will be overwritten by the second style that you define)

Happy interfacing!

Monday, June 21, 2010

Solve “You are not allowed to upload ‘FileName’. the requested file type: 'FileType’” problem on Vanilla Forum 1.x


You get this exception when you try to upload any file in your Vanilla Forum (Version 1) using any Attachment extension :
You are not allowed to upload ‘FileName’. the requested file type: 'FileType’

Resolution 1:

Add specified type as allowed type. Steps to do so follow here:

  1. Note the 'FileType’ in the error message.
  2. Go to extensions\Attachments\default.php file in your Vanilla forum’s directory.
  3. Add appropriate entry in Context->Configuration['ATTACHMENTS_ALLOWED_FILETYPES'] list.
  4. Note that it’s also important that you give correct extensions for the mime type you are allowing as both, 'FilteType’ (i.e. mime type) and file extensions are corss checked in Framework code of vanilla forum.
  5. Save the file and test.

Resolution 2:

Remove check for allowed types. Note that this is not very safe for public forum but it’s ‘ok’ for internal forum with known and responsible user. Steps to do so follow here:

  1. Go to “library\Framework\Framework.Class.Uploader.php”  file.
  2. Find this line of code “if (!array_key_exists($FileType, $this->AllowedFileTypes))”  and comment this ‘if’ and ‘else’ of it. Yes you need to comment if AND else.
  3. Save the file and test.

Thursday, April 15, 2010

Solve Exception Message: The IAsyncResult object was not returned from the corresponding asynchronous method on this class

Recently I was got a weird error on my Windows CE code (.NET compact framework) which was asynchronously listening for UDP (or may be same for TCP) messages.

Exception Message

Error Message: The IAsyncResult object was not returned from the corresponding asynchronous method on this class.
CallStack for debug purpose:
    at System.Net.Sockets.Socket.EndReceiveFrom()
    at BallyTech.SocketListener.UdpSocketListener.OnReceive()
    at System.Net.LazyAsyncResult.InvokeCallback()
    at WorkerThread.doWork()
    at WorkerThread.doWorkI()
    at WorkItem.doWork()
    at System.Threading.Timer.ring()


When frequently Open/Close UDP sockets, above exception comes while closing one socket and start listening on another socket on the same port. OnReceive method is called (only once) for the previous (closed) socket while doing “Start Listening” on new socket on the same port. As old socket is already dereferenced and closed, you will get above socket exception on EndReceiveFrom or EndReceive method.


In short, you have to ignore the calls of your OnReceive (or similar) for Old socket which you no longer use i.e. closed sockets.

Note that when you call BeginReceiveFrom to start listening for messages, it returns an instance of IAsyncResult. Don’t ignore this and store it into class level private variable (let’s say variable name currentAsyncResult).

Now make modification into  your OnReceive method to ignore any message which is not for currentAsyncResult.

private void OnReceive(IAsyncResult ar)
if (ar == currentAynchResult)
IPEndPoint ipeSender = new IPEndPoint(IPAddress.Any, 0);
EndPoint epSender = (EndPoint)ipeSender;

//Error comes here if we didn't have (ar == currentAynchResult) check
int bytesRead = udpSocket.EndReceiveFrom(ar, ref epSender);
//process further
catch (Exception ex)
//Log exception. Don't throw exception. Most probably BeginReceive failed.

Notice the if (ar == currentAynchResult) check where we got currentAynchResult from BeginReceiveFrom method while starting listening from new socket.

Happy Networking!

Wednesday, March 31, 2010

Configure OpenCV 2.0 on Visual Studio 2008 for VC++

You must be hating OpenCV 2.0 by now :) But don’t worry your pain will go soon (if yes, please write a comment). The biggest pain is that you will have to compile your OpenCV using CMake and all those stuff (as explained here). But if you are content with C or C++ and not interested in debugging inside OpenCV or Python then read further.

Download and Install, Emgu which is actually .NET wrapper for OpenCV but we will just use their precious .lib files which otherwise is pain in neck to generate (Download Emgu from here:

After Emgu installation, Open Visual Studio and follow these steps:

1. Go to Tool –> Options –> Projects and Solutions –> VC++ Directories

2. Now see a combobox “Show Directories for” and select “Include files” and add, “C:\Program Files\Emgu\Emgu CV\opencv\include\opencv” (verify, as program file location may differ if you are using 64 bit operating system)

3. Now in the same combobox select “Library files” and add, “C:\Program Files\Emgu\Emgu CV\lib\release

4.  Now go to your VC++ project, right click and go to Properties –> Configuration Properties –> Linker –> Input –> Additional Dependencies and add these lib files (which is at  C:\Program Files\Emgu\Emgu CV\lib\release) cv200.lib cvaux200.lib cxcore200.lib highgui200.lib (check library name, it may change according to OpenCV version used for the Emgu)

5. That’s it. Done for now. Take shot at compiling your VC++ code downloaded from internet ;)

NOTE: If you are interested in going into OpenCV library code while debugging then this may not be the best solution for you as Emgu only gives release .lib files. You will have to generate ‘debug’ lib files as described in

I am not sure but this same should help to configure VS 2010 also.

Monday, March 01, 2010

Wondering about System.Int32 implementation

If you are a .NET programmer (and do not use reflector), you would look at int and System.Int32 as same. But if you are also interested in reverse engineering, you would surprise how would they implement something like this.
This is how Int32 (part of mscorelib.dll) may look like in reflector,

namespace System
//attributes blah blah blah
public struct Int32  //implements blah blah blah....
internal int m_value;
//… other code with methods with ‘int’ as return type or parameter

But if int and Int32 are same, wouldn’t it become circular reference? (not ‘reference’ exactly has int is value type ;). The answer is NO. as we use them in real life. It seems reflector’s code is hardcoded to show it or mscorelib is compiled in some alien world.

I read[1] that there a special treatment given for 'int' (and so all other keywords). Interestingly, I learned creating my Int32 (and other predefined types). When I created something like this, in my project,
public struct Int32
public Int32 m_value;

public Int32 GetMe()
return this;

But after compilation, I saw (in reflactor) compiler did this to my class,
public struct Int32
// Fields
public int m_value;

// Methods
public unsafe int GetMe()
return *(((int*) this));

hmm.. Interesting. It looks like (also suggested in link [1]) when the compiler encounter an 'int' or 'Int32' in the structure which cannot be replace by pre-compiler as Int32, it gives 32 bit to variable m_value there. So, basically variable m_value doesn't exist as int or Int32 but it is just 32 bits which can be retrieved using unsafe code as shown above. Combination of visual studio intellisence, pre-compiler, compiler are specially designed to handle this scenario.
Note: For losers using Java, int is value type and Integer is reference type. Both are not same there. What a shame!

[1] C# compiler magic regarding int vs System.Int32 Thread on MSDN

Thursday, January 28, 2010

Fix "The project type not supported by this installation" blah blah blah after resetsettings command

Is your visual studio settings are messed up? You can reset your visual studio settings by starting it from visual studio command prompt:

devenv.exe /resetsettings

But often, WCF related stuff doesn't work after above command. When you open the WCF porject in your Visual Studio, you may get this error:
"The project type not supported by this installation" blah blah blah..

If you are the one who has done so, close the Visual Studio and run this command from visual studio command prompt:

devenv /ResetSkipPkgs

It should reset (i.e. remove in our case) the checks that should be skiped in order to open newer WCF project into your relatively older visual studio.

Thursday, January 21, 2010

.NET Namespace Naming Convention with Team Name in it

I hated naming conventions from collage time and nothing is much different today. Saying that, I also must accept that I secretly liked Microsoft's guidelines about naming conventions as it gives more freedom and meaningful restrictions than others (specially Sun Java). Let's leave other naming conventions and concentrate on namespace's maming convention of your assembly and classes.

Why namespace naming is important?
A namespace gives first hand impression on what the class and its method must be doing. With that, a class should get a unique identification based on its namespace. Carelessly crafted names are misleading advertisement which repulses intended audience or create confusion.

How Microsoft Tells us to name a namespace?
is what Namespace Naming Guidelines tells. Example being Microsoft.Build.Tasks

Is it long enough?
Organizations, with help of smart programmers, are now taking little more effort to refactor the code to extract common code which can be reused across teams. It is not impossible (infact it's more frequent) to have multiple implementation approach of a 'similar' feature by different team. For example team 'TreamA' and 'TeamB' in organization 'MyOrg' might have taken differnt approach to develop a media content viewer optimized for their own scenarios. If the organization want to share these media viewers across many teams to use, 'unique identification' functionality of namespace stands violated as media viewer class from both the team will look like,
This would not have occured if the namespace of viewers were named "MyOrg.Media.TreamA.Viewer" and "MyOrg.Media.TreamB.Viewer" beforehand.

I believe we should giving implementing team name in name as ending part of namespace. So my format would be