<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>.NET discussions</title>
	<atom:link href="http://dotnetfundas.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://dotnetfundas.wordpress.com</link>
	<description></description>
	<lastBuildDate>Sat, 08 Oct 2011 10:39:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='dotnetfundas.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>.NET discussions</title>
		<link>http://dotnetfundas.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://dotnetfundas.wordpress.com/osd.xml" title=".NET discussions" />
	<atom:link rel='hub' href='http://dotnetfundas.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Serialization and .NET framework</title>
		<link>http://dotnetfundas.wordpress.com/2011/10/08/serialization-and-net-framework/</link>
		<comments>http://dotnetfundas.wordpress.com/2011/10/08/serialization-and-net-framework/#comments</comments>
		<pubDate>Sat, 08 Oct 2011 10:37:47 +0000</pubDate>
		<dc:creator>Abhijeet Kulkarni</dc:creator>
				<category><![CDATA[Serialization]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">https://dotnetfundas.wordpress.com/2011/10/08/serialization-and-net-framework/</guid>
		<description><![CDATA[&#160; Moving ahead from unit testing aspects lets go through serialization and scenarios where we need to use this.&#160; Of course implementation wise we will see what is supported in .NET framework and its C# implementation. What is Serialization?? In computer science term serialization usually refers to persisting state of object. According to Wikipedia page [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetfundas.wordpress.com&amp;blog=9605895&amp;post=89&amp;subd=dotnetfundas&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&#160;<a href="http://dotnetfundas.files.wordpress.com/2011/10/sagareshwarsanctuaryphotobyabhisheskkadam.png"><img style="display:inline;border-width:0;" title="Sagareshwar Sanctuary, Photo By Abhishesk kadam" border="0" alt="Sagareshwar Sanctuary, Photo By Abhishesk kadam" src="http://dotnetfundas.files.wordpress.com/2011/10/sagareshwarsanctuaryphotobyabhisheskkadam_thumb.png?w=450&#038;h=398" width="450" height="398" /></a> </p>
</p>
<p><font size="2">Moving ahead from unit testing aspects lets go through serialization and scenarios where we need to use this.&#160; Of course implementation wise we will see what is supported in .NET framework and its C# implementation.</font></p>
<p><strong><font size="2">What is Serialization??</font></strong></p>
<p><font size="2">In computer science term serialization usually refers to persisting state of object.</font></p>
<p><font size="2">According to </font><a href="http://en.wikipedia.org/wiki/Serialization"><font size="2">Wikipedia page</font></a><font size="2"> </font></p>
<p><font size="2">“In </font><a href="http://en.wikipedia.org/wiki/Computer_science"><font size="2">computer science</font></a><font size="2">, in the context of data storage and transmission, <b>serialization</b> is the process of converting a </font><a href="http://en.wikipedia.org/wiki/Data_structure"><font size="2">data structure</font></a><font size="2"> or </font><a href="http://en.wikipedia.org/wiki/Object_(computer_science)"><font size="2">object</font></a><font size="2"> into a sequence of bits so that it can be stored in a </font><a href="http://en.wikipedia.org/wiki/Computer_file"><font size="2">file</font></a><font size="2"> or memory buffer, or transmitted across a </font><a href="http://en.wikipedia.org/wiki/Computer_network"><font size="2">network</font></a><font size="2"> connection link to be &quot;resurrected&quot; later in the same or another computer environment.<sup><a href="http://en.wikipedia.org/#cite_note-0">[1]</a></sup> </font></p>
<p><font size="2">When the resulting series of bits is reread according to the serialization format, it can be used to create a semantically identical clone of the original object. For many complex objects, such as those that make extensive use of </font><a href="http://en.wikipedia.org/wiki/Reference_(computer_science)"><font size="2">references</font></a><font size="2">, this process is not straightforward.</font></p>
<p><font size="2">This process of serializing an object is also called <b>deflating</b> or <b><a href="http://en.wikipedia.org/wiki/Marshalling_(computer_science)">marshalling</a></b> an object.<sup><a href="http://en.wikipedia.org/#cite_note-1">[2]</a></sup> The opposite operation, extracting a data structure from a series of bytes, is <b>deserialization</b> (which is also called <b>inflating</b> or <b>unmarshalling</b>). “</font></p>
<p><strong><font size="2">Ways of Serialization in .NET</font></strong></p>
<p><strong><font size="2"></font></strong></p>
<p><font size="2">Simplest way of serialization is to mark the class with the Serializable attribute.</font></p>
<pre><font size="2" face="Verdana"> [Serializable]
 public class SaveScores {
        public int Score = 0;
        public int Wickets = 0;
        public String PlayerName = String.Empty;
 }</font></pre>
<pre><font size="2" face="Verdana">IFormatter FormatData = new BinaryFormatter();
Stream SaveStream = new FileStream(&quot;SaveScores.Txt&quot;,
                                    FileMode.Create,
                                    FileAccess.Write, FileShare.None);
formatter.Serialize(SaveStream, FormatData);
SaveStream.Close();</font></pre>
<pre><font size="2" face="Verdana">We can also have selective serialization. For this we need to use </font></pre>
<pre><font size="2" face="Verdana">NonSerialized attribute with the fields we do not want to consider </font></pre>
<pre><font size="2" face="Verdana">for serialization.</font></pre>
<pre><font size="2" face="Verdana">[Serializable]
public class SaveScores{
  public int Score;
  [NonSerialized] public int Wickets;
  public String PlayerName=String.Empty;
}</font></pre>
<pre><font size="2" face="Verdana">Having seen this basic way of serializing a object, in coming posts </font></pre>
<pre><font size="2" face="Verdana">I will talk about other important aspects of Serialization which are </font></pre>
<ol>
<li><font size="2">Versioning. </font></li>
<li><font size="2">Custom Serialization. </font></li>
<li><font size="2">Concepts behind Serialization. </font></li>
<li><font size="2">Resources and Useful links for Serialization. </font></li>
</ol>
<p><font size="2">Till then .. Keep Reading, Keep Coding .. </font></p>
<pre><font size="2" face="Verdana">&#160;</font></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetfundas.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetfundas.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetfundas.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetfundas.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dotnetfundas.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dotnetfundas.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dotnetfundas.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dotnetfundas.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetfundas.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetfundas.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetfundas.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetfundas.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetfundas.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetfundas.wordpress.com/89/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetfundas.wordpress.com&amp;blog=9605895&amp;post=89&amp;subd=dotnetfundas&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dotnetfundas.wordpress.com/2011/10/08/serialization-and-net-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccf82f9e698e4fa268617eb083c04a68?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotnetinternals</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2011/10/sagareshwarsanctuaryphotobyabhisheskkadam_thumb.png" medium="image">
			<media:title type="html">Sagareshwar Sanctuary, Photo By Abhishesk kadam</media:title>
		</media:content>
	</item>
		<item>
		<title>Visual Studio Team System &#8211; Test Edition</title>
		<link>http://dotnetfundas.wordpress.com/2010/09/30/visual-studio-team-system-test-edition/</link>
		<comments>http://dotnetfundas.wordpress.com/2010/09/30/visual-studio-team-system-test-edition/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 20:01:42 +0000</pubDate>
		<dc:creator>Abhijeet Kulkarni</dc:creator>
				<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">https://dotnetfundas.wordpress.com/2010/09/30/visual-studio-team-system-test-edition/</guid>
		<description><![CDATA[&#160; Oh Yeah ! It was big gap between last post and this one. May be I was looking for this snap !! &#160; Continuing with my earlier posts I would like to write about two more tests available in visual studio Ordered Tests Web Tests In previous post we saw various aspects of unit [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetfundas.wordpress.com&amp;blog=9605895&amp;post=73&amp;subd=dotnetfundas&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>Oh Yeah ! It was big gap between last post and this one.</p>
<p>May be I was looking for this snap !!</p>
<p><a href="http://dotnetfundas.files.wordpress.com/2010/09/flower.png"><img style="display:inline;border-width:0;" title="flower" src="http://dotnetfundas.files.wordpress.com/2010/09/flower_thumb.png?w=450&#038;h=425" alt="flower" width="450" height="425" border="0" /></a></p>
<p>&nbsp;</p>
<p>Continuing with my earlier posts I would like to write about two more tests available in visual studio</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms182630(VS.80).aspx">Ordered Tests</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms182536(v=vs.90).aspx">Web Tests</a></p>
<p>In previous post we saw various aspects of unit test and related features.</p>
<p>One of the key things to understand is while running the unit tests deployed for project in ordered manner is very important. This is required for building a scenario by running tests in specific sequence or this ordering might be important from a view that we have to run unit tests specific to certain section of our program.</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms182470(v=VS.80).aspx">How to Run Ordered Tests</a> gives detailed insight on aspects related to ordered tests. This option for ordered test is available in developer edition as well as test edition.</p>
<p>Another important aspect related to testing of web based applications is web tests provided in visual studio test edition.</p>
<p>With help of web tests we can record various actions taken by user related to web application. This recorded actions include http request and responses, request status code time required for these requests.</p>
<p>Web Test Engine takes care of lots of things such as Extraction rules, validation rules, authentication, handling of cookies etc.</p>
<p>In addition to this features web tests can be connected to data sources like .csv files or excel files using the database providers so that post parameters covered in the recording can be connected to data for making these tests data driven.</p>
<p>Web tests play specific role to identify what changes have been made to UI or it can be used as a effective script tool which can easily populate the system to be deployed on client.</p>
<p>Two most important resources on web tests are</p>
<p><a href="http://blogs.msdn.com/b/amit_chatterjee/archive/2009/01/29/web-and-load-testing-with-visual-studio-team-system.aspx">Amit Chatterjee&#8217;s Blog</a> – A must read page for web tests</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms182536(v=vs.90).aspx">Working with web tests</a> – MSDN page for web tests.</p>
<p>I hope this sounds interesting and useful to all of you.</p>
<p>Keep coming, keep reading ..</p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:0286841b-78fd-489a-8606-66e92ab407cc" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">Technorati Tags: <a href="http://technorati.com/tags/Visual+Studio" rel="tag">Visual Studio</a>,<a href="http://technorati.com/tags/WebTests" rel="tag">WebTests</a>,<a href="http://technorati.com/tags/Unit+Testing" rel="tag">Unit Testing</a></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetfundas.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetfundas.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetfundas.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetfundas.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dotnetfundas.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dotnetfundas.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dotnetfundas.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dotnetfundas.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetfundas.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetfundas.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetfundas.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetfundas.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetfundas.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetfundas.wordpress.com/73/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetfundas.wordpress.com&amp;blog=9605895&amp;post=73&amp;subd=dotnetfundas&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dotnetfundas.wordpress.com/2010/09/30/visual-studio-team-system-test-edition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccf82f9e698e4fa268617eb083c04a68?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotnetinternals</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/09/flower_thumb.png" medium="image">
			<media:title type="html">flower</media:title>
		</media:content>
	</item>
		<item>
		<title>Unit Testing &#8211; Twists and Twirls ( Part 2)</title>
		<link>http://dotnetfundas.wordpress.com/2010/03/14/unit-testing-twists-and-twirls-part-2/</link>
		<comments>http://dotnetfundas.wordpress.com/2010/03/14/unit-testing-twists-and-twirls-part-2/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 08:20:40 +0000</pubDate>
		<dc:creator>Abhijeet Kulkarni</dc:creator>
				<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://dotnetfundas.wordpress.com/2010/03/14/unit-testing-twists-and-twirls-part-2/</guid>
		<description><![CDATA[Let see some action now and jump into how to test simple function residing in a class. For this we start with creating a simple class library in C# using Visual Studio 2008. Lets proceed with putting some simple code snippet which provides us simple arithmetic operations. Lets proceed with adding unit test project for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetfundas.wordpress.com&amp;blog=9605895&amp;post=69&amp;subd=dotnetfundas&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://dotnetfundas.files.wordpress.com/2010/03/kumbharleeghat.jpg"><img style="display:inline;border-width:0;" title="@Kumbharlee Ghat" src="http://dotnetfundas.files.wordpress.com/2010/03/kumbharleeghat_thumb.jpg?w=450&#038;h=338" alt="@Kumbharlee Ghat" width="450" height="338" border="0" /></a></p>
<p>Let see some action now and jump into how to test simple function residing in a class.</p>
<p>For this we start with creating a simple class library in C# using Visual Studio 2008.</p>
<p><a href="http://dotnetfundas.files.wordpress.com/2010/03/creatingclasslibrary.png"><img style="display:inline;border-width:0;" title="CreatingClassLibrary" src="http://dotnetfundas.files.wordpress.com/2010/03/creatingclasslibrary_thumb.png?w=450&#038;h=311" alt="CreatingClassLibrary" width="450" height="311" border="0" /></a></p>
<p>Lets proceed with putting some simple code snippet which provides us simple arithmetic operations.</p>
<p><a href="http://dotnetfundas.files.wordpress.com/2010/03/simplefunctions.png"><img style="display:inline;border-width:0;" title="Simplefunctions" src="http://dotnetfundas.files.wordpress.com/2010/03/simplefunctions_thumb.png?w=450&#038;h=366" alt="Simplefunctions" width="450" height="366" border="0" /></a></p>
<p>Lets proceed with adding unit test project for this class library which will contain two unit test methods.</p>
<p>For this we right click on class name and click on choice “Create Unit Tests… “.</p>
<p><a href="http://dotnetfundas.files.wordpress.com/2010/03/createunittests.png"><img style="display:inline;border-width:0;" title="CreateUnitTests" src="http://dotnetfundas.files.wordpress.com/2010/03/createunittests_thumb.png?w=449&#038;h=282" alt="CreateUnitTests" width="449" height="282" border="0" /></a></p>
<p>Following dialog is then displayed for user which allows some settings to be made as per user’s preferences.</p>
<p><a href="http://dotnetfundas.files.wordpress.com/2010/03/testpreference.png"><img style="display:inline;border-width:0;" title="TestPreference" src="http://dotnetfundas.files.wordpress.com/2010/03/testpreference_thumb.png?w=450&#038;h=343" alt="TestPreference" width="450" height="343" border="0" /></a></p>
<p>Here we select class and both the methods inside class so that Unit Tests will be created for them.</p>
<p>Output project type is C# test project which user can select as per preference.</p>
<p>Additionally clicking “settings” button will open Test Generation Settings dialog which will allow to set <em>Naming Settings</em> as well as <em>General settings</em>.</p>
<p><a href="http://dotnetfundas.files.wordpress.com/2010/03/testgenerationsetting.png"><img style="display:inline;border-width:0;" title="TestGenerationSetting" src="http://dotnetfundas.files.wordpress.com/2010/03/testgenerationsetting_thumb.png?w=450&#038;h=383" alt="TestGenerationSetting" width="450" height="383" border="0" /></a></p>
<p>There are five choices displayed for user under general settings.</p>
<ul>
<li>Mark all test results inconclusive by default</li>
<li>Enable generation warnings</li>
<li>Globally Qualify all types</li>
<li>Enable documentation comments</li>
<li>Honor <em>InternalsVisibleTo</em> Attribute.</li>
</ul>
<p>There you go ! Last one needs to be paid attention to ..</p>
<p>For time being lets proceed with our unit tests for <em>AddTwoNumbers</em> and <em>SubTwoNumbers</em> methods.</p>
<p>Once we click ok user is prompted for name of the Test project.</p>
<p><a href="http://dotnetfundas.files.wordpress.com/2010/03/nameproject.png"><img style="display:inline;border-width:0;" title="nameProject" src="http://dotnetfundas.files.wordpress.com/2010/03/nameproject_thumb.png?w=450&#038;h=385" alt="nameProject" width="450" height="385" border="0" /></a></p>
<p>Clicking of Create button will add Test project to the solution.</p>
<p><a href="http://dotnetfundas.files.wordpress.com/2010/03/createdproject.png"><img style="display:inline;border-width:0;" title="CreatedProject" src="http://dotnetfundas.files.wordpress.com/2010/03/createdproject_thumb.png?w=450&#038;h=369" alt="CreatedProject" width="450" height="369" border="0" /></a></p>
<p>If we closely observe few things added newly in the project</p>
<ul>
<li>LocalTestRun.testrunconfig file</li>
<li>Unit Testing.vsmdi file</li>
<li>SimpleMathTest project which contains SimpleMathTest.cs file.</li>
</ul>
<p>Lets see what all contents we have inside SimpleMathTest.cs file.</p>
<p><a href="http://dotnetfundas.files.wordpress.com/2010/03/testcontext.png"><img style="display:inline;border-width:0;" title="TestContext" src="http://dotnetfundas.files.wordpress.com/2010/03/testcontext_thumb.png?w=450&#038;h=388" alt="TestContext" width="450" height="388" border="0" /></a></p>
<p>Object of TextContext class called testContextInstance.</p>
<p>get; set; for TextContext which provides information about and functionality for the current test run.</p>
<p>Next to this we have two test methods</p>
<p>SubTwoNumbersTest()</p>
<p>AddTwoNumbersTest()</p>
<p><a href="http://dotnetfundas.files.wordpress.com/2010/03/testmethods.png"><img style="display:inline;border-width:0;" title="TestMethods" src="http://dotnetfundas.files.wordpress.com/2010/03/testmethods_thumb.png?w=450&#038;h=395" alt="TestMethods" width="450" height="395" border="0" /></a></p>
<p>we modify the values for “a” and “b” variables so as to check whether the actual and expected results match or not.</p>
<p>Changes made will look like this</p>
<p><a href="http://dotnetfundas.files.wordpress.com/2010/03/expectedactual.png"><img style="display:inline;border-width:0;" title="ExpectedActual" src="http://dotnetfundas.files.wordpress.com/2010/03/expectedactual_thumb.png?w=448&#038;h=446" alt="ExpectedActual" width="448" height="446" border="0" /></a></p>
<p>What we re trying to judge here is after passing a as 10 and b as 10 , whether addition is returned as 20 and subtraction as 0.</p>
<p>But question remains.. How do I test this ?? Lets check it out…</p>
<p><a href="http://dotnetfundas.files.wordpress.com/2010/03/runttestcase.png"><img style="display:inline;border-width:0;" title="RuntTestCase" src="http://dotnetfundas.files.wordpress.com/2010/03/runttestcase_thumb.png?w=450&#038;h=383" alt="RuntTestCase" width="450" height="383" border="0" /></a></p>
<p>As shown in the image, if we click on Test-&gt;Run we find two options</p>
<ul>
<li>Test in current context</li>
<li>All Tests in solution</li>
</ul>
<p>We select option Test in Current context. Another way to run Test in current context is Pressing Ctrl+R, T directly which will execute currently selected test case.</p>
<p>Another simplest way is to  click on vsmdi file which will open up Test List Editor listing all the test cases. We can also use toolbar items to run the tests in current context or all tests in solution.</p>
<p><a href="http://dotnetfundas.files.wordpress.com/2010/03/vsmdi.png"><img style="display:inline;border-width:0;" title="vsmdi" src="http://dotnetfundas.files.wordpress.com/2010/03/vsmdi_thumb.png?w=450&#038;h=447" alt="vsmdi" width="450" height="447" border="0" /></a></p>
<p>After clicking on Run Test in current context what we get is as follows</p>
<p><a href="http://dotnetfundas.files.wordpress.com/2010/03/runtestusingvsmdi.png"><img style="display:inline;border-width:0;" title="RunTestUsingVsmdi" src="http://dotnetfundas.files.wordpress.com/2010/03/runtestusingvsmdi_thumb.png?w=446&#038;h=354" alt="RunTestUsingVsmdi" width="446" height="354" border="0" /></a></p>
<p>What we see here in bottom as test is passed. Since we passed 10,10 as two input values and 20 as expected result; both values matched and test case is marked as successful(passed).</p>
<p>Whether to check what happens when actual and expected values do not match lets try out changing the values and this time we do it in SubTwoNumbersTest.</p>
<p>We change the value of b as 20 but still expected result is 0 and this is not going to match with actual value.</p>
<p>This time we will run the test case by using option ctrl+R, T</p>
<p>The failed test case result will look like</p>
<p><a href="http://dotnetfundas.files.wordpress.com/2010/03/failedtestcase.png"><img style="display:inline;border-width:0;" title="FailedTestCase" src="http://dotnetfundas.files.wordpress.com/2010/03/failedtestcase_thumb.png?w=450&#038;h=453" alt="FailedTestCase" width="450" height="453" border="0" /></a></p>
<p>We can also add columns to Test Results by right clicking first column header as per our preference.</p>
<p><a href="http://dotnetfundas.files.wordpress.com/2010/03/addcolumns.png"><img style="display:inline;border-width:0;" title="AddColumns" src="http://dotnetfundas.files.wordpress.com/2010/03/addcolumns_thumb.png?w=450&#038;h=395" alt="AddColumns" width="450" height="395" border="0" /></a></p>
<p>So far we have used Asser.Equal to compare actual and expected result. But Assert class provides us various methods which can be used to  conduct a test case. All the details for this methods can be found <a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.assert_members(VS.80).aspx">here</a>.</p>
<p>Before we conclude lets quickly summarize what we have seen in this post</p>
<ol>
<li>How to add a unit test project</li>
<li>Details of unit test project and how test functions are added.</li>
<li>How to run test cases and ways to run test cases</li>
<li>Details of  Assert class and methods residing under it</li>
</ol>
<p>In coming post we will see how “Honor Internals Visible To “ attribute is used and what happens with methods with different scope like private, internal and private static etc.</p>
<p>Please do write me about your feedback or queries  which I am expecting the most , so that this articles can be made better and better !</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetfundas.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetfundas.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetfundas.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetfundas.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dotnetfundas.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dotnetfundas.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dotnetfundas.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dotnetfundas.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetfundas.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetfundas.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetfundas.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetfundas.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetfundas.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetfundas.wordpress.com/69/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetfundas.wordpress.com&amp;blog=9605895&amp;post=69&amp;subd=dotnetfundas&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dotnetfundas.wordpress.com/2010/03/14/unit-testing-twists-and-twirls-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccf82f9e698e4fa268617eb083c04a68?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotnetinternals</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/03/kumbharleeghat_thumb.jpg" medium="image">
			<media:title type="html">@Kumbharlee Ghat</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/03/creatingclasslibrary_thumb.png" medium="image">
			<media:title type="html">CreatingClassLibrary</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/03/simplefunctions_thumb.png" medium="image">
			<media:title type="html">Simplefunctions</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/03/createunittests_thumb.png" medium="image">
			<media:title type="html">CreateUnitTests</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/03/testpreference_thumb.png" medium="image">
			<media:title type="html">TestPreference</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/03/testgenerationsetting_thumb.png" medium="image">
			<media:title type="html">TestGenerationSetting</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/03/nameproject_thumb.png" medium="image">
			<media:title type="html">nameProject</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/03/createdproject_thumb.png" medium="image">
			<media:title type="html">CreatedProject</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/03/testcontext_thumb.png" medium="image">
			<media:title type="html">TestContext</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/03/testmethods_thumb.png" medium="image">
			<media:title type="html">TestMethods</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/03/expectedactual_thumb.png" medium="image">
			<media:title type="html">ExpectedActual</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/03/runttestcase_thumb.png" medium="image">
			<media:title type="html">RuntTestCase</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/03/vsmdi_thumb.png" medium="image">
			<media:title type="html">vsmdi</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/03/runtestusingvsmdi_thumb.png" medium="image">
			<media:title type="html">RunTestUsingVsmdi</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/03/failedtestcase_thumb.png" medium="image">
			<media:title type="html">FailedTestCase</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/03/addcolumns_thumb.png" medium="image">
			<media:title type="html">AddColumns</media:title>
		</media:content>
	</item>
		<item>
		<title>Unit Testing &#8211; Twists and Twirls</title>
		<link>http://dotnetfundas.wordpress.com/2010/03/06/unit-testing-twists-and-twirls/</link>
		<comments>http://dotnetfundas.wordpress.com/2010/03/06/unit-testing-twists-and-twirls/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 21:07:14 +0000</pubDate>
		<dc:creator>Abhijeet Kulkarni</dc:creator>
				<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://dotnetfundas.wordpress.com/2010/03/06/unit-testing-twists-and-twirls/</guid>
		<description><![CDATA[In my previous posts , we saw some of the interesting scenarios in Interoperability. Having covered this area lets check out some of the “must know “ aspects and areas under Unit Testing. Frequently Used Terminologies Test Driven Development : Test-driven development (TDD) is an advanced technique of using automated unit tests to drive the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetfundas.wordpress.com&amp;blog=9605895&amp;post=36&amp;subd=dotnetfundas&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://dotnetfundas.files.wordpress.com/2010/03/sayajipune.jpg"><img style="display:inline;border-width:0;" title="@Sayaji,Pune" src="http://dotnetfundas.files.wordpress.com/2010/03/sayajipune_thumb.jpg?w=438&#038;h=367" alt="@Sayaji,Pune" width="438" height="367" border="0" /></a></p>
<p>In my previous posts , we saw some of the interesting scenarios in <a href="http://dotnetfundas.wordpress.com/">Interoperability</a>. Having covered this area lets check out some of the “must know “ aspects and areas under Unit Testing.</p>
<p><span style="text-decoration:underline;"><strong>Frequently Used Terminologies</strong></span></p>
<p><strong>Test Driven Development : </strong></p>
<p>Test-driven development (TDD) is an advanced technique of using automated unit tests to drive the design of software and force decoupling of dependencies. The result of using this practice is a comprehensive suite of unit tests that can be run at any time to provide feedback that the software is still working. This technique is heavily emphasized by those using Agile development methodologies.</p>
<p>click <a href="http://msdn.microsoft.com/en-us/library/aa730844(VS.80).aspx">here</a> for detailed information.</p>
<p><strong>Unit Testing:</strong></p>
<p>The primary goal of unit testing is to take the smallest piece of testable software in the application, isolate it from the remainder of the code, and determine whether it behaves exactly as you expect. Each unit is tested separately before integrating them into modules to test the interfaces between modules. Unit testing has proven its value in that a large percentage of defects are identified during its use.</p>
<p>The most common approach to unit testing requires drivers and stubs to be written. The driver simulates a calling unit and the stub simulates a called unit. The investment of developer time in this activity sometimes results in demoting unit testing to a lower level of priority and that is almost always a mistake. Even though the drivers and stubs cost time and money, unit testing provides some undeniable advantages. It allows for automation of the testing process, reduces difficulties of discovering errors contained in more complex pieces of the application, and test coverage is often enhanced because attention is given to each unit.</p>
<p><a href="http://msdn.microsoft.com/en-us/library/aa292197(VS.71).aspx">MSDN</a> info gives detailed insight on this.</p>
<p><strong>Test Scenarios:</strong></p>
<p>Test scenarios represent a powerful tool for test development. In general scenario defines an own model of target system, called the testing model. Scenario must define the state class for this model and the transitions, which must be described in terms of target methods</p>
<p><strong>Test Cases:</strong></p>
<p>A test case in software engineering is a set of conditions or variables under which a tester will determine whether an application or software system is working correctly or not. The mechanism for determining whether a software program or system has passed or failed such a test is known as a test oracle. In some settings, an oracle could be a requirement or use case, while in others it could be a heuristic. It may take many test cases to determine that a software program or system is functioning correctly. Test cases are often referred to as test scripts, particularly when written. Written test cases are usually collected into test suites.</p>
<p>More info on this <a href="http://en.wikipedia.org/wiki/Test_case">Wiki</a> page.</p>
<p><strong>Code Coverage:</strong></p>
<p>Code coverage is a measure used in software testing. It describes the degree to which the source code of a program has been tested. It is a form of testing that inspects the code directly and is therefore a form of white box testing. In time, the use of code coverage has been extended to the field of digital hardware, the contemporary design methodology of which relies on hardware description language(HDLs).</p>
<p>Code coverage techniques were amongst the first techniques invented for systematic software testing.</p>
<p><a href="http://en.wikipedia.org/wiki/Code_coverage">Detailed</a><strong> </strong>info is here.</p>
<p><strong>Test Frameworks:</strong></p>
<p>Unit testing frameworks, which help simplify the process of unit testing, have been developed for a wide variety of languages as detailed in this list of unit testing frameworks. It is generally possible to perform unit testing without the support of specific framework by writing client code that exercises the units under test and uses assertions, exception handling or other control flow mechanisms to signal failure. This approach is valuable in that there is a barrier to entry for the adoption of unit testing; having scant unit tests is hardly better than having none at all, whereas once a framework is in place, adding unit tests becomes relatively easy.</p>
<p><a href="http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks">Detailed list</a> of unit testing framework is worth having look at.</p>
<p>Okay ! Enough of theory .. isn’t it ??</p>
<p>We talked about Twists and Twirls .. where are they ???</p>
<p>We will be coming across them from next post as we go ahead and see the actual examples.  Getting used to this terminologies is really important and we will need them as we see various aspects of Unit Testing.</p>
<p>Till then .. Have a Nice One <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetfundas.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetfundas.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetfundas.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetfundas.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dotnetfundas.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dotnetfundas.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dotnetfundas.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dotnetfundas.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetfundas.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetfundas.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetfundas.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetfundas.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetfundas.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetfundas.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetfundas.wordpress.com&amp;blog=9605895&amp;post=36&amp;subd=dotnetfundas&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dotnetfundas.wordpress.com/2010/03/06/unit-testing-twists-and-twirls/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccf82f9e698e4fa268617eb083c04a68?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotnetinternals</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/03/sayajipune_thumb.jpg" medium="image">
			<media:title type="html">@Sayaji,Pune</media:title>
		</media:content>
	</item>
		<item>
		<title>Interops: .NET and Mono</title>
		<link>http://dotnetfundas.wordpress.com/2010/02/09/interops-net-and-mono/</link>
		<comments>http://dotnetfundas.wordpress.com/2010/02/09/interops-net-and-mono/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 21:25:11 +0000</pubDate>
		<dc:creator>Abhijeet Kulkarni</dc:creator>
				<category><![CDATA[Interops]]></category>

		<guid isPermaLink="false">http://dotnetfundas.wordpress.com/2010/02/09/interops-net-and-mono/</guid>
		<description><![CDATA[Ever wondered a scenario where you want to develop a cross platform .NET application ? What kind of framework is required for this kind of applications ?? Well lets discuss! Mono software platform allows developers to create cross platform applications which is an open source implementation of Microsoft’s .NET framework based on ECMA standards. Main [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetfundas.wordpress.com&amp;blog=9605895&amp;post=32&amp;subd=dotnetfundas&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://dotnetfundas.files.wordpress.com/2010/02/corbettnationalparkphotobyajeygodbole.jpg"><img style="display:inline;border-width:0;" title="@Corbett National Park,Photo by Ajey godbole" src="http://dotnetfundas.files.wordpress.com/2010/02/corbettnationalparkphotobyajeygodbole_thumb.jpg?w=458&#038;h=413" alt="@Corbett National Park,Photo by Ajey godbole" width="458" height="413" border="0" /></a></p>
<p>Ever wondered a scenario where you want to develop a cross platform .NET application ?</p>
<p>What kind of framework is required for this kind of applications ??</p>
<p>Well lets discuss!</p>
<p><a href="http://mono-project.com/Start">Mono</a> software platform allows developers to create cross platform applications which is an open source implementation of Microsoft’s .NET framework based on ECMA standards.</p>
<p>Main components of Mono</p>
<p>1) C# compiler for compiling C# 1.0 and C# 2.0 features and  additionally many of the C# 3.0 features.</p>
<p>2) Mono runtime which implements Common Language Infrastructure (CLI) , Just-In-Time (JIT) compiler, Ahead-of-Time (AOT) compiler, a library loader, the garbage collector, threading system and interoperability functionality.</p>
<p>3)Base Class Library which provides comprehensive set of classes for building applications.</p>
<p>4) Mono Class Library provides additional classes  for Gtk+, Zip files,LDAP,OpenGL etc.</p>
<p>The whole advantage of this Mono framework is , it provides a framework for user for Cross Platform development which is varied on <a href="http://mono-project.com/Mono:Linux">Linux</a>, <a href="http://mono-project.com/Mono:Windows">Microsoft Windows</a>, <a href="http://mono-project.com/Mono:OSX">Mac OS X</a>, <a href="http://mono-project.com/Mono:BSD">BSD</a>, and <a href="http://mono-project.com/Mono:Solaris">Sun Solaris</a>, <a href="http://mono-project.com/Mono:Wii">Nintendo Wii</a>, <a href="http://mono-project.com/Mono:PlayStation3">Sony PlayStation 3</a>, <a href="http://mono-project.com/Mono:Iphone">Apple iPhone</a> and many others with a additional advantage that developer is already used to .NET framework and programming language such as C#, VB.NET and Eiffel etc. Scripting and Embedding can also be used for various purposes.</p>
<p>This <a href="http://en.wikipedia.org/wiki/Mono_(software)">Wiki Page</a> gives detailed information about Mono framework  and its extensions.</p>
<p>As given on Wikipedia Several projects extend Mono such as</p>
<p>&nbsp;</p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Cocoa_Sharp">Cocoa#</a> <a href="http://www.cocoasharp.org/">[1]</a> wrappers around the native Mac OS X toolkit (<a href="http://en.wikipedia.org/wiki/Cocoa_(API)">Cocoa</a>).</li>
<li>Gecko#, bindings for embedding the layout engine used in Mozilla (<a href="http://en.wikipedia.org/wiki/Gecko_(layout_engine)">Gecko</a>).</li>
<li><a href="http://en.wikipedia.org/wiki/Gtk_Sharp">Gtk#</a>, C# wrappers around the underlying <a href="http://en.wikipedia.org/wiki/GTK%2B">GTK+</a> and <a href="http://en.wikipedia.org/wiki/GNOME">GNOME</a> libraries, written in <a href="http://en.wikipedia.org/wiki/C_(programming_language)">C</a>.</li>
<li><a href="http://en.wikipedia.org/wiki/Tao_Framework">Tao</a>, a collection of graphics and gaming bindings (OpenGL, SDL, Glut, Cg).</li>
<li><a href="http://www.mono-project.com/MoMA">Mono Migration Analyzer (MoMA)</a> tool.</li>
<li><a href="http://en.wikipedia.org/wiki/Moonlight_(runtime)">Moonlight</a>, an implementation of <a href="http://en.wikipedia.org/wiki/Microsoft_Silverlight">Silverlight</a> that uses Mono.</li>
</ul>
<p>&nbsp;</p>
<p><strong><span style="text-decoration:underline;">Updates and Resources </span></strong></p>
<p><a href="http://www.go-mono.com/mono-downloads/download.html">Mono 2.6.1</a>  is now available.</p>
<p>There are various forums and blogs which discuss latest updates about Mono which can be accessed <a href="http://mono-project.com/Community">here</a>.</p>
<p>Mono Tools for visual studio is available for <a href="http://go-mono.com/monotools/">download</a> with 30 day trial.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetfundas.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetfundas.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetfundas.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetfundas.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dotnetfundas.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dotnetfundas.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dotnetfundas.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dotnetfundas.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetfundas.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetfundas.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetfundas.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetfundas.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetfundas.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetfundas.wordpress.com/32/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetfundas.wordpress.com&amp;blog=9605895&amp;post=32&amp;subd=dotnetfundas&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dotnetfundas.wordpress.com/2010/02/09/interops-net-and-mono/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccf82f9e698e4fa268617eb083c04a68?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotnetinternals</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/02/corbettnationalparkphotobyajeygodbole_thumb.jpg" medium="image">
			<media:title type="html">@Corbett National Park,Photo by Ajey godbole</media:title>
		</media:content>
	</item>
		<item>
		<title>.NET &lt;-&gt; Java Interoperability</title>
		<link>http://dotnetfundas.wordpress.com/2010/02/09/net-java-interoperability/</link>
		<comments>http://dotnetfundas.wordpress.com/2010/02/09/net-java-interoperability/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 19:15:19 +0000</pubDate>
		<dc:creator>Abhijeet Kulkarni</dc:creator>
				<category><![CDATA[Interops]]></category>

		<guid isPermaLink="false">http://dotnetfundas.wordpress.com/2010/02/09/net-java-interoperability/</guid>
		<description><![CDATA[&#160; &#160; As we have been discussing this earlier necessity of Interoperability arises in various cases such as Reuse of existing systems Proof of concepts Migration To maintain lower project costs by using existing legacy apps. Considering above key points, lets check out some of the important aspects related to .NET and Java Interoperability. While [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetfundas.wordpress.com&amp;blog=9605895&amp;post=29&amp;subd=dotnetfundas&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p><a href="http://dotnetfundas.files.wordpress.com/2010/02/jugaadphotobyajeygodbole.jpg"><img style="display:inline;border-width:0;" title="Jugaad,Photo by Ajey godbole" src="http://dotnetfundas.files.wordpress.com/2010/02/jugaadphotobyajeygodbole_thumb.jpg?w=450&#038;h=399" alt="Jugaad,Photo by Ajey godbole" width="450" height="399" border="0" /></a></p>
<p>&nbsp;</p>
<p>As we have been discussing this earlier necessity of Interoperability arises in various cases such as</p>
<ol>
<li>Reuse of existing systems</li>
<li>Proof of concepts</li>
<li>Migration</li>
<li>To maintain lower project costs by using existing legacy apps.</li>
</ol>
<p>Considering above key points, lets check out some of the important aspects related to .NET and Java Interoperability.</p>
<p>While referring to various web sites for practical options available in  .NET and Java Interoperability,  I came across some info given on <a href="http://www.codeproject.com/KB/dotnet/Espresso.aspx">code project</a> written by <em>Guy Balteriski.</em> This article talks in depth about various aspects related to .NET and Java Interoperability such as</p>
<ol>
<li>Part I: Introduction to Java &amp; .NET interoperability and the suggested solution</li>
<li>Part II: Implement .NET proxy to the Java classes</li>
<li>Part III: Using Attributes to extend the Java API solution</li>
<li>Part IV: Java to .NET API calls</li>
<li>Part V: Implement Java proxy to the .NET classes</li>
<li>Part VI: Adding Annotations to extend the .NET API solution</li>
</ol>
<p><a href="http://dotnetfundas.files.wordpress.com/2010/02/jninetruntimearch.gif"><img style="display:inline;border-width:0;" title="JniNetRuntimeArch" src="http://dotnetfundas.files.wordpress.com/2010/02/jninetruntimearch_thumb.gif?w=450&#038;h=268" alt="JniNetRuntimeArch" width="450" height="268" border="0" /></a></p>
<p>A must see website on this topic is <a href="http://www.jnbridge.com/">jnbridge</a>.</p>
<p>This <a href="http://msdn.microsoft.com/en-us/library/ms953968.aspx">MSDN</a> example shows  Java/.NET Interoperability with the Microsoft.com Web Service.</p>
<p>Overall with this frameworks and other options a true blend of interoperability can be achieved between Java and .NET for delivering real time problem scenarios.</p>
<p>Hope this helps !</p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetfundas.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetfundas.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetfundas.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetfundas.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dotnetfundas.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dotnetfundas.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dotnetfundas.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dotnetfundas.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetfundas.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetfundas.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetfundas.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetfundas.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetfundas.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetfundas.wordpress.com/29/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetfundas.wordpress.com&amp;blog=9605895&amp;post=29&amp;subd=dotnetfundas&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dotnetfundas.wordpress.com/2010/02/09/net-java-interoperability/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccf82f9e698e4fa268617eb083c04a68?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotnetinternals</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/02/jugaadphotobyajeygodbole_thumb.jpg" medium="image">
			<media:title type="html">Jugaad,Photo by Ajey godbole</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/02/jninetruntimearch_thumb.gif" medium="image">
			<media:title type="html">JniNetRuntimeArch</media:title>
		</media:content>
	</item>
		<item>
		<title>Interops &#8211; Inter Language Approach</title>
		<link>http://dotnetfundas.wordpress.com/2010/01/04/interops-inter-language-approach/</link>
		<comments>http://dotnetfundas.wordpress.com/2010/01/04/interops-inter-language-approach/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 16:42:21 +0000</pubDate>
		<dc:creator>Abhijeet Kulkarni</dc:creator>
				<category><![CDATA[Interops]]></category>

		<guid isPermaLink="false">http://dotnetfundas.wordpress.com/2010/01/04/interops-inter-language-approach/</guid>
		<description><![CDATA[Technorati Tags: Interops In my previous posts we saw important aspects regarding Interops-Why and Ways to do it Interops-Win32&#60;-&#62;.NET Interops-COM&#60;-&#62;.NET Moving further into world of interops lets now check some of  interesting aspects of Interlanguage interoperability on .NET framework. The problems of interoperability have been around for many years and I found this useful info [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetfundas.wordpress.com&amp;blog=9605895&amp;post=24&amp;subd=dotnetfundas&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://dotnetfundas.files.wordpress.com/2010/01/diwali09.jpg"><img style="display:inline;border-width:0;" title="Diwali '09" src="http://dotnetfundas.files.wordpress.com/2010/01/diwali09_thumb.jpg?w=399&#038;h=288" alt="Diwali '09" width="399" height="288" border="0" /></a></p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:d8fec051-05bf-403a-85ea-743de9611524" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">Technorati Tags: <a href="http://technorati.com/tags/Interops" rel="tag">Interops</a></div>
<p>In my previous posts we saw important aspects regarding</p>
<ol>
<li><a href="http://dotnetfundas.wordpress.com/2009/09/28/interops-why-and-ways-to-do-it/">Interops-Why and Ways to do it</a></li>
<li><a href="http://dotnetfundas.wordpress.com/2009/10/06/interops-win32-net/">Interops-Win32&lt;-&gt;.NET</a></li>
<li><a href="http://dotnetfundas.wordpress.com/2009/10/12/interops-com-net/">Interops-COM&lt;-&gt;.NET</a></li>
</ol>
<p>Moving further into world of interops lets now check some of  interesting aspects of Interlanguage interoperability on .NET framework.</p>
<p>The problems of interoperability have been around for many years and I found this useful info on <a href="http://msdn.microsoft.com/en-us/library/ms973862.aspx">MSDN</a> which describes number of standards and architectures developed to address this issues</p>
<ol>
<li>Representation Standards</li>
<li>Architecture Standards</li>
<li>Language Standards</li>
<li>Execution Environments</li>
</ol>
<p><strong><span style="text-decoration:underline;">Representation Standards </span></strong></p>
<p>External Data Representation(XDR) and Network Data Representation (NDR ), address the issue of passing data types between different machines. ( e.g. big-endian issues, little-endian issues,  and different word sizes)</p>
<p><span style="text-decoration:underline;"><strong>Architecture Standards</strong></span></p>
<p><a href="http://msdn.microsoft.com/en-us/library/aa373935(VS.85).aspx">Remote Procedure Call by Distributed Computing Environment</a></p>
<p><a href="http://java.sun.com/developer/onlineTraining/corba/corba.html">Common Object Request Broker Architecture</a></p>
<p><a href="http://www.microsoft.com/com/default.mspx">Component Object Model</a></p>
<p>All these standards handle issues of calling methods across language, process and machine boundaries.</p>
<p><strong><span style="text-decoration:underline;">Language Standards</span></strong></p>
<p><span style="text-decoration:underline;"><a href="http://msdn.microsoft.com/en-us/netframework/aa569283.aspx">ECMA C# and Common Language Infrastructure Standards</a></span></p>
<p><a href="http://en.wikipedia.org/wiki/ANSI_C">ANSI C standards</a> which allow distribution of source code across compilers and machines.</p>
<p><strong><span style="text-decoration:underline;">Execution Environments</span></strong></p>
<p><a href="http://msdn.microsoft.com/en-us/library/8bs2ecf4(VS.71).aspx">Common Language Runtime</a></p>
<p><a href="http://en.wikipedia.org/wiki/Dynamic_Language_Runtime">Dynamic Language Runtime</a></p>
<p>Referring to CLR info on MSDN we can easily figure out it consists of 3 main components</p>
<ol>
<li>Common Type System which supports many of the operations found in modern programming languages.</li>
<li>A metadata system, which allows metadata to be persisted with types at compile time and the used by execution system at run time.</li>
<li>A execution system which allows which allows .NET programs execution providing features such as memory management.</li>
</ol>
<p>Dynamic Language Runtime provides following services</p>
<ol>
<li>A dynamic type system</li>
<li>Dynamic method dispatch</li>
<li>Dynamic code generation</li>
<li>Hosting API</li>
</ol>
<p>DLR is used to implement dynamic languages like Python and Ruby on the .NET framework.</p>
<p>There are still interesting aspects to be covered in interoperability and I will be covering it in next two posts. Keep visiting <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetfundas.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetfundas.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetfundas.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetfundas.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dotnetfundas.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dotnetfundas.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dotnetfundas.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dotnetfundas.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetfundas.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetfundas.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetfundas.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetfundas.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetfundas.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetfundas.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetfundas.wordpress.com&amp;blog=9605895&amp;post=24&amp;subd=dotnetfundas&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dotnetfundas.wordpress.com/2010/01/04/interops-inter-language-approach/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccf82f9e698e4fa268617eb083c04a68?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotnetinternals</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2010/01/diwali09_thumb.jpg" medium="image">
			<media:title type="html">Diwali '09</media:title>
		</media:content>
	</item>
		<item>
		<title>Interops &#8211; COM &lt;-&gt; .NET</title>
		<link>http://dotnetfundas.wordpress.com/2009/10/12/interops-com-net/</link>
		<comments>http://dotnetfundas.wordpress.com/2009/10/12/interops-com-net/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 18:02:09 +0000</pubDate>
		<dc:creator>Abhijeet Kulkarni</dc:creator>
				<category><![CDATA[Interops]]></category>

		<guid isPermaLink="false">http://dotnetfundas.wordpress.com/2009/10/12/interops-com-net/</guid>
		<description><![CDATA[In my last post I mentioned , There are two ways that C# code can directly call unmanaged code: Directly call a function exported from DLL Call an interface method on a COM object In this post lets concentrate on how to call an interface method on a COM object and how this can be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetfundas.wordpress.com&amp;blog=9605895&amp;post=20&amp;subd=dotnetfundas&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://dotnetfundas.files.wordpress.com/2009/10/mysore.jpg"><img style="display:inline;border-width:0;" title="@Mysore" src="http://dotnetfundas.files.wordpress.com/2009/10/mysore_thumb.jpg?w=268&#038;h=325" alt="@Mysore" width="268" height="325" border="0" /></a></p>
<p>In my last post I mentioned ,</p>
<p>There are two ways that C# code can directly call unmanaged code:</p>
<ol>
<li>Directly call a function exported from DLL</li>
<li>Call an interface method on a COM object</li>
</ol>
<p>In this post lets concentrate on how to call an interface method on a COM object and how this can be implemented for managed environment.</p>
<p>.NET framework provides following facilities to perform COM Interop</p>
<ol>
<li>Creating COM objects</li>
<li>Determining if a COM interface is implemented by an object</li>
<li>Calling methods on COM interfaces</li>
<li>Implementing objects and interfaces that can be called by COM clients.</li>
</ol>
<p>Additionally, .NET framework also handles reference counting issues with COM Interop so there is no need to call or implement Addref and Release.</p>
<p>COM Interop provides access to existing COM components without requiring that the original components need to be modified and for this we can use a COM Interop utility (Tlbimp.exe).  <a href="http://msdn.microsoft.com/en-us/library/tt0cf3sx(VS.80).aspx">Type library importer</a> converts the type definitions found within a COM type library into equivalent definitions in a CLR assembly.</p>
<p>Type library Importer performs following conversions :</p>
<ol>
<li>COM coclasses are converted to C# classes with a parameter less constructor</li>
<li>COM structs are converted to C# structs with public fields.</li>
</ol>
<p><a href="http://msdn.microsoft.com/en-us/library/f7dy01k1(VS.80).aspx">Microsoft Intermediate Language Disassembler</a> provides a great way to check out the output of Tlbimp.exe to view the result of the conversion.</p>
<p>In addition to this, COM Interop allows programmers to access managed objects as easily as they access other COM objects Here COM Interop provides a <a href="http://msdn.microsoft.com/en-us/library/tzat5yw6(VS.71).aspx">Assembly Registration Tool</a>  that exports the managed types into a type library and registers the managed component as a traditional COM component.</p>
<p>I referred <a href="http://msdn.microsoft.com/en-us/library/aa645736(VS.71).aspx#vcwlkcominteroptutorialcreatinganunmanagedcomclasswrapper">MSDN</a> for following steps and key points are as follows</p>
<p><strong><span style="text-decoration:underline;">Creating a COM Class Wrapper</span></strong></p>
<p>Tlbimp converts a COM type library into .NET framework metadata- effectively creating a managed wrapper that can be called from any managed language.</p>
<ol>
<li>.NET framework metadata created with Tlbimp can be included in a C# build via /R compiler option.</li>
<li>Using Visual Studio we need to add only COM type library and conversion is done automatically.</li>
</ol>
<p>Important attributes in understanding COM mapping are</p>
<ol>
<li>ComImport</li>
<li>GUID</li>
<li>Interface Type</li>
<li>PreserveSig</li>
</ol>
<p><strong><span style="text-decoration:underline;">Declaring and Creating Comcoclass object</span></strong></p>
<p>COM coclasses are represented as a classes with parameterless constructors  in C#. ComImport attribute is a must for them. Creating instance of this class using the new operator is the C# equivalent of calling CoCreateInstance.</p>
<p>Additional restrictions are as follows</p>
<ol>
<li>The class must not inherit from any other class</li>
<li>The class must implement no interfaces</li>
<li>GUID for the class</li>
</ol>
<p><strong><span style="text-decoration:underline;">Declaring a COM Interface</span></strong></p>
<ol>
<li>COM interfaces are represented in C# as interfaces with COMImport and GUID attributes.</li>
<li>COM Interfaces declared in C# must include declarations for all members of their base interfaces with the exception of members of IUnknown and IDispatch. These are added by .NET framework automatically.</li>
<li>COM interfaces which derive from IDispatch must be marked with the InterfaceType attribute.</li>
<li>When calling a COM interface method from C# code, CLR runtime must marshal the parameters and return values to/ from the COM object.</li>
<li>Common way to return success or failure is to return an HRESULT and have an out paramter marked as “retval” in MIDL for the real return value of method.</li>
</ol>
<p>Apart from this following are the links, one should must see for        COM &lt;-&gt; .NET interoperability given on MSDN</p>
<p><a href="http://msdn.microsoft.com/en-us/magazine/cc163494.aspx">Introduction to COM Interop</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/aa645736(VS.71).aspx#vcwlkcominteroppart1cclienttutorialanchor1">COM Interop Part 1: C# Client Tutorial</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/aa645738(VS.71).aspx">COM Interop Part 2: C# Server Tutorial</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/f07c8z1c(VS.71).aspx">COM Callable Wrapper</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/zsfww439(VS.71).aspx">Exposing .NET Framework Components to COM</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/bd9cdfyx(VS.80).aspx">Advanced COM Interoperability</a></p>
<p><a href="http://msdn.microsoft.com/en-us/magazine/cc188708.aspx">Simplify App Deployment with ClickOnce and Registration-Free COM</a></p>
<p>I will be writing few more posts on Interops and some of the interesting aspects discovered using this. Meanwhile, do let me know your feedback and expectations from this blog.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetfundas.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetfundas.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetfundas.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetfundas.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dotnetfundas.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dotnetfundas.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dotnetfundas.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dotnetfundas.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetfundas.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetfundas.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetfundas.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetfundas.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetfundas.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetfundas.wordpress.com/20/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetfundas.wordpress.com&amp;blog=9605895&amp;post=20&amp;subd=dotnetfundas&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dotnetfundas.wordpress.com/2009/10/12/interops-com-net/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccf82f9e698e4fa268617eb083c04a68?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotnetinternals</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2009/10/mysore_thumb.jpg" medium="image">
			<media:title type="html">@Mysore</media:title>
		</media:content>
	</item>
		<item>
		<title>Interops &#8211; Win32 &lt;-&gt; .NET</title>
		<link>http://dotnetfundas.wordpress.com/2009/10/06/interops-win32-net/</link>
		<comments>http://dotnetfundas.wordpress.com/2009/10/06/interops-win32-net/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 21:32:50 +0000</pubDate>
		<dc:creator>Abhijeet Kulkarni</dc:creator>
				<category><![CDATA[Interops]]></category>

		<guid isPermaLink="false">http://dotnetfundas.wordpress.com/2009/10/06/interops-win32-net/</guid>
		<description><![CDATA[Technorati Tags: Win32,.NET As discussed in my first post , a common scenario where Interops are needed is accessing a legacy code written using Win32 APIs  in .NET applications for various reasons. There are two ways that C# code can directly call unmanaged code: Directly call a function exported from DLL Call an interface method [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetfundas.wordpress.com&amp;blog=9605895&amp;post=16&amp;subd=dotnetfundas&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://dotnetfundas.files.wordpress.com/2009/10/lamp.jpg"><img style="display:inline;border-width:0;" title="lamp" src="http://dotnetfundas.files.wordpress.com/2009/10/lamp_thumb.jpg?w=244&#038;h=184" alt="lamp" width="244" height="184" border="0" /></a></p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:258f1022-06b3-48d8-a9a0-ddf042591f30" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">Technorati Tags: <a href="http://technorati.com/tags/Win32" rel="tag">Win32</a>,<a href="http://technorati.com/tags/.NET" rel="tag">.NET</a></div>
<p>As discussed in my first post , a common scenario where Interops are needed is accessing a legacy code written using Win32 APIs  in .NET applications for various reasons.</p>
<p>There are two ways that C# code can directly call unmanaged code:</p>
<ol>
<li>Directly call a function exported from DLL</li>
<li>Call an interface method on a COM object</li>
</ol>
<p>Luckily <a href="http://msdn.microsoft.com/en-us/library/aa288468(VS.71).aspx">Platform Invoke</a> (P/Invoke) service provided by .NET framework supports invoking unmanaged code residing in DLLs to be called in .NET environment.</p>
<p>C# provides a mechanism for providing declarative tags, called attributes which can be placed in certain entities in source code to specify additional information. Information contained in attributes can be ret rived through reflection, or one can use predefined attributes.</p>
<p>Use of DllImport can be made as follows in C# for calling MathFuncimportClass from unmanaged DLL.</p>
<table width="400" border="0" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td valign="top" width="400">[DllImport] public class MathFuncimportClass { &#8230; }</td>
</tr>
</tbody>
</table>
<p>In addition to this , we can have few named parameters as well as unnamed(positional) parameters.</p>
<table width="469" border="0" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td valign="top" width="467">[DllImport("user32.dll", SetLastError=false,ExactSpelling=false)]<br />
[DllImport("user32.dll", ExactSpelling=false,SetLastError=false)]<br />
[DllImport("user32.dll")]</td>
</tr>
</tbody>
</table>
<p>For a broader look one must have a reading of <a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute_members.aspx">DllImportAttribute Members</a></p>
<p>An excellent info on EntryPoint, Charset, SetLastError and CallingConventions is given on <a href="http://msdn.microsoft.com/en-us/magazine/cc164123.aspx#S5">Jason Clark’s post</a> on MSDN Magazine. These are all optional properties in DllImportAttribute.</p>
<p><strong><span style="text-decoration:underline;">Data Marshaling </span></strong></p>
<p>While transferring data between managed and unmanaged combination of code , CLR follows number of rules that one must know so as to tackle any tricky scenario.</p>
<p>While passing parameter to a Windows API function important points needs to be considered as follows</p>
<ol>
<li>Is the data in a form of integer or float ?</li>
<li>Is the data signed integer or unsigned integer ?</li>
<li>Bitwise presentation of integer data</li>
<li>Floating point data and its precision.</li>
</ol>
<p>Some special scenarios encountered while marshalling are</p>
<ol>
<li>Marshaling pointers</li>
<li>Marshaling Opaque pointers</li>
<li>Marshaling Text</li>
<li>Marshaling a complex structure.</li>
</ol>
<p>A detailed explanation for all these four points is here on <a href="http://msdn.microsoft.com/en-us/magazine/cc164193.aspx">MSDN Magazine.</a> Figure 4 on this link also describes actual MSIL signature seen by CLR in various cases.</p>
<p><strong><span style="text-decoration:underline;">Copying and Pinning</span></strong></p>
<p>While CLR performs Data Marshaling , it used two options <a href="http://msdn.microsoft.com/hi-in/23acw07k(en-us).aspx">copying and pinning</a> .</p>
<p>1) While marshaling the data, the interop marshaler can copy or pin the data being marshaled. Copying the data will place a copy of data from one memory to another memory location.</p>
<p><a href="http://msdn.microsoft.com/hi-in/23acw07k(en-us).aspx">Value types passed by value and by reference</a> explains this scenario.</p>
<p>2) Pinning temporarily locks the data in its current memory location, and thus it is kept away from relocating by CLR’s garbage collector.</p>
<p>A clear scenario can be visualized here at <a href="http://msdn.microsoft.com/hi-in/23acw07k(en-us).aspx">Reference types passed by value and by reference</a></p>
<p><strong><span style="text-decoration:underline;">P/Invoke Interop Assistant</span></strong></p>
<p>For quickly figuring out the P/Invoke signature for Win32 API function PInvoke Interop Assistant can be very useful. This tool assists developers with conversion from C++ to managed P/Invoke signatures and vice a versa.</p>
<p>This tool is available for <a href="http://www.codeplex.com/clrinterop/Release/ProjectReleases.aspx?ReleaseId=14120">download</a> on codeplex website.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetfundas.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetfundas.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetfundas.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetfundas.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dotnetfundas.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dotnetfundas.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dotnetfundas.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dotnetfundas.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetfundas.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetfundas.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetfundas.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetfundas.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetfundas.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetfundas.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetfundas.wordpress.com&amp;blog=9605895&amp;post=16&amp;subd=dotnetfundas&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dotnetfundas.wordpress.com/2009/10/06/interops-win32-net/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccf82f9e698e4fa268617eb083c04a68?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotnetinternals</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2009/10/lamp_thumb.jpg" medium="image">
			<media:title type="html">lamp</media:title>
		</media:content>
	</item>
		<item>
		<title>Interops &#8211; Why and Ways to do it</title>
		<link>http://dotnetfundas.wordpress.com/2009/09/28/interops-why-and-ways-to-do-it/</link>
		<comments>http://dotnetfundas.wordpress.com/2009/09/28/interops-why-and-ways-to-do-it/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 12:46:48 +0000</pubDate>
		<dc:creator>Abhijeet Kulkarni</dc:creator>
				<category><![CDATA[Interops]]></category>

		<guid isPermaLink="false">http://dotnetfundas.wordpress.com/2009/09/28/interops-why-and-ways-to-do-it/</guid>
		<description><![CDATA[Technorati Tags: Interops For next few days I intend to write about various aspects of .Net Interops and different scenarios where Interops are extremely useful. Before moving ahead to interops lets first check out some of the important terminologies in .NET . Managed Code and Data : Code developed on .NET platform (e.g. code in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetfundas.wordpress.com&amp;blog=9605895&amp;post=9&amp;subd=dotnetfundas&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://dotnetfundas.files.wordpress.com/2009/09/westernthali.jpg"><img style="display:inline;border-width:0;" title="Western Thali" src="http://dotnetfundas.files.wordpress.com/2009/09/westernthali_thumb.jpg?w=244&#038;h=184" alt="Western Thali" width="244" height="184" border="0" /></a></p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:8c9d48d2-9838-48ad-8eae-2facaa75cf4e" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">Technorati Tags: <a href="http://technorati.com/tags/Interops" rel="tag">Interops</a></div>
<p>For next few days I intend to write about various aspects of .Net Interops and different scenarios where Interops are extremely useful.</p>
<p>Before moving ahead to interops lets first check out some of the important terminologies in .NET .</p>
<p><strong>Managed Code and Data :</strong></p>
<p>Code developed on .NET platform (e.g. code in C#,VB.NET etc) is referred to as managed code and contains some metadata which is used for Common Language Runtime. ( for more info visit  <a href="http://blogs.msdn.com/clrteam" target="_blank">CLR Team Blog</a> ) Data used by .NET applications is called managed data , since .NET runtime manages data-related tasks such as allocating and reclaiming memory, and type checking.  By default code and data used by .NET applications is managed and while accessing the unmanaged code and data e.g. COM objects we can use interop assemblies which will be discussed in later part of this post.</p>
<p><strong>Assemblies :</strong></p>
<p>A primary building block of .NET application is referred to as assembly. It is a collection of functionality that is built, versioned and deployed as a single implementation unit containing one or more files. Each assembly contains a assembly manifest. Every assembly whether static or dynamic contains collection of data that describes how the elements in the assembly relate to each other. The metadata contained in assembly is needed to specify the assembly’s version requirements and security identity. The assembly manifest can be stored in either a PE file ( an .exe or .dll ) with Microsoft intermediate language (MSIL) code or in a standalone PE file that contains only assembly manifest information.  ( A must see article on assemblies is here  <a href="http://msdn.microsoft.com/en-us/library/1w45z383(VS.71).aspx" target="_blank">MSDN</a> )</p>
<p><strong>Type Libraries and Assembly Manifests :</strong></p>
<p>A type library declares the classes , interfaces , constants and procedures that are exposed by an application or dynamic link library ( DLL ) . A type library is usually a resource in a program file. It can also be a stand-alone binary file with the extension .tlb or .olb . Manifests also include information about</p>
<ol>
<li>Assembly identity, version, culture and digital signature</li>
<li>Files that make up the assembly implementation</li>
<li>Types and resources that make up the assembly, including those</li>
<li>that are exported from it</li>
<li>Compile-time dependencies on other assemblies.</li>
<li>Permissions required to run the assemblies to run properly.</li>
</ol>
<p>For importing information from a type library into .NET application Visual Studio.NET contains a utility called as Tlbimp.exe.  ( more information is given <a href="http://http://msdn.microsoft.com/en-us/library/tt0cf3sx(VS.71).aspx" target="_blank">here</a>. )</p>
<p><strong>Why Interops ?</strong></p>
<p>While implementing solutions for various problem statements there is a necessity of invoking features provided by other applications or interaction with APIs provided to invoke important services or features.</p>
<p>Following may be some of the scenarios where interops are required</p>
<ol>
<li>Invoking Win32 apps in .NET</li>
<li>Invoking COM components in application.</li>
<li>Invoking features of MS Office.</li>
<li>Invoking inter language communication</li>
<li>Invoking features of .NET on other platforms.</li>
<li>Invoking functionality provided by a native code where a conversion process is necessary to translate argument data between managed code and native code.</li>
</ol>
<p><strong>Ways to implement Interops :</strong></p>
<p>Having seen some of the basic  reasons why interoperability is required , lets see some of the ways these interops can be implemented.</p>
<p><strong><span style="text-decoration:underline;">PIAs </span></strong></p>
<p>Primary Interop Assembly is a unique, vendor supplied assembly that contains type definitions ( as metadata) of types implemented with COM. There can be only one Primary Interop Assembly , which must be signed with a strong name by the publisher of COM type library. A single primary interop assembly can wrap more than one version of the same type library.</p>
<p>Primary Interop Assemblies must meet following requirements</p>
<ol>
<li>Include all COM types defined in the original type library and maintain the same GUID identities.</li>
<li>Be signed with a strong name using standard public key cryptography</li>
<li>Contain the PrimaryInteropAssemblyAttribute.</li>
<li>Avoid redefining external COM types.</li>
<li>Reference other primary interop assemblies for external for external COM dependencies.</li>
</ol>
<p>Having a single type definition ensures that all .NET framework applications bind to the same type at compile time, and that the type is marshaled the same way at run time. It is important to create only one primary interop assembly for each COM type library because multiple assemblies can introduce type incompatibility.</p>
<p>There are several other aspects with PIA such as</p>
<ol>
<li>Naming a primary interop assembly</li>
<li>Generating a primary interop assembly</li>
<li>Customizing a primary interop assembly</li>
<li>Distributing a primary interop assembly</li>
</ol>
<p><a href="http://msdn.microsoft.com/en-us/library/hfac4fky.aspx" target="_blank">MSDN</a> explains in-depth approach of all these points.</p>
<p>Office XP PIAs can be downloaded <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=C41BD61E-3060-4F71-A6B4-01FEBA508E52&amp;displaylang=en#QuickInfoContainer" target="_blank">here</a> .</p>
<p><strong><span style="text-decoration:underline;">System.Runtime.InteropServices Namespace</span></strong></p>
<p>System.Runtime.InteropServices namespace provide a wide variety of members that support COM interop and platform invoke services.</p>
<p>A <a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.aspx" target="_blank">detailed description</a> of its classes and structures is given on MSDN which covers all the aspects about using this namespace and is a must read chapter for everyone who wants to cover this concepts in a systematic approach.</p>
<p><span style="text-decoration:underline;"><strong>Platform Invoke</strong></span></p>
<p>Platform Invoke services ( commonly referred as P/Invoke) allows managed code to call unmanaged functions that are implemented in a DLL.</p>
<p>Important aspects one must consider while using P/Invoke are</p>
<ol>
<li><a href="http://msdn.microsoft.com/en-us/library/48zeb25s(VS.71).aspx" target="_blank">Using Attributes</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute(VS.71).aspx" target="_blank">DllImportAttribute Class</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshalasattribute(VS.71).aspx" target="_blank">MarshalAsAttribute Class</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.structlayoutattribute(VS.71).aspx" target="_blank">StructLayoutAttribute Class</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.inattribute(VS.71).aspx" target="_blank">InAttribute Class</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.outattribute(VS.71).aspx" target="_blank">OutAttribute Class</a></li>
</ol>
<p><strong><span style="text-decoration:underline;">Java and .NET interoperability</span></strong></p>
<p>With <a href="http://blogs.msdn.com/interoperability/archive/2009/09/28/new-bridge-broadens-java-and-net-interoperability.aspx" target="_blank">Restlet</a> lightweight open source project its now possible to use lightweight REST framework for Java that used Restlet extension for ADO.NET Data Services.</p>
<p>More info about Restlet open source project is <a href="http://www.restlet.org/" target="_blank">here</a></p>
<p>In coming articles I will be explaining all of these ways in detail and resources that one must have a look for covering several effective practices while using Interops. I will also be covering various areas where these interops can be used.</p>
<p>Do let me know all of your suggestions and areas to be covered in this post.</p>
<p>Keep Visiting !!</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetfundas.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetfundas.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetfundas.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetfundas.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dotnetfundas.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dotnetfundas.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dotnetfundas.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dotnetfundas.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetfundas.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetfundas.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetfundas.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetfundas.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetfundas.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetfundas.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetfundas.wordpress.com&amp;blog=9605895&amp;post=9&amp;subd=dotnetfundas&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dotnetfundas.wordpress.com/2009/09/28/interops-why-and-ways-to-do-it/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccf82f9e698e4fa268617eb083c04a68?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotnetinternals</media:title>
		</media:content>

		<media:content url="http://dotnetfundas.files.wordpress.com/2009/09/westernthali_thumb.jpg" medium="image">
			<media:title type="html">Western Thali</media:title>
		</media:content>
	</item>
	</channel>
</rss>
