Thursday, October 23, 2008
Unit Testing in Visual Studio 2008
Error: Friend assembly reference 'AssemblyName' is invalid. Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations.
To fix this error, the steps are as:
1. Create a strong name key for the TestProject using the Visual Studio Command prompt
:sn –k “TestProject.snk”
2. Add the strong name key to the TestProject and in the properties of the TestProject, sign the assembly with the strong name key file
3. Extract the public key from the “TestProject.snk” and export it a new file as
sn –p TestProject.snk PublicKey.snk
4. Get the public key from the “PublicKey.snk file using
sn –tp PublicKey.snk
5. Add the public key in the AssemblyInfo.cs file as
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("TestProject1, PublicKey=0024000004800000940000000602000000240000525341310004000001000100274324f6df083237e787bcafcd35a1f9a746b018e7be3d3c47654aeed9d1efbf3ad0b47c00eaae26531b9b4965170680bc699fca7bb5f4eb87980fd12676d26aaaa84aa5f0c26f6187535dded0734a57fe5a88aeaee22997b021b7630676e53702d211fa47cb6c915b282e669c2f444c85e9e096fc0b222efa93e61751e20dba")]
This should resove the error.
Friday, October 17, 2008
Generating a proxy in WCF when generics is used
By default svcutil command does not include System.Collection datatypes
By Default, the command is :
svcutil /l vb "http://localhost/SampleWCFService/SampleContract.svc?wsdl"
where SampleWCFService is a WCF service hosted on the IIS
If a service method returns or accepts a Generic List , then the svcutil command will be as follows :
svcutil /l vb /CollectionType:System.Collections.Generic.List`1 "http://localhost/SampleWCFService/SampleContract.svc?wsdl"
If the service accepts or returns more then one System.Collections datatypes,say, Hashtable and generic list then the command will be as follows :
svcutil /l vb /CollectionType:System.Collections.Hashtable /CollectionType:System.Collections.Generic.List`1 "http://localhost/SampleWCFService/SampleContract.svc?wsdl"
Tuesday, October 14, 2008
Dependency Properties in WPF
http://www.mridey.com/blog/Lists/Posts/Post.aspx?List=321eab0d%2De4d2%2D4523%2D914e%2D128a6688109f&ID=4
http://blog.hackedbrain.com/articles/UnderstandingDependencyObjectAndDependencyProperty.aspx
Monday, October 13, 2008
Basic differences between Windows and WPF application:
As a beginner to WPF having worked on Windows application, some of the basic differences that I came across between the two are:
1. The Windows class derives from System.Windows.Forms namespace whereas a WPF class derives from the System.Windows.Window namespace
2. The program.cs file was used to specify the startup class in a Windows app but in a WPF app, the Startup Uri in the App.xaml can be used to specify the startup class.
3. The name attribute for any control was mandatory in a Windows app, but is not mandatory for a WPF application. Eg: If I have 2 buttons in a WPF form without any name property, if I add a click event for the 2 buttons the events generated are
private void Button_Click(object sender, RoutedEventArgs e)
{
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
}
4. If you noticed in the previous example, the RoutedEventArgs is something new compared to the EventArgs in a Windows App. So, what is the difference between the two?
A Routed event can not only occur on the object that initially raises it but also on objects related to it i.e. the event can be passed on.
Some good links to get started with WPF are
http://aspalliance.com/articles/LearnWPF.aspx
http://windowsclient.net/