I have already seen the below link
WPF, 'Object reference not set to an instance of an object' in Designer
My problem is similar but a little different. I am not setting any data context in XAML itself. I am creating my own user control and I am using that in another.
<usercontrols:MyControl1 x:Name="MyControl1" Grid.Row="5" Height="Auto" Width="Auto">
</usercontrols:MyControl1>
This is the code I am using in second control to refer MyControl1. This generally does not throw any exception. But, When I specify some code in the constructer of MyControl1, the exception is coming. It also says "Cannot Create an Instance of MyControl1".