<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;D0YBR3w_eip7ImA9WhRbGEw.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408</id><updated>2012-02-10T00:49:16.242+05:30</updated><category term="Decompiler" /><category term="VS 2010" /><category term="Bug" /><category term="DataTable" /><category term="Surface Tag" /><category term="VC++" /><category term="Route" /><category term="Trace" /><category term="CodeDom" /><category term="ASP.NET" /><category term="System Programming" /><category term="Scripting" /><category term="Async programming" /><category term="Web Development" /><category term="Goto" /><category term=".Net 3.5" /><category term="Assembly Language" /><category term="sql query" /><category term="Design Time" /><category term="Extension Methods" /><category term="Debugging" /><category term="MOSS" /><category term=".bat file" /><category term="MSACCESS" /><category term="ExpandoObject" /><category term="Surface IdentityTag" /><category term="Threading" /><category term="VS 2008" /><category term="FaultContract" /><category term="jQuery" /><category term="MySQL" /><category term="Azure Development" /><category term="object" /><category term="Logging" /><category term="Keyword" /><category term="Web.config" /><category term="Cmdlet" /><category term="XML" /><category term="Tips" /><category term="Windows PowerShell" /><category term="IIS" /><category term="WSS" /><category term="Rest" /><category term="Custom Controls" /><category term="C# Keywords" /><category term="iPhone" /><category term="Array" /><category term="WebParts" /><category term="Agile" /><category term="Expression" /><category term="VB.Net" /><category term="Arithmetic Expression" /><category term="TFS Programming" /><category term="CLR" /><category term="MVC" /><category term="javascript" /><category term="URL Rewriting" /><category term="VS 2005" /><category term="dynamic" /><category term="CAB" /><category term="Loginless User" /><category term="RSS Feed" /><category term="AppFabric" /><category term="Puzzle" /><category term="Azure" /><category term="Garbage Collector" /><category term="HTML 5" /><category term="Windows Phone" /><category term="Exception" /><category term="MSEXCEL" /><category term="Objective-C" /><category term="Windows Azure" /><category term="SQL Profiler" /><category term="Transaction" /><category term="Windows Forms" /><category term="Application Design" /><category term="Delegate" /><category term="Cloud Computing" /><category term="SOS" /><category term="TFS" /><category term="Microsoft surface" /><category term=".Net 4" /><category term="COM" /><category term="RegEx" /><category term="Caching" /><category term="Generics" /><category term="sql server" /><category term="DataRow" /><category term="var" /><category term="C#" /><category term="Algorithm" /><category term="Reflection" /><category term="HttpModule" /><category term="SEO" /><category term="WCF" /><category term="sql" /><category term="Database" /><category term="Linq" /><category term="RAZOR" /><category term="RegularExpressions" /><category term="Sharepoint" /><category term="SSRS 2008" /><category term="PropertyBag" /><category term="iPad" /><category term="FaultException" /><category term="Silverlight" /><category term="DOS" /><title>Joymon V/S Code</title><subtitle type="html">Here you can see software programming related articles,tips and sample code snippets.You can see a wide variety of topics other than WPF &amp;amp; Silverlight for which I am running separate blogs.</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://joymonscode.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>119</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/JoymonV/sCode" /><feedburner:info uri="joymonv/scode" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;CkMEQH46eip7ImA9WhRbEE4.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-4498508636001172540</id><published>2012-01-31T22:50:00.000+05:30</published><updated>2012-01-31T22:50:01.012+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-31T22:50:01.012+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Windows Phone" /><category scheme="http://www.blogger.com/atom/ns#" term="Tips" /><title>How can I use keyboard in Windows Phone 7 simulator ?</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/CWjNTMoIKCOumrdpqeZYlKDxhZU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/CWjNTMoIKCOumrdpqeZYlKDxhZU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/CWjNTMoIKCOumrdpqeZYlKDxhZU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/CWjNTMoIKCOumrdpqeZYlKDxhZU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
When I entered into the WP 7 development using the WP7 emulator, the first annoying behaviour noticed was the unavailability of machine keyboard support in the emulator. I had to use the visual keyboard popped up by the simulator. Our Windows Phone 7 application has integration with Azure and ACS which requires authentication every time I run the app. In other words that was the only part which really needs keyboard input. I don't know why I didn't google to get the keyboard support .May be I was in bad impression that the simulator always simulates in the real way.&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Days passed and the schedule became tight .Accidently I press on a key and I could see that it is accepting the physical keyboard entries. This made the development easier and didn't get much time to bother about the key which made that magic. Later the week I had to restart my machine and could see that the emulator is not at all accepting the keyboard. This made me to google for that magic key and it was "Page Up".&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Yes really there are some keyboard short cuts. Have a look at the below page for details&lt;/div&gt;
&lt;div&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/ff754352(v=VS.92).aspx"&gt;http://msdn.microsoft.com/en-us/library/ff754352(v=VS.92).aspx&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-4498508636001172540?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/jNHBojtSf8s" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/4498508636001172540/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=4498508636001172540" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/4498508636001172540?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/4498508636001172540?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/jNHBojtSf8s/how-can-i-use-keyboard-in-windows-phone.html" title="How can I use keyboard in Windows Phone 7 simulator ?" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2012/01/how-can-i-use-keyboard-in-windows-phone.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEUEQ3w6fip7ImA9WhRUFE8.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-8886318026117281465</id><published>2012-01-24T23:00:00.000+05:30</published><updated>2012-01-24T23:00:02.216+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-24T23:00:02.216+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term=".Net 4" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><title>Ultimate method to disable the viewstate of asp.net web page</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/qfvJeHZof1_843MYtIkiLNAWSjs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/qfvJeHZof1_843MYtIkiLNAWSjs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/qfvJeHZof1_843MYtIkiLNAWSjs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/qfvJeHZof1_843MYtIkiLNAWSjs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Recently I was working on a ASP.Net project template which can&amp;nbsp;accommodate&amp;nbsp;both asp.net web forms and MVC 3 screens together. I started with a MVC 3 application and added a web page .I could see that MVC3 template is missing some configurations in the web.config which makes it little difficult to work. Finally I could see the web forms running along with the MVC views after some changes. But when I put a button inside the webpage and wired its click event the things started breaking. The error I was getting tells about the view state.&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;The state information is invalid for this page and might be 
corrupted.&lt;/i&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;"&gt;&lt;b&gt;Description: 
&lt;/b&gt;An unhandled exception occurred during the execution of the current web 
request. Please review the stack trace for more information about the error and 
where it originated in the code. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Exception Details: 
&lt;/b&gt;System.Web.HttpException: The state information is invalid for this page and 
might be corrupted.&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style="font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;"&gt;With the stack trace as&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre&gt;[FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters. ]
   System.Convert.FromBase64String(String s) +0
   System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +77
   System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState) +4
   System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) +37
   System.Web.UI.HiddenFieldPageStatePersister.Load() +147

[ViewStateException: Invalid viewstate. 
 Client IP: ::1
 Port: 
 Referer: http://localhost:49849/WebForm1.aspx
 Path: /WebForm1.aspx
 User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
 ViewState: /wEPDwUKMjA0OTM4MTAwNGRk,/wEPDwUKMjA0OTM4MTAwNGRk]

[HttpException (0x80004005): The state information is invalid for this page and might be corrupted.]
   System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) +235
   System.Web.UI.ViewStateException.ThrowViewStateError(Exception inner, String persistedState) +14
   System.Web.UI.HiddenFieldPageStatePersister.Load() +251
   System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +106
   Mvc3TestApp.WebForm1.LoadPageStateFromPersistenceMedium() in E:\Joy\Code\DotNet\ASPDOTNET\MVC\Mvc3TestApp\Mvc3TestApp\WebForm1.aspx.cs:27
   System.Web.UI.Page.LoadAllState() +43
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +8431
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +253
   System.Web.UI.Page.ProcessRequest() +78
   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
   System.Web.UI.Page.ProcessRequest(HttpContext context) +49
   ASP.webform1_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\09b72d60\350d6099\App_Web_uhhehyfz.0.cs:0
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp;amp; completedSynchronously) +75
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Disabling ASP.Net page viewstate&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
I have compared the code and config with a newly created normal asp.net web forms application.But not able to find any difference. Then I decided to go with disabling the view state.&lt;br /&gt;
&lt;br /&gt;
As everybody does I disabled the view state at the page directive as follows&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 13px;"&gt;&lt;span style="background-attachment: initial; background-clip: initial; background-color: yellow; background-image: initial; background-origin: initial;"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="color: blue;"&gt;@&lt;/span&gt;&amp;nbsp;&lt;span style="color: maroon;"&gt;Page&lt;/span&gt;&amp;nbsp;&lt;span style="color: red;"&gt;Language&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"C#"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red;"&gt;AutoEventWireup&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"true"&lt;/span&gt;&amp;nbsp;
&lt;span style="color: red;"&gt;CodeBehind&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"WebForm1.aspx.cs"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red;"&gt;Inherits&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"Mvc3TestApp.WebForm1"&lt;/span&gt;&amp;nbsp;
&lt;span style="color: red;"&gt;Debug&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"true"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red;"&gt;EnableViewState&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"false"&lt;/span&gt;&amp;nbsp;
&lt;span style="color: red;"&gt;EnableViewStateMac&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"false"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red;"&gt;EnableSessionState&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"True"&lt;/span&gt;&amp;nbsp;
&lt;span style="color: red;"&gt;ViewStateMode&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"Disabled"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red;"&gt;ViewStateEncryptionMode&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"Never"&lt;/span&gt;&amp;nbsp;
&lt;span style="color: red;"&gt;EnableEventValidation&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"false"&lt;/span&gt;&amp;nbsp;&lt;span style="background-attachment: initial; background-clip: initial; background-color: yellow; background-image: initial; background-origin: initial;"&gt;%&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;pre style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 13px;"&gt;&lt;span style="background-attachment: initial; background-clip: initial; background-color: yellow; background-image: initial; background-origin: initial;"&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
It didn't fix the issue.Then I started disabling the view state for the controls present in the web page.Still the same error. Then I started google and could see some&lt;a href="http://renditionprotocol.blogspot.com/2007/01/state-information-is-invalid-for-this.html" target="_blank"&gt; ideas&lt;/a&gt; such as disabling in the web.config.But still the viewstate came and it was not able to deserialize properly.&lt;br /&gt;
&lt;br /&gt;
This makes me to do something myself and started debugging. After some time I could see that I can disable by overriding the&amp;nbsp;&lt;span style="background-color: white; font-family: Consolas; font-size: 13px;"&gt;LoadPageStateFromPersistenceMedium &lt;/span&gt;method. It was very simple.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 13px;"&gt;&lt;pre style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; font-family: Consolas;"&gt;&lt;span style="color: blue;"&gt;protected&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;override&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;object&lt;/span&gt;&amp;nbsp;LoadPageStateFromPersistenceMedium()
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;return&amp;nbsp;null;&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: green;"&gt;//return&lt;/span&gt;&amp;nbsp;&lt;span style="color: green;"&gt;base.LoadPageStateFromPersistenceMedium();&lt;/span&gt;
}&lt;/pre&gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-8886318026117281465?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/3ouUTAKzhFs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/8886318026117281465/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=8886318026117281465" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/8886318026117281465?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/8886318026117281465?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/3ouUTAKzhFs/ultimate-method-to-disable-viewstate-of.html" title="Ultimate method to disable the viewstate of asp.net web page" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2012/01/ultimate-method-to-disable-viewstate-of.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0IGQX0yfyp7ImA9WhRVGE8.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-3464410401708318935</id><published>2012-01-17T23:02:00.000+05:30</published><updated>2012-01-17T23:02:00.397+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-17T23:02:00.397+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="VS 2010" /><title>List of my favourite Visual Studio 2010 Extensions</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/yQHXLVZXL4OmXmD9tcD4DTBmTiA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yQHXLVZXL4OmXmD9tcD4DTBmTiA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/yQHXLVZXL4OmXmD9tcD4DTBmTiA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yQHXLVZXL4OmXmD9tcD4DTBmTiA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
There is no question that Visual &amp;nbsp;Studio is my&amp;nbsp;favourite, the most used and best code editor. Now I am using Visual Studio 2010 waiting for the final release of VSTS 2011. When we use VSTS 2010 sometime we feel that, it would be nice if it has one more feature which may increase our productivity. If you start feeling like that don't wait to open the Visual Studio Extension Manager.It will look as below and it is the place where you can get the desired features as extensions which are not delivered with VS 2010 where most of them are developed by third parties.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://www.danielmoth.com/Blog/ExtensionManagerDialog.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="313" src="http://www.danielmoth.com/Blog/ExtensionManagerDialog.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
Select the Online gallery and search for the words which match your interest.I am sure that you will find almost what you need. Just select and install from Extension Manager itself. When I used it I could see that it saved lot of time especially the spell check extension :-) .Below are some extensions I am using .Hope any .Net developer can use those to leverage his productivity.&lt;br /&gt;
&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/d0d33361-18e2-46c0-8ff2-4adea1e34fef/" target="_blank"&gt;Productivity Power Tools&lt;/a&gt;&amp;nbsp;- This brings you a new Tool window called Solution Navigator which is a much improved version of Solution Explorer.Using the Solution Navigator you can drill down till the method name and open the method directly. Also it comes with a good search mechanism and much more.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/7c8341f1-ebac-40c8-92c2-476db8d523ce" target="_blank"&gt;Spell Checker&lt;/a&gt; - This works like the office spell check and will surely help you to write method names without spelling mistake.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/e792686d-542b-474a-8c55-630980e72c30" target="_blank"&gt;Indent Guides&lt;/a&gt;&amp;nbsp;- Draws a line&amp;nbsp;vertically&amp;nbsp;to connect your braces.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/55c24bf1-2636-4f94-831d-28db8505ce00" target="_blank"&gt;Regex Editor&lt;/a&gt; - A handy utility to test regex patterns before checking in your code.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/c255a1e4-04ba-4f68-8f4e-cd473d6b971f" target="_blank"&gt;TFS Power Tools&lt;/a&gt; - If you are using Visual Studio TFS as code repository.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
NB: If you just google for visual studio 2010 extensions you will get tons of VS&amp;nbsp;&lt;a href="http://stackoverflow.com/questions/2757357/visual-studio-2010-recommended-extensions" target="_blank"&gt;extension lists like this&lt;/a&gt;. But use it, only if you think your system is capable enough to handle the extensions. Otherwise it will decrease your productivity.&lt;/div&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-3464410401708318935?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/1C5DeGxrYIw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/3464410401708318935/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=3464410401708318935" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/3464410401708318935?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/3464410401708318935?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/1C5DeGxrYIw/list-of-my-favourite-visual-studio-2010.html" title="List of my favourite Visual Studio 2010 Extensions" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2012/01/list-of-my-favourite-visual-studio-2010.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A04CQX8zeCp7ImA9WhRVEkw.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-8032222010133414384</id><published>2012-01-10T23:56:00.000+05:30</published><updated>2012-01-10T23:56:00.180+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-10T23:56:00.180+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Web Development" /><category scheme="http://www.blogger.com/atom/ns#" term="Tips" /><category scheme="http://www.blogger.com/atom/ns#" term="IIS" /><category scheme="http://www.blogger.com/atom/ns#" term=".Net 4" /><category scheme="http://www.blogger.com/atom/ns#" term="WCF" /><title>Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel' after WCF non-http activation in IIS 7.5 with .Net 4.0</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/2gxosqlOjfbOS0cyPtJIpMO-Zpo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2gxosqlOjfbOS0cyPtJIpMO-Zpo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/2gxosqlOjfbOS0cyPtJIpMO-Zpo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2gxosqlOjfbOS0cyPtJIpMO-Zpo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;em style="background-color: white; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 16px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;"Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'&lt;/em&gt;
&lt;br /&gt;
&lt;em style="background-color: white; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 16px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;br /&gt;&lt;/em&gt;&lt;br /&gt;
&lt;span style="background-color: white; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 16px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;/span&gt;&lt;/div&gt;
This is an error you may encounter when you configure your machine ie IIS 7.5 for &lt;a href="http://msdn.microsoft.com/en-us/library/ms731053.aspx"&gt;non-http activation to host WCF services&lt;/a&gt;.Initially I wonder what I did to reach this situation.But soon I realized that the relation between IIS and .Net 4.0 has broken and I need to register .Net 4.0 to IIS. Just used the famous &lt;a href="http://msdn.microsoft.com/en-us/library/k6h9cz8h(v=VS.100).aspx"&gt;aspnet_regiis.exe&lt;/a&gt; utility which is located at &amp;lt;%WindowsDir%&amp;gt;\Microsoft.NET\Framework\v4.0.30319.&lt;br /&gt;
&lt;br /&gt;
Mainly this happens when we install .Net framework 4.0 after IIS installation or activating non http wcf service support after IIS and .Net 4.0 installations.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-8032222010133414384?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/58Le4-AN8Js" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/8032222010133414384/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=8032222010133414384" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/8032222010133414384?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/8032222010133414384?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/58Le4-AN8Js/could-not-load-type-systemservicemodela.html" title="Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel' after WCF non-http activation in IIS 7.5 with .Net 4.0" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2012/01/could-not-load-type-systemservicemodela.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEECQXw9eSp7ImA9WhRWFUs.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-989790613023431280</id><published>2012-01-03T09:21:00.000+05:30</published><updated>2012-01-03T09:21:00.261+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-03T09:21:00.261+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="VS 2010" /><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><category scheme="http://www.blogger.com/atom/ns#" term="Web Development" /><category scheme="http://www.blogger.com/atom/ns#" term=".Net 4" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><category scheme="http://www.blogger.com/atom/ns#" term="RAZOR" /><title>Creating simple ASP.Net MVC 3 RAZOR application and adding a view to list users</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/_gHGpfp9h_9-2UGfmhGYyY3a89M/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_gHGpfp9h_9-2UGfmhGYyY3a89M/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/_gHGpfp9h_9-2UGfmhGYyY3a89M/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_gHGpfp9h_9-2UGfmhGYyY3a89M/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
I am really new to Razor the new view engine of ASP.Net MVC and decided to have a look at it during last weekend. First I started with what are the specialties&amp;nbsp;of RAZOR and could see that it is more simple than the traditional ASP.Net view engine. Then I searched for the &lt;a href="http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx"&gt;differences between the asp.net view engine and the Razor&lt;/a&gt; in terms of usage which will help me to write Razor view.Also I got the list which says how the &lt;a href="http://httputility.com/various/razorhelperscheatsheet.html"&gt;Razor view elements are converted to HTML elements&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Seems we are ready to taste RAZOR through a sample application. Again searched for creating simple razor application and got the link which explains how to create a user list with option such as edit,list...&lt;br /&gt;
&lt;a href="http://www.asp.net/mvc/tutorials/overview/creating-a-mvc-3-application-with-razor-and-unobtrusive-javascript"&gt;http://www.asp.net/mvc/tutorials/overview/creating-a-mvc-3-application-with-razor-and-unobtrusive-javascript&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
But it looks little complicated to me as we need to create model and all. So decided to just list down the user list from Membership provider.Steps goes as follows.&lt;br /&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;Create a new ASP.Net MVC 3 project with default templates which will setup the membership provider and some pages such as the login, create new user etc...&lt;/li&gt;
&lt;li&gt;Create a new action in HomeController.cs named "Users". Add the below code to return the MembershipUserCollection.

&lt;div id="codeSnippetWrapper"&gt;
&lt;pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; ActionResult Users()
{
      &lt;span style="color: blue;"&gt;return&lt;/span&gt; View(Membership.GetAllUsers());
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;Right click on the "Users" Action method definition and select the "Add view".Use the same master page of other views(&lt;span class="Apple-style-span" style="background-color: white; font-family: Consolas; font-size: 13px; white-space: pre;"&gt;~/Views/Shared/_Layout.cshtml&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;Go to the added view and add the below lines in it.
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"&gt;@{
    ViewBag.Title = "Users";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
&lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon;"&gt;h2&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;Users&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon;"&gt;h2&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;
@foreach (var user in Model)
{ 
    @user.UserName
}&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;Go to master page and add action along with Home and About.

&lt;div id="codeSnippetWrapper"&gt;
&lt;pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"&gt;&lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon;"&gt;li&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;@Html.ActionLink("Users", "Users", "Home")&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon;"&gt;li&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
Hope the steps are self explanatory. From the Action method in the Controller we are passing the MembershipUserCollection as model and that model is being enumerated in the RAZOR View to display the UserName.&lt;br /&gt;
&lt;br /&gt;
More on ASP.Net MVC 3&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/gg416514(v=vs.98).aspx"&gt;http://msdn.microsoft.com/en-us/library/gg416514(v=vs.98).aspx&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://davidhayden.com/blog/dave/archive/2011/01/05/ASPNETMVC3TutorialsIndex.aspx"&gt;http://davidhayden.com/blog/dave/archive/2011/01/05/ASPNETMVC3TutorialsIndex.aspx&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-989790613023431280?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/rTIU13Au58I" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/989790613023431280/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=989790613023431280" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/989790613023431280?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/989790613023431280?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/rTIU13Au58I/creating-simple-aspnet-mvc-3-razor.html" title="Creating simple ASP.Net MVC 3 RAZOR application and adding a view to list users" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2012/01/creating-simple-aspnet-mvc-3-razor.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkQMQXw4fip7ImA9WhRXGUs.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-3402178348420302260</id><published>2011-12-27T10:03:00.000+05:30</published><updated>2011-12-27T10:03:00.236+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-27T10:03:00.236+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Rest" /><category scheme="http://www.blogger.com/atom/ns#" term="VS 2010" /><category scheme="http://www.blogger.com/atom/ns#" term="Web Development" /><category scheme="http://www.blogger.com/atom/ns#" term=".Net 4" /><category scheme="http://www.blogger.com/atom/ns#" term="WCF" /><title>Creating and exposing simple REST based services in WCF 4.0</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/1RauBwGcOI7cZLxfQC8Y7LzKA1U/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1RauBwGcOI7cZLxfQC8Y7LzKA1U/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/1RauBwGcOI7cZLxfQC8Y7LzKA1U/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1RauBwGcOI7cZLxfQC8Y7LzKA1U/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
ReST (&lt;a href="http://en.wikipedia.org/wiki/Representational_state_transfer"&gt;Representational State Transfer&lt;/a&gt;) is something which makes the web service url easy to remember by pointing a resource rather than a web page.ie it done have the page.aspx and the query string syntax. For example consider the scenario where I need to get the details of employee named “Joy” &lt;br /&gt;
&lt;br /&gt;
Traditional way : &lt;a href="http://www.company.com/Employee.aspx?name=Joy"&gt;www.company.com/Employee.aspx?name=Joy&lt;/a&gt;&lt;br /&gt;
ReST way : &lt;a href="http://www.company.com/employees/Joy"&gt;www.company.com/employees/Joy&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
There is not question that the Rest URL is simple. Now lets look at how to create such a service in .Net 4.0.&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Create a web application normally. &lt;/li&gt;
&lt;li&gt;Add a WCF service to the project. &lt;/li&gt;
&lt;li&gt;Right click on the .svc file and view markup . Add Factory="System.ServiceModel.Activation.WebServiceHostFactory into the &amp;lt;%@ ServiceHost node.&lt;/li&gt;
&lt;li&gt;In the Service interface methods add [WebGet] attribute. This makes them visible to the ReST service. Set the URI template of the WebGet properly.&lt;/li&gt;
&lt;/ul&gt;
So above are the steps to follow. Lets now see one example Service contract.Famous DoWork method to ReST.
  &lt;br /&gt;
&lt;div&gt;
&lt;pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"&gt;[ServiceContract]
&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;interface&lt;/span&gt; IMyService
{
        [OperationContract]
        [WebGet]
        &lt;span style="color: blue;"&gt;string&lt;/span&gt; DoWork ();
}&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
The implementation is same.No change .
    &lt;br /&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; MyService : IMyService
{
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;string&lt;/span&gt; DoWork ()
    {
        &lt;span style="color: blue;"&gt;return&lt;/span&gt; &lt;span style="color: #006080;"&gt;"Yes.Our ReST service worked!!!"&lt;/span&gt;;
    }
}&lt;/pre&gt;
&lt;br /&gt;
All set.Hit F5 and in the browser type &lt;a href="http://localhost:&amp;lt;port&amp;gt;/myservice.svc/dowork" title="http://localhost:58247/myservice.svc/dowork"&gt;http://localhost:&amp;lt;port&amp;gt;/myservice.svc/dowork&lt;/a&gt; .You can see the output as xml.

      &lt;br /&gt;
&lt;div&gt;
&lt;pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"&gt;&lt;span style="color: blue;"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: maroon;"&gt;xml&lt;/span&gt; &lt;span style="color: red;"&gt;version&lt;/span&gt;&lt;span style="color: blue;"&gt;="1.0"&lt;/span&gt;?&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon;"&gt;string&lt;/span&gt; &lt;span style="color: red;"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue;"&gt;="http://schemas.microsoft.com/2003/10/Serialization/"&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;Yes.Our ReST service worked!!!&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon;"&gt;string&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;strong&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;u&gt;WCF ReST return as JSON&lt;/u&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
Its little difficult for the calling party to process the xml and one more issue is the xml is heavy.So the immediate solution which comes to this scenario is the JSON format. Its easy to make our output to JSON.Just change the WebGet to specify JSON format as follows.
        &lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"&gt;[WebGet(ResponseFormat=WebMessageFormat.Json)]&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;strong&gt;&lt;u&gt;&lt;/u&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;
&lt;strong&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;u&gt;How to pass parameters to the WCF ReST services&lt;/u&gt;&lt;/strong&gt;

          &lt;br /&gt;
&lt;strong&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/strong&gt;&lt;/div&gt;
Nobody is going to have only simple services as above in any of the projects. Passing arguments are necessary in WCF ReST services and its supports too using the UriTemplate property of WebGet.

        &lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"&gt;[OperationContract]
[WebGet(UriTemplate=&lt;span style="color: #006080;"&gt;"/Add/{a}/{b}"&lt;/span&gt;)]
&lt;span style="color: blue;"&gt;int&lt;/span&gt; Add ( &lt;span style="color: blue;"&gt;string&lt;/span&gt; a, &lt;span style="color: blue;"&gt;string&lt;/span&gt; b );&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
Implementation as follows.&lt;/div&gt;
&lt;div&gt;
&lt;pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;int&lt;/span&gt; Add(&lt;span style="color: blue;"&gt;string&lt;/span&gt; a, &lt;span style="color: blue;"&gt;string&lt;/span&gt; b)
{
    &lt;span style="color: blue;"&gt;int&lt;/span&gt; num1, num2;
    &lt;span style="color: blue;"&gt;if&lt;/span&gt; (&lt;span style="color: blue;"&gt;int&lt;/span&gt;.TryParse(a, &lt;span style="color: blue;"&gt;out&lt;/span&gt; num1) &amp;amp;&amp;amp; &lt;span style="color: blue;"&gt;int&lt;/span&gt;.TryParse(b, &lt;span style="color: blue;"&gt;out&lt;/span&gt; num2))
    {
        &lt;span style="color: blue;"&gt;return&lt;/span&gt; num1 + num2;
    }
    &lt;span style="color: blue;"&gt;throw&lt;/span&gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; ArgumentException(&lt;span style="color: #006080;"&gt;"Give numbers to add"&lt;/span&gt;);
}&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
Look at the UriTemplate it tells how the arguments are going to arrive. So call the service appropriately.&lt;/div&gt;
&lt;div&gt;
&lt;a href="http://localhost:&amp;lt;port&amp;gt;/Myservice.svc/Add/3/2" title="http://localhost:58247/Myservice.svc/Add/3/2"&gt;http://localhost:&amp;lt;port&amp;gt;/Myservice.svc/Add/3/2&lt;/a&gt;

          &lt;br /&gt;
&lt;strong&gt;&lt;u&gt;&lt;/u&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;
&lt;strong&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;u&gt;Points to Note&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;
The steps which I performed are very basic and this is working since the framework is 4.0 where it automatically use the &lt;a href="http://msdn.microsoft.com/en-us/library/bb412176.aspx"&gt;WebHttpBinding &lt;/a&gt;and other configurations. If you are using old frameworks you may need to set the binding properly.&lt;br /&gt;
&lt;br /&gt;
Another thing is the parameters here are string. So convert them accordingly. I don't thing a sample is needed to see this in your computer.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
There are more scenarios in this like such as how to pass and return complex types and how to use the Http Post etc...Hope I can post later.&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-3402178348420302260?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/UjQ3DS5nCwg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/3402178348420302260/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=3402178348420302260" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/3402178348420302260?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/3402178348420302260?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/UjQ3DS5nCwg/creating-and-exposing-simple-rest-based.html" title="Creating and exposing simple REST based services in WCF 4.0" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2011/12/creating-and-exposing-simple-rest-based.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DU8EQXgyfyp7ImA9WhRQEU8.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-3529321781128015477</id><published>2011-12-06T05:00:00.000+05:30</published><updated>2011-12-06T05:00:00.697+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-06T05:00:00.697+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Azure" /><category scheme="http://www.blogger.com/atom/ns#" term="AppFabric" /><category scheme="http://www.blogger.com/atom/ns#" term="Azure Development" /><category scheme="http://www.blogger.com/atom/ns#" term="Caching" /><category scheme="http://www.blogger.com/atom/ns#" term="Windows Azure" /><title>Successfully tried Windows Azure AppFabric Caching in Azure environment</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/bRAGI4xTejpGSRTbrlCCcxj2Cpw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bRAGI4xTejpGSRTbrlCCcxj2Cpw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/bRAGI4xTejpGSRTbrlCCcxj2Cpw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bRAGI4xTejpGSRTbrlCCcxj2Cpw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
You might have wondered why I am telling this as an achievement. It is meant to cache the data and what is there to say "Successfully tried". Yes.There are so many things to say about it even though there are so many articles which explain how to cache in a step by step manner with images. Roughly speaking it took me 3 days to test the caching in the real Azure hosted environment. Below are the issues we faced during the process.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;Issue 1 : Wrong SDK version ie Azure SDK to Azure Guest OS mapping&lt;/u&gt;&lt;br /&gt;
&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;br /&gt;
Initially I was using Azure SDK 1.6 which is not supported in the Azure production servers. More details are explained&amp;nbsp;&lt;a href="http://joymonscode.blogspot.com/2011/11/azure-sdk-16-releasedbut-dont-use-till.html"&gt;here&lt;/a&gt;. Most of the time we were getting the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.applicationserver.caching.datacacheexception(v=ws.10).aspx"&gt;DataCacheException&lt;/a&gt;&amp;nbsp;with&amp;nbsp;ErrorCode&amp;lt;ERRCA0017&amp;gt; which is nothing but &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.applicationserver.caching.datacacheerrorcode.retrylater(v=WS.10).aspx"&gt;RetryLater&lt;/a&gt;. Funny part is when we reverted to SDK 1.5 retry disappeared.&lt;br /&gt;
&lt;hr /&gt;
&lt;u&gt;Issue 2 :&amp;nbsp;Windows AppFabric v/s Azure AppFabric&lt;/u&gt;&lt;br /&gt;
&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;br /&gt;
Azure emulator don't have support to simulate Azure caching. So the idea was to use the Windows AppFabric cache which can be installed in our local machines and later change the configuration to use the actual Azure AppFabric .After configuring Windows AppFabric using Windows PowerShell and all we were able to connect to the local cache .But after&amp;nbsp;hosting the same code to Azure,&amp;nbsp;we came to know that there are some &lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/gg185678.aspx"&gt;differences between Windows Server AppFabric and the Azure AppFabric&lt;/a&gt;. It made us rewrite our AppFabricCacheProvider class based on the &lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/gg278350.aspx"&gt;Azure AppFabric caching API reference&lt;/a&gt;. The exceptions we got at this stage was &lt;a href="http://msdn.microsoft.com/en-us/library/system.notsupportedexception.aspx"&gt;NotSupportedException&lt;/a&gt;.&lt;br /&gt;
Below are some links which explains how to setup Windows Server AppFabric caching.&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/ff637746.aspx"&gt;http://msdn.microsoft.com/en-us/library/ff637746.aspx&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://www.wadewegner.com/2010/08/getting-started-with-windows-server-appfabric-cache/"&gt;http://www.wadewegner.com/2010/08/getting-started-with-windows-server-appfabric-cache/&lt;/a&gt;&lt;br /&gt;
&lt;hr /&gt;
&lt;u&gt;Issue 3 : Network issues to access caching clusters in your development&amp;nbsp;environment&lt;/u&gt;&lt;br /&gt;
&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;br /&gt;
We tried to access the real Azure AppFabric cache from out development&amp;nbsp;environment.&amp;nbsp;The Azure caching machine was not reachable from our normal company network. My be some firewalls were in middle. We had resolved it using another external internet connection which don't have any restriction.&lt;br /&gt;
If you happen to face this issue, you will get exception which says it cannot access some particular IPAddress which you can easily verify by pinging or &lt;a href="http://www.mediacollege.com/internet/troubleshooter/traceroute.html"&gt;tracert&lt;/a&gt;&lt;br /&gt;
&lt;hr /&gt;
&lt;u&gt;Issue 4 : AppFabric dlls to be included in the Azure publish package.&lt;/u&gt;&lt;br /&gt;
&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;br /&gt;
After 2 days we were able to successfully implement the caching framework and access Azure AppFabric cache from services in&amp;nbsp;our development&amp;nbsp;environment.Everybody became happy for some moment .But we lost the mood when we hosted our services in the Azure. Since we haven't implemented any logging framework it was really difficult for us to get the exact exception. The exception was mainly happening on the line .&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Calibri; font-size: 15px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Calibri; font-size: 15px;"&gt;&lt;i&gt;DataCacheFactoryConfiguration = new DataCacheFactoryConfiguration("clientName");&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Calibri; font-size: 15px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
Finally we were able to track that down to assembly not found issues ie "&lt;span class="Apple-style-span" style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: x-small; line-height: 16px;"&gt;The system&amp;nbsp;&lt;/span&gt;&lt;em style="background-color: white; font-family: arial, sans-serif; font-size: small; font-style: normal; font-weight: bold; line-height: 16px; text-align: -webkit-auto;"&gt;cannot&lt;/em&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: x-small; line-height: 16px; text-align: -webkit-auto;"&gt;&amp;nbsp;find the file specified. Could&amp;nbsp;&lt;/span&gt;&lt;em style="background-color: white; font-family: arial, sans-serif; font-size: small; font-style: normal; font-weight: bold; line-height: 16px; text-align: -webkit-auto;"&gt;not load&lt;/em&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: x-small; line-height: 16px; text-align: -webkit-auto;"&gt;&amp;nbsp;file or assembly '&lt;/span&gt;&lt;wbr style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: small; line-height: 16px; text-align: -webkit-auto;"&gt;&lt;/wbr&gt;&lt;em style="background-color: white; font-family: arial, sans-serif; font-size: small; font-style: normal; font-weight: bold; line-height: 16px; text-align: -webkit-auto;"&gt;Microsoft&lt;/em&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: x-small; line-height: 16px; text-align: -webkit-auto;"&gt;.&lt;/span&gt;&lt;em style="background-color: white; font-family: arial, sans-serif; font-size: small; font-style: normal; font-weight: bold; line-height: 16px; text-align: -webkit-auto;"&gt;WindowsFabric&lt;/em&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: x-small; line-height: 16px; text-align: -webkit-auto;"&gt;.&lt;/span&gt;&lt;em style="background-color: white; font-family: arial, sans-serif; font-size: small; font-style: normal; font-weight: bold; line-height: 16px; text-align: -webkit-auto;"&gt;Common&lt;/em&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: x-small; line-height: 16px; text-align: -webkit-auto;"&gt;, Version=1.0.0.0"&lt;/span&gt;&amp;nbsp;. Yes we were missing some dlls in the package which we uploaded to Azure. It was from the&amp;nbsp;&lt;i&gt;C:\Program Files\Windows Azure AppFabric SDK\V1.5\Assemblies\NET4.0\Cache&lt;/i&gt; folder.We added all the dlls, present in this location to our package and it stated working. Better refer these dlls in your web project / service host project so that these will be packaged automatically.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Microsoft.Web.DistributedCache.dll&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;Microsoft.WindowsFabric.Common.dll&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;Microsoft.WindowsFabric.Data.Common.dll&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
The question remains ,how it worked in the emulator? Answer was simple. All these dlls were in our GAC. in Azure machines, GAC don't have these dlls.&lt;br /&gt;
&lt;hr /&gt;
There were so many minor issues like the letter casing of &amp;lt;dataCacheClients&amp;gt;,should we use the&amp;nbsp;&amp;lt;dataCacheClients&amp;gt; or&amp;nbsp;&amp;lt;dataCacheClient&amp;gt; section in the config, port 22233 was blocked etc...Below are some links if you are struggling to get Azure AppFabric Caching working&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://blog.bareweb.eu/2011/07/hello-world-with-azure-appfabric-caching-service-v1-0/"&gt;http://blog.bareweb.eu/2011/07/hello-world-with-azure-appfabric-caching-service-v1-0/&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/wazplatformtrainingcourse_buildingappswithcacheservice_topic5#_Toc304208609"&gt;Exercise 3: Creating a Reusable and Extensible Caching Layer&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/ff921008.aspx"&gt;Appendix 1: Table of Error Code Strings&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-3529321781128015477?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/3yWDDvfZvgA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/3529321781128015477/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=3529321781128015477" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/3529321781128015477?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/3529321781128015477?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/3yWDDvfZvgA/successfully-tried-windows-azure.html" title="Successfully tried Windows Azure AppFabric Caching in Azure environment" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2011/12/successfully-tried-windows-azure.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUEHQ3s9cCp7ImA9WhRRFU4.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-204072281626240921</id><published>2011-11-29T00:49:00.000+05:30</published><updated>2011-11-29T09:03:52.568+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-29T09:03:52.568+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Windows Phone" /><category scheme="http://www.blogger.com/atom/ns#" term="Azure" /><category scheme="http://www.blogger.com/atom/ns#" term="Silverlight" /><title>Installing SSL certificates to Windows Phone 7 emulator</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/SBcPUx_bTi60kB_ld5kYUTwtyT0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SBcPUx_bTi60kB_ld5kYUTwtyT0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/SBcPUx_bTi60kB_ld5kYUTwtyT0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SBcPUx_bTi60kB_ld5kYUTwtyT0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
The days are again getting tight due to new technologies like Windows Azure, Windows Phone 7 &amp;amp; iPhone development. It is always interesting to work in new technologies where we learn so many new things ,hacks etc…My recent project uses &lt;a href="http://www.microsoft.com/windowsazure/"&gt;Windows Azure&lt;/a&gt; as server side technology and mobile as client side. For the time being we are using iPhone as client. &lt;br /&gt;
&lt;br /&gt;
When we start with Azure we could see that we can simulate the &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/windowsazuredevelopment/thread/6f25531f-0523-4a04-9d2a-4b4f42fc9cdb"&gt;https scenario even in the emulator&lt;/a&gt; which is more like the production environment. Really like it. But after some time, it became trouble. There were not enough MAC machines where we can test the iPhone application. So I moved to WP 7 as client for testing purpose. I integrated the &lt;a href="http://watwp.codeplex.com/"&gt;Azure tool kit for WP 7&lt;/a&gt; and when tried to access the &lt;a href="http://www.microsoft.com/windowsazure/features/accesscontrol/"&gt;Azure ACS&lt;/a&gt;, it started throwing errors .Our REST based services hosted using HTTPS in emulator are not working. ie simply says network error.&lt;br /&gt;
&lt;br /&gt;
After a google we could see that it is due to lack of certificates. If it was some other .Net client I can live with &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.aspx"&gt;ServicePointManager&lt;/a&gt; and its &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.servercertificatevalidationcallback.aspx"&gt;validation callback&lt;/a&gt;. But unfortunately there is &lt;a href="http://forums.silverlight.net/t/216069.aspx/1"&gt;no such ServicePointManager in Silverlight.&lt;/a&gt; So it is proved that WP7 never allows you to access the https url &lt;a href="http://blogs.msdn.com/b/davidhardin/archive/2010/12/30/wp7-and-self-signed-ssl-certificates.aspx"&gt;without proper certificate&lt;/a&gt;. But how to install certs in WP7 .When I asked my fellow developer who has Windows Phone, he told that he normally send the certificate file (.cer)through mail and the opening of attachment in phone will prompt for installation.&lt;br /&gt;
&lt;br /&gt;
But where is the mail client in simulator. Tried to send to my gmail id. But no luck.Then I tried the next way. Export the certificate into .cer format, host the .cer file in IIS and access it from Phone’s browser.Yes it worked. I was able to install the certificate. But again I got error in getting data through REST service. That was due to certificate URL issue .I should have used the exact certificate which is created for the IIS. ie for the localhost/127.0.0.1.&lt;br /&gt;
&lt;br /&gt;
Below are the steps to install the certificate in WP7 and get the Azure REST services working which is hosted in Azure emulator.&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Export the certificate as .cer&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;The certificate should be for the exact web address. ie export the certificate for 127.0.0.1 from IIS.&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;Host this certificate .Even in your &lt;a href="http://localhost/%3Ccert"&gt;http://localhost/&amp;lt;cert&lt;/a&gt; Name&amp;gt;.cer&lt;/li&gt;
&lt;li&gt;Make sure your IIS has the proper MIME type for the .cer&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;MIME type for .cer certificate file is application/x-x509-ca-cert&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;Browse to this certificate path from Windows Phone 7 emulator.&lt;/li&gt;
&lt;li&gt;Install the certificate.&lt;/li&gt;
&lt;/ul&gt;
Now you are all set to access https service hosted Windows Azure emulator from Windows Phone 7 with debugging support.&lt;br /&gt;
Enjoy… production environment in development.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-204072281626240921?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/4yRlMtC6kkw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/204072281626240921/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=204072281626240921" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/204072281626240921?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/204072281626240921?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/4yRlMtC6kkw/installing-ssl-certificates-to-windows.html" title="Installing SSL certificates to Windows Phone 7 emulator" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2011/11/installing-ssl-certificates-to-windows.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUMAQX8zeSp7ImA9WhRSGU0.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-9218167319743841485</id><published>2011-11-22T00:54:00.000+05:30</published><updated>2011-11-22T00:54:00.181+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-22T00:54:00.181+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Azure" /><category scheme="http://www.blogger.com/atom/ns#" term="Azure Development" /><category scheme="http://www.blogger.com/atom/ns#" term="Windows Azure" /><title>Azure SDK 1.6 released.But don't use till Azure Guest OS supports</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/_c0hEK3PHfMxlInpKEm1cpjCuoo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_c0hEK3PHfMxlInpKEm1cpjCuoo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/_c0hEK3PHfMxlInpKEm1cpjCuoo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_c0hEK3PHfMxlInpKEm1cpjCuoo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
I came to know that &lt;a href="http://blogs.msdn.com/b/windowsazure/archive/2011/11/14/updated-windows-azure-sdk-amp-windows-azure-hpc-scheduler-sdk.aspx"&gt;Windows Azure SDK 1.6 released&lt;/a&gt; and as normal I jumped into it. I did a caching framework and when I tried to host in Azure it started giving me errors .Since I am new to Azure it took me good amount of time to figure out what is going wrong. After hard googling I could see that the Azure is still &amp;nbsp;not supporting the SDK 1.6 in its production environment. Check out the link below link which explains Azure Guest OS and SDK compatibility&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="clip13x9 nav_dots_current"&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/ee924680.aspx" id="gg482095_MSDN.10_en-us" title="Windows Azure Guest OS Releases and SDK Compatibility Matrix"&gt;Windows Azure Guest OS Releases and SDK Compatibility Matrix&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
As of now the latest Guest OS is&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/hh560566.aspx"&gt;Windows Azure Guest OS 1.16 (Release 201109-01)&lt;/a&gt;&amp;nbsp;which supports Azure SDK 1.5 or older.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-9218167319743841485?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/_hJ-R0eyJ1k" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/9218167319743841485/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=9218167319743841485" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/9218167319743841485?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/9218167319743841485?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/_hJ-R0eyJ1k/azure-sdk-16-releasedbut-dont-use-till.html" title="Azure SDK 1.6 released.But don't use till Azure Guest OS supports" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2011/11/azure-sdk-16-releasedbut-dont-use-till.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUAEQHc9eCp7ImA9WhRSE08.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-359617749122982433</id><published>2011-11-15T08:55:00.000+05:30</published><updated>2011-11-15T08:58:21.960+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-15T08:58:21.960+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="VS 2010" /><category scheme="http://www.blogger.com/atom/ns#" term=".Net 4" /><category scheme="http://www.blogger.com/atom/ns#" term="Bug" /><category scheme="http://www.blogger.com/atom/ns#" term="VS 2008" /><category scheme="http://www.blogger.com/atom/ns#" term="Generics" /><category scheme="http://www.blogger.com/atom/ns#" term="Debugging" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="Application Design" /><category scheme="http://www.blogger.com/atom/ns#" term="Exception" /><category scheme="http://www.blogger.com/atom/ns#" term=".Net 3.5" /><category scheme="http://www.blogger.com/atom/ns#" term="Delegate" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>Generic retry mechanism &amp; catch using generic exception type</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/rDuK8hARcgALLHygwf-kt7h1Cis/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rDuK8hARcgALLHygwf-kt7h1Cis/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/rDuK8hARcgALLHygwf-kt7h1Cis/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rDuK8hARcgALLHygwf-kt7h1Cis/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Couple of weeks back we faced one situation where a portion of our code breaks due to a IIS not available situation and we were advised to implement a retry mechanism.Hope I can talk about that server down problem in future posts. The retry mechanism needs to implement based on the exception which will occur on that particular scenario. We tried test code by putting the try catch block and could see its working in one place. But there&amp;nbsp; are a bunch of other areas we need to modify the code.Also in future too developers may need to use this retry mechanism. &lt;br /&gt;
The architect resting in me jumped and said that we can use a generic retry mechanism using .net generics. My colleagues were in little confusion about how to achieve a generic mechanism for retry where the size and location of code differs and spread out in 150 projects.With the help of &lt;a href="http://msdn.microsoft.com/en-us/library/system.action.aspx"&gt;Action&lt;/a&gt; delegate I was able to convince them and the subsequent google gave us ready made code to do the same.    &lt;br /&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; ExecuteWithRetry( Action action, UInt16 noOfAttempts )
{
    &lt;span style="color: green;"&gt;//Validate args:Throw exception on retryCount=0&lt;/span&gt;
    &lt;span style="color: blue;"&gt;int&lt;/span&gt; count = 1;
    &lt;span style="color: blue;"&gt;for&lt;/span&gt; (; ; count++)
    {
        &lt;span style="color: blue;"&gt;try&lt;/span&gt;
        {
            action();
            &lt;span style="color: blue;"&gt;break&lt;/span&gt;;
        }
        &lt;span style="color: blue;"&gt;catch&lt;/span&gt; (ReTryableException ex)
        {
            Log(ex, count);
            &lt;span style="color: blue;"&gt;if&lt;/span&gt; (count == noOfAttempts) &lt;span style="color: blue;"&gt;throw&lt;/span&gt;;
        }
    }
}&lt;/pre&gt;
&lt;br /&gt;
Everybody became happy like after the first fight seen in movies. We know that the movie needs to complete its 2 hours with excitement and for that villain&amp;nbsp; should come back with more power. Here too the villain come back when the perfectionist in me put forward the suggestion of making it real generic so that we can move to the utility project and can be consumed by other fellow developers as well. So we rewrote the logic as follows.&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; ExecuteWithRetry&amp;lt;TException&amp;gt; ( Action action, UInt16 noOfAttempts ) &lt;span style="color: blue;"&gt;where&lt;/span&gt; TException :Exception   
{
    &lt;span style="color: green;"&gt;//Validate args:Throw exception on retryCount=0&lt;/span&gt;
    &lt;span style="color: blue;"&gt;int&lt;/span&gt; count=1;
    &lt;span style="color: blue;"&gt;for&lt;/span&gt;(;;count++)
    {
        &lt;span style="color: blue;"&gt;try&lt;/span&gt;
        {
            action();
            &lt;span style="color: blue;"&gt;break&lt;/span&gt;;
        }
        &lt;span style="color: blue;"&gt;catch&lt;/span&gt; (TException ex)
        {
            Log(ex, count);
            &lt;span style="color: blue;"&gt;if&lt;/span&gt; (count == noOfAttempts) &lt;span style="color: blue;"&gt;throw&lt;/span&gt;;
        }
    } 
}&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
Oh what an idea sir ji…There was one more suggestion came to make retry after specific interval. But before that we tried to integrate modified function in our app.&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;strong&gt;&lt;u&gt;Catching exception using generic type&lt;/u&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
Here starts the second part of the story. When we run from Visual studio it didn’t hit the catch block!!! Theoretically there are no issues but practically it failed. At least for some moment surrounding people even I thought that our understanding about either Exception handling or generics is wrong. Even we thought of getting rid of this concept and write redundant retry code everywhere. But when we came back to our original state , we googled it and find that it is a BUG in .Net when &lt;a href="http://stackoverflow.com/questions/1577760/why-cant-i-catch-a-generic-exception-in-c"&gt;running inside Visual Studio debugging mode&lt;/a&gt;.We tried running by double clicking the application and it works perfect.We were also able to see this bug in the &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/362422/debugger-broken-after-vs-sp1-using-catch-t-ex"&gt;Microsoft connect&lt;/a&gt; and says its fixed. &lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
There is on workaround available for this issue its as follows&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"&gt;&lt;span style="color: blue;"&gt;catch&lt;/span&gt; (Exception ex)
{
    TException tEx = ex &lt;span style="color: blue;"&gt;as&lt;/span&gt; TException;
    &lt;span style="color: blue;"&gt;if&lt;/span&gt; (tEx != &lt;span style="color: blue;"&gt;null&lt;/span&gt;) { &lt;span style="color: green;"&gt;/*Process */&lt;/span&gt;}
    &lt;span style="color: blue;"&gt;else&lt;/span&gt; &lt;span style="color: blue;"&gt;throw&lt;/span&gt;;
}&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
This changed my perception&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
“The bug is there only due to poor dev’s coding mistake never by compilers, development tools or the framework” &lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
to &lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
“Compilers, development tools and frameworks are also coded by developers”. &lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
Later I happen to read a post about &lt;a href="http://blogs.msdn.com/b/lucian/archive/2011/10/17/a-day-in-the-life-of-compiler-bugfixing.aspx"&gt;fixing a compiler bug&lt;/a&gt; which enforced my perception.&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-359617749122982433?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/L2ohdLmMHvo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/359617749122982433/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=359617749122982433" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/359617749122982433?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/359617749122982433?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/L2ohdLmMHvo/generic-retry-mechanism-catch-using.html" title="Generic retry mechanism &amp;amp; catch using generic exception type" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2011/11/generic-retry-mechanism-catch-using.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0UCQXk5cSp7ImA9WhRTF0k.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-7841478977840816549</id><published>2011-11-08T15:11:00.000+05:30</published><updated>2011-11-08T15:11:00.729+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-08T15:11:00.729+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Azure Development" /><category scheme="http://www.blogger.com/atom/ns#" term="Windows Azure" /><category scheme="http://www.blogger.com/atom/ns#" term="Cloud Computing" /><title>Yes.I was able to run Azure apps in emulator</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/yEe0Vtcsym017cANg4Z3jDKHhvg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yEe0Vtcsym017cANg4Z3jDKHhvg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/yEe0Vtcsym017cANg4Z3jDKHhvg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yEe0Vtcsym017cANg4Z3jDKHhvg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;“&lt;i&gt;Role instances are taking longer than expected to start. Do you want to continue waiting?”&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;The above error message must be very familiar to the newbies of Windows Azure when they try to run Azure application in Azure emulator .When we &lt;a href="http://www.google.co.in/search?gcx=c&amp;amp;sourceid=chrome&amp;amp;ie=UTF-8&amp;amp;q=Role+instances+are+taking+longer+than+expected+to+start.+Do+you+want+to+continue+waiting%3F"&gt;search&lt;/a&gt; for this error msg, we get so many links which says the experience of resolving this error. My situation was also not exceptional .Among my team members only my machine got this disease. &lt;/p&gt;  &lt;p&gt;When I opened the &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/windowsazuredevelopment/thread/e40cf6be-16a9-4f6e-a1df-f7092aa7aa38/"&gt;first link&lt;/a&gt; I could see a list of 14 check points to be corrected to get the emulator working. I went through each and every point and verified it.But no luck. There was an interesting solution that we need to &lt;a href="http://stackoverflow.com/questions/7051153/role-instances-are-taking-longer-than-expected-to-start-is-there-a-new-solutio"&gt;opt for retry&lt;/a&gt; and it will work .I tried clicking on the Wait button 10-15 times without any luck. Another forum said this was an identified issue in Azure sdk 1.3 and fixed in 1.4 .But I am getting the issue even in Azure 1.5.&lt;/p&gt;  &lt;p&gt;There were some guys who got it working by reinstalling the Azure sdk and some went to the extend of reinstalling OS. That was not my option because we are using a OS image which has some special softwares pre installed. So I tried to dig into the inner details of emulator working.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Inner details of Azure emulator&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;When I started digging into emulator the first thing I could see is it will create a &lt;a href="http://social.msdn.microsoft.com/Forums/en/windowsazuretroubleshooting/thread/5593764f-31e0-4b58-a326-77c48f5d5fa9"&gt;temporary site&lt;/a&gt; in IIS 7.But when I looked in IIS, I was able to realize that the issue is with creating the temporary site for Azure emulator. After that I tried opening the system tray icon of emulator and checked the &lt;a href="http://blogs.msdn.com/b/avkashchauhan/archive/2011/09/14/windows-azure-sdk-1-5-version-1-5-40909-1602-installation-and-quick-walkthrough.aspx"&gt;emulator console view&lt;/a&gt; by clicking on the ‘I’ button. There was nothing. Then I decided to check where are log files of Azure emulator? &lt;/p&gt;  &lt;p&gt;It was simple the location of Azure emulator logs is&lt;/p&gt;  &lt;p&gt;c:\users\&amp;lt;username&amp;gt;\AppData\Local\dftmp\&lt;/p&gt;  &lt;p&gt;Now I got a bunch of error log files and started analyzing it and could see a good error (sometimes errors are better than nothing) from the \dftmp\DevFCLogs folder which said &lt;/p&gt;  &lt;p&gt;“There is already a listener on IP endpoint 127.0.0.1:12001”&lt;/p&gt;  &lt;p&gt;The next google took me to a strange &lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/hh472164.aspx"&gt;msdn page&lt;/a&gt; which asked to me to free the below ports.&lt;/p&gt;  &lt;p&gt;12000, 12001, 12002, 808, 16001, or 15100.&lt;/p&gt;  &lt;p&gt;After freeing the ports I was able to run the application successfully in emulator .But look at the port 808 which I an using for net.tcp binding and essential for my other project.That means I need to change that port or work on only one project at a time. When I googled again I could see that there are some more people with same &lt;a href="http://serena-yeoh.blogspot.com/2011/10/windows-azure-compute-emulator-hangs.html"&gt;issue with the 808 port&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;If you follow the &lt;a href="http://blogs.msdn.com/b/avkashchauhan/archive/2011/09/14/windows-azure-sdk-1-5-version-1-5-40909-1602-installation-and-quick-walkthrough.aspx"&gt;step by step instruction to install Azure sdk&lt;/a&gt; and got it working in the first shot, you are the lucky person in Azure world. Otherwise you are screwed especially if you are the coder. I was lucky that I am not the developer in that project and could survive some days by drawing boxes and arrows &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://lh4.ggpht.com/-3wi38X8gOq8/TrOz0y0VjXI/AAAAAAAAOzk/fT-MeXjP73k/wlEmoticon-smile%25255B2%25255D.png?imgmax=800" /&gt;&lt;/p&gt;  &lt;p&gt;If you are in the same situation where I was go through the &lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/gg508668.aspx"&gt;Azure SDK 1.5 known issues&lt;/a&gt; and try the workarounds. Also look are the “&lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/hh404002.aspx"&gt;Getting Started with Locally Running a Windows Azure Application&lt;/a&gt;” page in MSDN. Then start looking at the &lt;a href="http://computrengineer.blogspot.com/2011/03/azure-sdk-13-role-instances-are-taking.html"&gt;14 check points&lt;/a&gt; mentioned above.Add the unblocking of ports as 15th check point. Finally goto the logs folder and google it. I don’t think there is any need to reinstall the OS.&lt;/p&gt;  &lt;p&gt;My initial opinion about Windows Azure is, it’s a cloud in all means. An unclear dark cloud which may cause heavy rain at any time to which we are throwing our apps and data. Another complaint is about the Azure sdk which is not mature even in its v 1.5 to at least &lt;a href="http://msdn.microsoft.com/en-us/library/hh289317.aspx"&gt;block the direct URL access to WCF REST service by configuration&lt;/a&gt; where ACS protects the service. Hope I can post more about Azure later.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-7841478977840816549?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/yYoP1hFBpUw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/7841478977840816549/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=7841478977840816549" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/7841478977840816549?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/7841478977840816549?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/yYoP1hFBpUw/yesi-was-able-to-run-azure-apps-in.html" title="Yes.I was able to run Azure apps in emulator" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/-3wi38X8gOq8/TrOz0y0VjXI/AAAAAAAAOzk/fT-MeXjP73k/s72-c/wlEmoticon-smile%25255B2%25255D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2011/11/yesi-was-able-to-run-azure-apps-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEMEQXw5eip7ImA9WhRTEEU.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-1988652929461436381</id><published>2011-11-01T00:10:00.000+05:30</published><updated>2011-11-01T00:10:00.222+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-01T00:10:00.222+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term=".Net 4" /><category scheme="http://www.blogger.com/atom/ns#" term="Application Design" /><category scheme="http://www.blogger.com/atom/ns#" term=".Net 3.5" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>Running another .net executable without Process.Start</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/vVIoBcDMloscvOhKqbHwwxB1LQA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vVIoBcDMloscvOhKqbHwwxB1LQA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/vVIoBcDMloscvOhKqbHwwxB1LQA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vVIoBcDMloscvOhKqbHwwxB1LQA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Whenever we get a requirement like this first answer will be &lt;a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx"&gt;Process.Start&lt;/a&gt; which is the common way to start another application from one application. It creates different process ,its region and execute independently.    &lt;br /&gt;
&lt;pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"&gt;&lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; StartProcess()
{
    Process proc = &lt;span style="color: blue;"&gt;new&lt;/span&gt; Process();
    proc.StartInfo = &lt;span style="color: blue;"&gt;new&lt;/span&gt; ProcessStartInfo() {FileName=&lt;span style="color: #006080;"&gt;@"Path\Executable file.exe"&lt;/span&gt; };
    proc.Start();
}&lt;/pre&gt;
&lt;br /&gt;
This is the correct solution &lt;u&gt;if the application is not a .net executable&lt;/u&gt;.You can also see new process in the task manager. But here we need to load an application which is in .net itself. So are there any other method to load a new application in the current process itself? &lt;br /&gt;
&lt;br /&gt;
It is YES since AppDomain is a unique feature in.Net. AppDomain is an another separation in the process for isolated execution.This separation is managed by the .Net runtime, not by the windows OS which manages Process and its allocation. Everybody must have heard about AppDomain and will be in confusion with Application and Process.&amp;nbsp; For more details about AppDomain please refer the articles below&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://codebetter.com/raymondlewallen/2005/04/04/what-is-an-application-domain-an-explanation-for-net-beginners/"&gt;http://codebetter.com/raymondlewallen/2005/04/04/what-is-an-application-domain-an-explanation-for-net-beginners/&lt;/a&gt;&lt;br /&gt;  &lt;a href="http://msdn.microsoft.com/en-us/library/2bh4z9hs(v=vs.71).aspx"&gt;http://msdn.microsoft.com/en-us/library/2bh4z9hs(v=vs.71).aspx&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Once you are confortable with AppDomain read the below which explains how to create new AppDomain of the other application and start it.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;u&gt;Executing an Assembly present other application using Appdomain&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Creating the appdomain is very easy as follows&lt;br /&gt;
&lt;pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"&gt;&lt;span style="color: green;"&gt;//Creating the setup object&lt;/span&gt;
AppDomainSetup setup = &lt;span style="color: blue;"&gt;new&lt;/span&gt; AppDomainSetup();

setup.ApplicationBase = &lt;span style="color: #006080;"&gt;@"D:\Joy\POCs\DesktopUIApp"&lt;/span&gt;;
&lt;span style="color: green;"&gt;//Set the probing path if needed&lt;/span&gt;
&lt;span style="color: green;"&gt;//setup.PrivateBinPath = "Some path which resides inside ApplicationBase";&lt;/span&gt;

&lt;span style="color: green;"&gt;//Create the domain&lt;/span&gt;
AppDomain domain = AppDomain.CreateDomain(&lt;span style="color: #006080;"&gt;"NewApp"&lt;/span&gt;, AppDomain.CurrentDomain.Evidence, setup);&lt;/pre&gt;
Now we have the appdomain. If you are a .net developer with knowledge in &lt;a href="http://msdn.microsoft.com/en-us/library/f7ykdhsy(v=vs.80).aspx"&gt;reflection&lt;/a&gt; you can think about so many techniques to start the other application as follows&lt;br /&gt;
&lt;br /&gt;
1) Create assembly using the AppDomain.&lt;a href="http://msdn.microsoft.com/en-us/library/system.appdomain.load(v=VS.100).aspx"&gt;Load&lt;/a&gt; method and get the Main() method’s MethodInfo and invoke it. &lt;br /&gt;  2) Create type of App of target application using the &lt;a href="http://msdn.microsoft.com/en-us/library/system.appdomain.createinstanceandunwrap(v=VS.100).aspx"&gt;AppDomain.CreateInstanceAndUnwrap&lt;/a&gt; () and executes it.&lt;br /&gt;  &lt;br /&gt;But almost all these techniques will fail because it cannot create another application inside this appdomain since it has one.ie multiple Applications are not allowed in same app domain.So the API which works is as follows. &lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: #f4f4f4; font-family: 'Courier New', courier, monospace; font-size: 11px; line-height: 16px; white-space: pre;"&gt;AppDomain domain = AppDomain.CreateDomain(&lt;span style="color: #006080;"&gt;"NewApp"&lt;/span&gt;, AppDomain.CurrentDomain.Evidence, setup);&lt;/span&gt;&lt;br /&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"&gt;domain.ExecuteAssembly(&lt;span style="color: #006080;"&gt;@"D:\Joy\POCs\DesktopUIApp\DesktopUI.exe"&lt;/span&gt;);
            &lt;/pre&gt;
&lt;br /&gt;
This executes the specified assembly in the new appdomain. Only thing you need to know is the name of the assembly to be started.This is not useful when you don’t know what type of files to be opened such as downloading files from server and opening it.&lt;/div&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-1988652929461436381?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/li6bhxuA2lg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/1988652929461436381/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=1988652929461436381" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/1988652929461436381?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/1988652929461436381?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/li6bhxuA2lg/running-another-net-executable-without.html" title="Running another .net executable without Process.Start" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2011/11/running-another-net-executable-without.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0cBRXs8cCp7ImA9WhdaFUw.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-8717188141523064181</id><published>2011-10-25T09:27:00.001+05:30</published><updated>2011-10-25T09:27:34.578+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-25T09:27:34.578+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="VS 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="VS 2010" /><category scheme="http://www.blogger.com/atom/ns#" term=".Net 4" /><category scheme="http://www.blogger.com/atom/ns#" term="VS 2008" /><category scheme="http://www.blogger.com/atom/ns#" term=".Net 3.5" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>Fusion log viewer fuslogvw ie Assembly Binding Log Viewer</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/EjOl1mazkbY0CuMsGZZ1PVd4kDo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/EjOl1mazkbY0CuMsGZZ1PVd4kDo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/EjOl1mazkbY0CuMsGZZ1PVd4kDo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/EjOl1mazkbY0CuMsGZZ1PVd4kDo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
When you work with .net and your dlls are scattered around &lt;a href="http://msdn.microsoft.com/en-us/library/6axd4fx6.aspx"&gt;GAC&lt;/a&gt;, application bin, or reference assemblies its very difficult to check which version of dll is loaded in the application. Without knowing that you cannot ensure that your code changes are in effect. For small projects you can put Console.WriteLine or Messagebox.Show to indicate your code change .But when we talk about bigger applications with hundreds of project and thousands of code files ,it is not practical.Also there are chances that your message box code might get checked into the code repository which gives fun for others.&lt;br /&gt;
&lt;br /&gt;
Another scenario is creating and maintaining &lt;a href="http://msdn.microsoft.com/en-us/library/system.appdomain.aspx"&gt;AppDomains &lt;/a&gt;.There are concepts like &lt;a href="http://msdn.microsoft.com/en-us/library/system.appdomain.basedirectory.aspx"&gt;ApplicationBasePath&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.appdomainsetup.privatebinpath.aspx"&gt;PrivateBinPath &lt;/a&gt;for the appdomains which decides from where the runtime should load the assembly or what is the &lt;a href="http://msdn.microsoft.com/en-us/library/yx7xezcf.aspx"&gt;sequence in searching for assembly&lt;/a&gt;. If you are versioning your application there are chances for &lt;a href="http://msdn.microsoft.com/en-us/library/system.missingmethodexception.aspx"&gt;MissingMethodException &lt;/a&gt;if the loaded assembly is not compatible with the versions.&lt;br /&gt;
&lt;br /&gt;
All these things says we need to profile/inspect the assembly loading&amp;nbsp;behavior in .net on the fly to make sure the dlls are loaded from correct location and it is the Fusion log viewer which comes with Visual Studio.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Starting the tool&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;Make sure the registry entry&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: 'Segoe UI', Verdana, Arial; font-size: 13px;"&gt;HKLM\Software\Microsoft\Fusion\ForceLog is 1&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Goto visual studio command prompt.&lt;/li&gt;
&lt;li&gt;Type and enter '&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.71).aspx"&gt;fuslogvw&lt;/a&gt;&lt;/b&gt;'&lt;/li&gt;
&lt;li&gt;This will bring you the tool window.Make sure the log path is correct.&lt;/li&gt;
&lt;li&gt;Now run your assembly.&lt;/li&gt;
&lt;li&gt;Once the application loads click on the refresh button in the assembly log viewer.&lt;/li&gt;
&lt;li&gt;You got the details of assemblies loaded with loading history and from which location&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
This is very useful in my current project to identify assembly loading where we have versioning and play with AppDomains all around.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;a href="http://www.hanselman.com/blog/BackToBasicsUsingFusionLogViewerToDebugObscureLoaderErrors.aspx"&gt;http://www.hanselman.com/blog/BackToBasicsUsingFusionLogViewerToDebugObscureLoaderErrors.aspx&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-8717188141523064181?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/d60PDp7C_f8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/8717188141523064181/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=8717188141523064181" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/8717188141523064181?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/8717188141523064181?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/d60PDp7C_f8/fusion-log-viewer-fuslogvw-ie-assembly.html" title="Fusion log viewer fuslogvw ie Assembly Binding Log Viewer" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2011/10/fusion-log-viewer-fuslogvw-ie-assembly.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkEMQXw4eCp7ImA9WhdUF0k.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-3510848487574287658</id><published>2011-10-04T22:48:00.000+05:30</published><updated>2011-10-04T22:48:00.230+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-04T22:48:00.230+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term=".Net 4" /><category scheme="http://www.blogger.com/atom/ns#" term="Reflection" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="Application Design" /><category scheme="http://www.blogger.com/atom/ns#" term=".Net 3.5" /><title>ControlledSingleton pattern</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/6LDpVzlvt69vM6iBiMPiqy3kQWM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6LDpVzlvt69vM6iBiMPiqy3kQWM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/6LDpVzlvt69vM6iBiMPiqy3kQWM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6LDpVzlvt69vM6iBiMPiqy3kQWM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Some months back I had written a post to describe how to &lt;a href="http://joymonscode.blogspot.com/2011/02/how-to-get-calling-method-name.html"&gt;get the name of the calling method&lt;/a&gt; programmatically. ie to get the call stack entry just below the current method. That post was born in relation with one of our requirement to create controlled singleton pattern which I described in it’s previous &lt;a href="http://joymonscode.blogspot.com/2011/02/how-to-get-method-name-inside-same.html"&gt;post&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Why we need ControlledSingleton pattern?&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;u&gt;This is needed when you plan to make a class Singleton after so much code is written using that class and you have technical and managerial limitations to change all the existing code&lt;/u&gt;.The normal singleton pattern with private constructor will not be applicable here since it needs full inspection in your code base for compilation as well as usage of reflection. You can easily fix the compilation issues but reflection cannot be caught that much easily.Also if you are serializing the Singleton class to persist its state or pass through WCF, certainly you cannot make it as singleton otherwise the serializer will fail.&lt;/p&gt;  &lt;p&gt;If your company management in case of product development or you client in case of projects are really adamant on quality and are ready to give you enough time to refactor code,just go with that and implement the real singleton. Also if you are developing a new project you can decide on which class to be singleton and make that as normal singleton class.Unfortunately I didn’t had this luxury which lead me to the ControlledSingleton pattern.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;What is ControlledSingleton&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;According to me it’s &lt;strong&gt;same as normal singleton but giving permission to some components to create the object of singleton class.&lt;/strong&gt;The components may be some classes,some methods or some assemblies.That depends on the requirements of the developer who implements the pattern. I am not sure whether there are any other pattern in different name which is same as this.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Implementing ControlledSingleton&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;This depends upon the environment / programming language you are using.Since I am a .net developer I can see 2 methods to implement the pattern&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;u&gt;Validating the caller using call stack&lt;/u&gt;       &lt;br /&gt;This can be achieved by inspecting the current &lt;a href="http://joymonscode.blogspot.com/2011/02/how-to-get-calling-method-name.html"&gt;call stack&lt;/a&gt; and checking whether the caller has the permission to create the object.Please refer my previous posts to get detailed idea.       &lt;br /&gt;&lt;a href="http://joymonscode.blogspot.com/2011/02/how-to-get-calling-method-name.html"&gt;http://joymonscode.blogspot.com/2011/02/how-to-get-calling-method-name.html&lt;/a&gt;      &lt;br /&gt;      &lt;br /&gt;&lt;u&gt;Characteristics&lt;/u&gt;:-The draw back of this method is we cannot ensure singleton at compile time.Each and every time before inspecting the call stack will cause performance impacts. This is applicable only in managed languages where we have the method name at runtime.       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;&lt;u&gt;InternalsVisibleTo attribute        &lt;br /&gt;&lt;/u&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx"&gt;InternalsVisibleToAttribute&lt;/a&gt; defined on assembly tells the system that there are some more assemblies which can see it’s internal members. That means if we make a class Singleton using internal constructor the assemblies which are specified in the InternalsVisibleTo attribute can create the object of the singleton class.       &lt;br /&gt;      &lt;br /&gt;&lt;u&gt;Characteristics&lt;/u&gt;:-The advantage of this is we can ensure at the compile time itself. This idea can also extend to unmanaged languages too since it works at compile time. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;u&gt;&lt;strong&gt;About attached sample&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;The sample contains 3 projects. “ControlledSingleton” project contains the singleton class PersonsContext. The class is made as Singleton using internal constructor which means any class inside that project can create the instance of the singleton class. The InternalsVisibleTo attribute is pointing to the second assembly named “SingletonPermitted”.ie it can create object of PersonContext.The “ControlledSingleton_Demo” is a console application which don’t have permission to create the object of singleton class. It cannot even try to use reflection to create the object.&lt;/p&gt;  &lt;p&gt;Download the sample from &lt;a href="https://skydrive.live.com/?cid=890c06c8106550a0&amp;amp;sc=documents&amp;amp;uc=1&amp;amp;id=890C06C8106550A0%21151#"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Recommended changes&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The above methods allows so many objects of the singleton class in the system at same time.If you don’t have serialization on your singleton candidate you can think about a ReInitializeSingleton method which is internal to modify/replace the single ton object.&lt;/p&gt;  &lt;p&gt;&lt;em&gt;internal ReinitializeSingleton(params)&lt;/em&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-3510848487574287658?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/U2FHGCL-Dao" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/3510848487574287658/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=3510848487574287658" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/3510848487574287658?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/3510848487574287658?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/U2FHGCL-Dao/controlledsingleton-pattern.html" title="ControlledSingleton pattern" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2011/10/controlledsingleton-pattern.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0EMQXw4cSp7ImA9WhdUEU4.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-9206958164740899323</id><published>2011-09-27T21:38:00.000+05:30</published><updated>2011-09-27T21:38:00.239+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-27T21:38:00.239+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Garbage Collector" /><category scheme="http://www.blogger.com/atom/ns#" term="Debugging" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>How to know when .Net GC is working</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/kJB89WLFdCN-Rb33uwxMfvDEwEo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kJB89WLFdCN-Rb33uwxMfvDEwEo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/kJB89WLFdCN-Rb33uwxMfvDEwEo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kJB89WLFdCN-Rb33uwxMfvDEwEo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;One of my previous posts I was explaining how to learn the &lt;a href="http://joymonscode.blogspot.com/2011/09/icorprofilercallback-and-return-to.html"&gt;working of JIT during an application run&lt;/a&gt;. That gives us actual feeling of how the concept if working in the real world. If you are interested to know how the other concepts are working you can monitor using the windows tool called &lt;a href="http://msdn.microsoft.com/en-us/library/aa645516(v=vs.71).aspx"&gt;perfmon&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Perfmon.exe can be found inside the system32 folder in Windows installation &lt;/p&gt;  &lt;p&gt;&lt;em&gt;&amp;lt;InstallDrive&amp;gt;:\Windows\System32\perfmon.exe&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;You can easily open the application by just typing perfmon in the search box of start menu.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Using Perfmon to monitor the .net Activities&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Perfmon is a great tool and its not possible to cover all the aspects of it in this post. Just google for its full usage scenarios. I am just concentrating on how to use it to monitor when GC is working for our application. You can use the same method to know when the jitting happens.&lt;/p&gt;  &lt;p&gt;Ok. Lets open the perfmon and watch what are the options in it.There are PerformanceMonitor, &lt;a href="http://technet.microsoft.com/en-us/library/cc722173(WS.10).aspx"&gt;ReliabilityMonitor&lt;/a&gt;, Data collector sets and Reports.We are interested in the performance monitor where we get the status of GC using a counter.What is a counter in perfmon?Counter is a criteria or specification what to monitor which can be added to a graph to see its current value. By default the processor time counter will be available there. Below are the easy steps to add a counter for monitoring GC of an application.&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Goto Performance monitor-&amp;gt;Click &lt;strong&gt;”+”&lt;/strong&gt; button at top –&amp;gt;Expand “.Net CLR Memory” in the available counters-&amp;gt;Select “# Gen 0 Collections”-&amp;gt;Select your application in the “Instances of selected object” section-&amp;gt;Click on “Add” –&amp;gt;Click “Ok”&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Remove the processor time counter for easy monitoring. Now the graph will reflect the change when GC comes into picture. For learning purpose better put a button to invoke GC using &lt;a href="http://msdn.microsoft.com/en-us/library/system.gc.collect.aspx"&gt;GC.Collect&lt;/a&gt; method .So that you can see the counter increments when you click on that button.&lt;/p&gt;  &lt;p&gt;When you add the counter you might have noticed so many counters available there .Play with those and conquer the technology with its inner working.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-9206958164740899323?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/QDJVeRNasdU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/9206958164740899323/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=9206958164740899323" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/9206958164740899323?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/9206958164740899323?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/QDJVeRNasdU/how-to-know-when-net-gc-is-working.html" title="How to know when .Net GC is working" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2011/09/how-to-know-when-net-gc-is-working.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEQMQXY5cSp7ImA9WhdVFUk.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-2786811959022359868</id><published>2011-09-20T23:43:00.000+05:30</published><updated>2011-09-20T23:43:00.829+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-20T23:43:00.829+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="iPhone" /><category scheme="http://www.blogger.com/atom/ns#" term="iPad" /><category scheme="http://www.blogger.com/atom/ns#" term="Objective-C" /><title>Learning Objective-C Setting environment &amp; HelloWorld.m</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/kfIPdzHP2oh-f1KKIwNxgpKNDsE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kfIPdzHP2oh-f1KKIwNxgpKNDsE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/kfIPdzHP2oh-f1KKIwNxgpKNDsE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kfIPdzHP2oh-f1KKIwNxgpKNDsE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Couple of weeks back I happened to meet one of my relative in a family function who is in college studying computer science. He is a tech kid who expected so many things from me when I told I am working in computer field for the last 6 years. He is more interested in creating his own computer game rather than playing .When in college people might not have selected a technology path and will be having knowledge in all most all the areas such as Embedded Systems,.Net,Networking,Java etc...He was not an exception and he started shooting his questions when he met a 6 years experienced professional. The conversation (mainly his doubts) touched so many areas from creating small web sites to programming &lt;a href="http://www.iturls.com/English/TechHotspot/TH_ai.asp"&gt;artificial intelligence systems&lt;/a&gt; and &lt;a href="http://www.etsimo.uniovi.es/cscene/CS4/CS4-02.html"&gt;controlling device through parallel port&lt;/a&gt; to creating a robot.&lt;/p&gt;  &lt;p&gt;I was able to survive on the programming topics related to assembly language,C,C++,Java &amp;amp; .Net and how the computer functions internally at the register level. But really failed on Obj C used in iPhone,iPad, Symbian in Nokia, embedded systems and robotics. Finally he asked me “What are you doing in your company related to computer science?” .I had to admit that I am developing a highly generic .Net application for executing workflows which is now targeting auditing workflows. Even I don’t know the auditing business because there is another application to author auditing workflow which is carried out by business analysts. One more thing is we are programming one level up from the real machine and OS .ie we are talking /programming to the .Net and .Net will talk to the machine through OS to carry out the tasks.&lt;/p&gt;  &lt;p&gt;The conversation stopped there. But when I think about that I feel there are so many things in high level language club which I don’t know. Learning robotics and programming for embedded systems are not at all in the scope at least now. I applied filters again and came to 3 topics VC++,Android &amp;amp; Obj C. Learning VC++ is delayed because I didn’t get a chance to work. It will not be a problem, if I get a chance. Android uses Java which is again .Net like language. So the remaining is Obj-C which I never tried. Yes my next is &lt;a href="http://en.wikipedia.org/wiki/Objective-C"&gt;Objective-C&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;u&gt;&lt;strong&gt;Why should I learn Obj C / benefits of Obj-C&lt;/strong&gt;&lt;/u&gt;     &lt;br /&gt;My first reason is the popularity of Apple products and this is the way I can make use of their framework.There are so many iPhone clones. But they cannot get into an agreement that which is the real clone. So iPhone is still the king .As everybody knows Cocoa is the framework to program iPad and iPhone and it need Obj-C. When I started ObjC the usage of class got my attention on the first day itself.We need to have an interface and implementation when we write a simple class itself. We need to share that interface only when we distribute that class. There are lot more reasons when we look at the language level.If you are interested please check the below links     &lt;br /&gt;&lt;a href="http://support.apple.com/kb/TA45902?viewlocale=en_US"&gt;http://support.apple.com/kb/TA45902?viewlocale=en_US&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://www.answerbag.com/q_view/135341"&gt;http://www.answerbag.com/q_view/135341&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Starting Objective-C&lt;/u&gt;       &lt;br /&gt;&lt;/strong&gt;As everybody when we start something fresh we look for teachers. Likewise I checked with the iPhone team in my company .Its 2 new joiners fresh out of college with one Mac and one iPad who got trained in WPF and Silverlight by me .According to them XCode is the only way to execute Objective C and now its licensed and it needs a MAC machine. My upgrade request toWin7 and if possible i7 is pending for months.In this situation asking MAC machine from the company to learn Obj C is not at all a question.Again I am alone and only way is google. I could see couple of ways which helps us to learn objective C in windows. Let’s start with&amp;#160; &lt;a href="http://www.gnu.org/software/gnustep/experience/Windows.html"&gt;GNUStep&lt;/a&gt; which I feel the simple way.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Setting up environment in Windows&lt;/u&gt;&lt;/strong&gt;     &lt;br /&gt;You can get detailed instructions and download links from the below sites.     &lt;br /&gt;&lt;a href="http://www.gnustep.org/experience/Windows.html"&gt;http://www.gnustep.org/experience/Windows.html&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://www.techotopia.com/index.php/Installing_and_using_GNUstep_and_Objective-C_on_Windows"&gt;http://www.techotopia.com/index.php/Installing_and_using_GNUstep_and_Objective-C_on_Windows&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;According to my experience you need to install 3 things in the given order &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;GNUstep MSYS System &lt;/li&gt;    &lt;li&gt;GNUstep Core &lt;/li&gt;    &lt;li&gt;GNUstep Devel &lt;/li&gt; &lt;/ul&gt; This will give you the shell which can be opened by StartMenu-&amp;gt;Programs-&amp;gt;GNUStep-&amp;gt;Shell  &lt;p&gt;&lt;u&gt;&lt;strong&gt;Compiling &amp;amp; Running first ObjC program&lt;/strong&gt;&lt;/u&gt;     &lt;br /&gt;Just write a small C program to output HelloWorld which can be compiled in normal c compilers or through visual studio.Don’t add any ObjC features such as classes.Below is a small sample. &lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #cc6633"&gt;#include&lt;/span&gt; &amp;lt;stdio.h&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; main(&lt;span style="color: #0000ff"&gt;void&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;    printf(&lt;span style="color: #006080"&gt;&amp;quot;God is Love\n&amp;quot;&lt;/span&gt;);&lt;br /&gt;    Foo();&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; ;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Foo()&lt;br /&gt;{&lt;br /&gt;    printf(&lt;span style="color: #006080"&gt;&amp;quot;Inside Foos\ns&amp;quot;&lt;/span&gt;);&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;I normally starts with “God id Love” rather than “Hello World”.The extension for objective C programs is dot(.)m.Save the above program in helloworld.m.Now we have the sample. Then compile using gcc&amp;#160; compiler which will give the .exe file.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;em&gt;&lt;strong&gt;gcc helloworld.m&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the environment variable is not set properly this may cause some errors.In that &lt;a href="http://forums.tizag.com/showthread.php?t=236"&gt;case set the environement&lt;/a&gt; variables properly. It will be the PATH variable in the environment setup.Successful compilation will give an .exe file. Now execute that exe same as normal exe. Now we are in a position to learn Obj C.Next time other language features such as loops ,select etc…Then go to class and objects.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-2786811959022359868?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/8HrXp24Ae_k" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/2786811959022359868/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=2786811959022359868" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/2786811959022359868?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/2786811959022359868?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/8HrXp24Ae_k/learning-objective-c-setting.html" title="Learning Objective-C Setting environment &amp;amp; HelloWorld.m" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2011/09/learning-objective-c-setting.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkEAQn07fSp7ImA9WhdWGUU.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-1723256503993421566</id><published>2011-09-14T13:54:00.001+05:30</published><updated>2011-09-14T13:54:03.305+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-14T13:54:03.305+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Assembly Language" /><category scheme="http://www.blogger.com/atom/ns#" term="Debugging" /><category scheme="http://www.blogger.com/atom/ns#" term=".Net 3.5" /><category scheme="http://www.blogger.com/atom/ns#" term="VC++" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>ICorProfilerCallBack and return to unmanaged code</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/46oEMoZfv0PchOjkeqw1vU5wseU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/46oEMoZfv0PchOjkeqw1vU5wseU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/46oEMoZfv0PchOjkeqw1vU5wseU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/46oEMoZfv0PchOjkeqw1vU5wseU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;As a .net developer if you just want your code to be run by the .net runtime and get your work done please don’t read this further.This is for the developers who really want to know what is happening inside the computer when they run a .net application. After reading you may think, why we need .net which is managed by somebody else and we need to code within it’s boundaries rather than exploring the system’s capabilities.So be careful.&lt;/p&gt;  &lt;p&gt;&lt;u&gt;&lt;strong&gt;Practical feeling v/s theories&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;From my childhood days itself, I have a habit of practically feeling things before confirming the theories.When my parents said there is shock so don’t touch the electric wire ,I didn’t believe.But realized when I touched myself.(Its 250volts in India).I am sure that ,this nature will be there with many people. The same problem appeared when I entered into the computer programming world. I started programming in my school days directly in the BASIC language where it was really hard for me to write program because I don’t know how this T.V is going to add 2 numbers which I am entering through keyboard. The teachers were simply saying computer will identify your command and process accordingly.But again how it knows how to manage carry and all.&lt;/p&gt;  &lt;p&gt;All these questions were answered when I learned about the &lt;a href="http://en.wikipedia.org/wiki/Logic_gate"&gt;logical gates&lt;/a&gt; in digital electronics during the second year of diploma.Then I learned how these gates techniques can be leveraged to &lt;a href="http://www.cavehill.uwi.edu/fpas/cmp/online/el21c/lesson18.html"&gt;8085 processor instructions&lt;/a&gt; which I executed in a &lt;a href="http://www.kmitl.ac.th/~kswichit/mtk-85/index.html"&gt;small kit which has 7 segment display&lt;/a&gt; .There was no software &lt;a href="http://www.softlookup.com/display.asp?id=6856"&gt;simulators for 8085&lt;/a&gt;&amp;#160; available at that time for us.Third year I wrote and executed &lt;a href="http://en.wikipedia.org/wiki/X86_assembly_language"&gt;assembly instructions&lt;/a&gt; in an actual computer by &lt;a href="http://www.emu8086.com/assembler_tutorial/compiler.html"&gt;compiling that into .exe&lt;/a&gt;.That put me in a stage to think about a compiler or interpreter which can understand a high level language and convert to machine instructions.The high level languages which was confortable for me was C,C++&amp;amp; VC++ in which we can easily plan how our code is going to execute in the physical machine. JAVA and .Net I learned as backups.&lt;/p&gt;  &lt;p&gt;Things will not be always good for us.When I came out of the college the world needs .Net and Java programmers than traditional unmanaged coders. Since the bread and butter is important than the passion, I started with C# and .Net since it allows me to write C++ type language in my favorite development tool Visual Studio.But the same issue came there. How my code is being executed by the .Net?&lt;/p&gt;  &lt;p&gt;As like any other .net fresher in India, my starting days were hard. So many things to do.No time to think whether its logical or not.That compels people to swallow the theories like how they believe in God. I had to believe that there is something called &lt;a href="http://en.wikipedia.org/wiki/Common_Intermediate_Language"&gt;IL code&lt;/a&gt; to which we are compiling our source code which is machine independent. This helps us to write code in different languages such as VB.Net and C# in a single solution.It was really interesting for me.&lt;/p&gt;  &lt;p&gt;Also theories said there is a &lt;a href="http://msdn.microsoft.com/en-us/library/ee787088.aspx"&gt;garbage collector&lt;/a&gt; which will collect all the free memory so no need to worry about the memory management while coding. That’s great,but I got so many &lt;a href="http://support.microsoft.com/kb/318263"&gt;memory leak issues&lt;/a&gt; which I was not able to understand at that time. As a developer support engineer I was not supposed to fix the issues, only forward to the development team. &lt;/p&gt;  &lt;p&gt;Another doubt was when we double click on the exe &lt;a href="http://stackoverflow.com/questions/6605956/what-happens-when-a-net-application-is-started"&gt;how the .net runtime takes control of the exe&lt;/a&gt; and manage execution of it.In Java when we run we specify &lt;a href="http://www.cs.swarthmore.edu/~newhall/unixhelp/debuggingtips_Java.html"&gt;Java &amp;lt;AppName&amp;gt;.class&lt;/a&gt; which clearly says we are executing Java.exe which is responsible for executing the IL code.&lt;/p&gt;  &lt;p&gt;Things became clear when I tackled my developer support job. In free time googles I came to know there is a tool called &lt;a href="http://msdn.microsoft.com/en-us/library/aa309387(v=vs.71).aspx"&gt;ILDasm.exe&lt;/a&gt; in the .net framework which is present in my machine itself using which I can see the IL code.This made the concept of language interoperability strong in my mind.ie I realized myself that all our code which is written in VB or C# will compile into this same format.Or even we can &lt;a href="http://www.codeproject.com/KB/msil/ilassembly.aspx"&gt;write code in IL itself&lt;/a&gt; and compile using &lt;a href="http://msdn.microsoft.com/en-us/library/496e4ekx(v=vs.80).aspx"&gt;ILAsm&lt;/a&gt;. Then I thought about reverse engineering the IL to C# since its in a readable form which lead me to a nice tool called &lt;a href="http://www.reflector.net/"&gt;Reflector&lt;/a&gt; to reverse engineer the .Net code. This tool also showed me scenarios where the compiler optimize our code because some code which I wrote came in different form on reflection.&lt;/p&gt;  &lt;p&gt;Again the season changed to busy. Microsoft introduced new technology called &lt;a href="http://msdn.microsoft.com/en-us/library/aa970268.aspx"&gt;WPF&lt;/a&gt; for presentation purpose.As a control vendor my company also jumped into WPF where I was coordinating the development team and the release. As a .net engineer I had to learn one more technology keeping so many queries in mind.WPF introduced more queries into my mind like where is the &lt;a href="http://stackoverflow.com/questions/624367/how-to-handle-wndproc-messages-in-wpf"&gt;WndProc function in WPF&lt;/a&gt;?,how the &lt;a href="http://www.abhisheksur.com/2011/07/internals-of-dependency-property-in-wpf.html"&gt;DP is working internally&lt;/a&gt;,who is invoking the PropertyChanged event in INotifyPropertyChanged,Is WPF really making use of my graphics card etc…But WPF helped me in one way which is nothing but to understand the working of GC. Since WPF comes &lt;a href="http://blogs.msdn.com/b/jgoldb/archive/2010/06/14/memory-leak-hotfixes-for-wpf-3-5-sp1.aspx"&gt;with memory leaks&lt;/a&gt; if we use bindings ,I got opportunities to explore the .net process memory using another nice tool called &lt;a href="http://www.codeproject.com/KB/debug/windbg_quick_start.aspx"&gt;WinDbg&lt;/a&gt; which showed me what are gen0 objects and when they goto&amp;#160; gen1 and gen2 also what is &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc534993.aspx"&gt;LOH&lt;/a&gt; and why its getting fragmented which leads to &lt;a href="http://connect.microsoft.com/VisualStudio/feedback/details/521147/large-object-heap-fragmentation-causes-outofmemoryexception"&gt;OutOfMemory exception&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;But still so many queries are left.When a type is being initialized? if our assembly contains so many types will it decrease the performance due to loading time? How the .net runtime takes control when we double click on the .net exe? When a function is being JITted? When the GC starts its operation? etc… and most of the queries were answered when I work with Microsoft for my current company.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Working with Microsoft people&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;As I mentioned in some of the previous posts ,I got an excellent opportunity to work with Microsoft in their &lt;a href="http://www.microsoft.com/about/companyinformation/usaoffices/southeast/en/us/charlotte.aspx"&gt;Charlotte,NC campus&lt;/a&gt; which leveraged my knowledge about the internals of .Net .Especially working with &lt;a href="https://www.facebook.com/people/Wade-Mascia/1070611456"&gt;Wade Mascia&lt;/a&gt; who codes the &lt;a href="http://blogs.msdn.com/b/debugdiag/"&gt;DebugDiag&lt;/a&gt; was really wonderful.He introduced me one interface called &lt;a href="http://msdn.microsoft.com/en-us/library/ms230818.aspx"&gt;ICorProfilerCallBack&lt;/a&gt; which has enough functions which will be called by the CLR when it performs its different operations. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Using ICorProfilerCallback in managed code&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;But fortunately or unfortunately we &lt;a href="http://www.dotnetmonster.com/Uwe/Forum.aspx/dotnet-clr/85/Can-ICorProfilerCallback-be-implemented-in-managed-code"&gt;cannot implement ICorProfilerCallback in managed code&lt;/a&gt; such as C# or VB.net.I am looking for anyways to do so which I know not logical since writing profiler in managed code to profile managed code makes no sense.We are going to see when our method is going to be JITted and if we write the profiler in managed code how CLR can call the profiler callback method which needs JITting itself. That means we are back to unmanaged world.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Implementing ICorProfilerCallback&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Its my continuous 6th year, I am writing&amp;#160; managed .net code.That made it difficult for me to write the VC++ code in a day.So as a normal developer, I googled for the code. There was not much luck except &lt;a href="http://www.codeproject.com/KB/dotnet/dotnetprofiler.aspx"&gt;one article in CodeProject&lt;/a&gt;.It was simple and has basic functionalities of ICorProfileCallback interface like logging method calls.So I took that code and started scratching it to add my requirements.Hope &lt;a href="http://www.codeproject.com/script/Membership/View.aspx?mid=508756"&gt;scott_hackett&lt;/a&gt; will not mind, I am modifying his code&lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://lh5.ggpht.com/-DI17Hz0XN3c/TnBkoNgkwAI/AAAAAAAAOW0/_qwUOASf8m8/wlEmoticon-smile2.png?imgmax=800" /&gt;.&lt;/p&gt;  &lt;p&gt;When we implement the ICorProfilerCallback, we need to know about one more interface which is &lt;a href="http://msdn.microsoft.com/en-us/library/ms233177.aspx"&gt;ICorProfilerInfo&lt;/a&gt; which is used as a helper when we deal with the profiler such as to get the method name from the ID and all.We will get an object of ICorProfilerInfo as parameter in the initialize method of ICorProfilerCallback interface.The Initialize method is called by CLR.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;ICorProfilerCallback2 &amp;amp; ICorProfilerInfo2&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;These are the types introduced in .Net2.0 which contains some more functionalities. These are inherited interfaces of their counterparts in&amp;#160; old framework versions. So to get the new features cast the argument coming though Initialize method to &lt;a href="http://msdn.microsoft.com/en-us/library/ms231876.aspx"&gt;ICorProfilerInfo2&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Steps to implement ICorProfilerCallback&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;For detailed description please see the &lt;a href="http://www.codeproject.com/KB/dotnet/dotnetprofiler.aspx"&gt;original article&lt;/a&gt;.Below is a summary&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Implement the interface ICorProfilerCallback /ICorProfilerCallback2 in a VC++ Com project as normal. &lt;/li&gt;    &lt;li&gt;If you want your profiler to be recognized by the CLR and call the profiler methods,you need to set environment variables appropriately. &lt;/li&gt;    &lt;li&gt;Simple implementation of ICorProfilerCallback will not give us the call back to our methods.For that we need to register which events we need using the &lt;a href="http://msdn.microsoft.com/en-us/library/ms230853.aspx"&gt;SetEventMask&lt;/a&gt; method of ICorProfilerInfo object.Do that in the ICorProfilerCallback::Initialize itself.It accepts a DWORD and each bit controls one callback feature. &lt;/li&gt;    &lt;li&gt;Now our methods in the implementation class will get called based on the mask we set except the MethodEnter and Leave.For that we need to hook separately using the ICorProfilerInfo::&lt;a href="http://msdn.microsoft.com/en-us/library/ms231434.aspx"&gt;SetEnterLeaveFunctionHooks&lt;/a&gt; method.I don’t know why method execution callbacks need a separate way. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;About the attached sample&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The sample which I got from code project article doesn’t filter namespaces based on our needs. What I wanted was to filter how my application is getting JITed and the method calls.So I modified the ProfilerLauncher to accept namespace and passed that namespace to profiler through the environmental variable ‘NS_FILTER’. Environment variables are the only one way we can communicate to the profiler from outside world. Files are there, but I don’t want to use. &lt;/p&gt;  &lt;p&gt;Also modified the profiler to log based on the namespace and added logging mask for the JITting events.As I told earlier its my second visit to C++ after 6 years.Things seems changed / I forgot C++ which made me write code like a fresher.So don’t expect a professional style coding in the sample.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Running the sample&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Before running my modified sample I would recommend running the &lt;a href="http://www.codeproject.com/KB/dotnet/dotnetprofiler/dotnetprofiler_src.zip"&gt;sample attached in the code project&lt;/a&gt; article which gives you an idea how many methods are being called when we run a simple win forms application. There are 3 files needed to run the sample.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;DotnetProfiler.dll :This is the unmanaged profiler. &lt;/li&gt;    &lt;li&gt;ProfilerLauncher.exe : This is the runner wrote in .Net which accepts target .net exe path and the namespace to filter.Then it create a process with required environment variables and starts execution of the target .net application. &lt;/li&gt;    &lt;li&gt;Helloworld.exe : Just a .net application which we are going to be profiled.Put your application instead of this. Don’t forget to enter the correct namespace in the launcher screen. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;This logs the profile information in a text file in the same folder.Download the sample from &lt;a href="https://skydrive.live.com/embedicon.aspx/BlogSamples/JoymonsCode/dotnetprofiler^_src^_Modified.zip?cid=890c06c8106550a0&amp;amp;sc=documents"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-1723256503993421566?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/xeYd1wxSqUU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/1723256503993421566/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=1723256503993421566" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/1723256503993421566?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/1723256503993421566?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/xeYd1wxSqUU/icorprofilercallback-and-return-to.html" title="ICorProfilerCallBack and return to unmanaged code" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/-DI17Hz0XN3c/TnBkoNgkwAI/AAAAAAAAOW0/_qwUOASf8m8/s72-c/wlEmoticon-smile2.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2011/09/icorprofilercallback-and-return-to.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ck8MQHw-fSp7ImA9WhdWE0w.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-7066586398471246735</id><published>2011-09-06T17:38:00.000+05:30</published><updated>2011-09-06T17:38:01.255+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-06T17:38:01.255+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="dynamic" /><category scheme="http://www.blogger.com/atom/ns#" term="Array" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><title>Creating non zero based arrays in .Net</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/8hpDsCwBtur1hEDa2OtV47am9lI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8hpDsCwBtur1hEDa2OtV47am9lI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/8hpDsCwBtur1hEDa2OtV47am9lI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8hpDsCwBtur1hEDa2OtV47am9lI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Last week when I was hunting for .Net performance tips and an array related tip got my attention.It says &lt;em&gt;&lt;u&gt;“Non-zero based arrays will reduce performance”&lt;/u&gt;&lt;/em&gt;.ie the current default lower bound of .net array is 0.If we change this lower bound of array it will cause performance penalty.But luckily there are no places in our project where developers used non-zero based arrays. I should say thanks to .Net architects in Microsoft than our developers, for making the creation of non-zero based arrays bit complicated. According to my current knowledge, using the normal declaration syntax of array, its not possible to create non-zero based arrays. The only way now is to use the Array.CreateInstance method.Look at the below code snippet. &lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;Array arrayObject = Array.CreateInstance(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;), &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] { 5 }, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] { 2 });&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This creates single dimension integer array of size 5 with lower bound as 2.ie you need to access the array as arrayObject[2] to [6] not arrayObject[0]. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;&lt;u&gt;Normal array and Array.CreateInstance&lt;/u&gt;&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;As you know all the arrays are of class type Array which gives them the ability of iteration and all. We can create array using the CreateInstance method, just like how we create normal array with square bracket.If we display the type of Array object we can see its exactly same as the type of normal array object with [].We can cast the output to normal array object and access the elements using [].Look at the below code it just creates an array with zero as lower bound and access the element at position 0. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;br /&gt;  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; TestBase0Array()&lt;br /&gt;{&lt;br /&gt;    Array arrayObject=Array.CreateInstance(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;), &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] { 5 }, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] { 0 });&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] intArray = arrayObject &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[];&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (intArray != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;br /&gt;    {&lt;br /&gt;        Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;TestBase0Array(): ArrayCreateInstance() succeded for base 0, Array type :&amp;quot;&lt;/span&gt; + intArray.GetType().FullName);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;&lt;br /&gt;        {&lt;br /&gt;            intArray[0] = 10;&lt;br /&gt;            Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;TestBase0Array():Write &amp;amp; Read from array [0] - &amp;quot;&lt;/span&gt; + intArray[0]);&lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (Exception ex)&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;TestBase0Array():Not able to access array&amp;quot;&lt;/span&gt;);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;br /&gt;        Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;TestBase0Array(): Not able cast to int[]&amp;quot;&lt;/span&gt;);&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;&lt;u&gt;Type of non-zero based arrays&lt;/u&gt;&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;When we come to arrays who’s lower bound is not zero, the type will be different. it will contain a ‘*’.If its an integer array the type will be ‘&lt;em&gt;System.Int32[*]&lt;/em&gt;’. This means we cannot cast the output of Array.CreateInstance to our normal array object which is declared using [].(But I am not sure whether there are any hidden methods to cast to normal array).So we cannot access the array elements using [].Then the final option is to use the SetValue and GetValue methods of Array class.Look at the below code. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;br /&gt;  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; TestBase2Array()&lt;br /&gt;{&lt;br /&gt;    Array arrayObject=Array.CreateInstance(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;), &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] { 5 }, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] { 2 });&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] intArray = arrayObject &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[];&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (intArray != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;br /&gt;    {&lt;br /&gt;        Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;TestBase2Array(): ArrayCreateInstance() succeded for base 0, Array type :&amp;quot;&lt;/span&gt; + intArray.GetType().FullName);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;&lt;br /&gt;        {&lt;br /&gt;            intArray[0] = 10;&lt;br /&gt;            Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;TestBase2Array():Write &amp;amp; Read from array [0] - &amp;quot;&lt;/span&gt; + intArray[0]);&lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (Exception ex)&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;TestBase2Array():Not able to access array using []&amp;quot;&lt;/span&gt;);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;        Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;TestBase2Array(): Not able cast to int[].Array Type :&amp;quot;&lt;/span&gt;+arrayObject.ToString());&lt;br /&gt;        Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;TestBase2Array(): Lower bound :&amp;quot;&lt;/span&gt; + arrayObject.GetLowerBound(0).ToString());&lt;br /&gt;        Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;TestBase2Array(): Length :&amp;quot;&lt;/span&gt; + arrayObject.Length.ToString());&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;&lt;br /&gt;        {&lt;br /&gt;            arrayObject.SetValue(10, 0);&lt;br /&gt;            Console.WriteLine (&lt;span style="color: #006080"&gt;&amp;quot;TestBase2Array(): Element at 0&amp;quot;&lt;/span&gt;+ arrayObject.GetValue(10, 0).ToString());&lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (Exception ex)&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;TestBase2Array(): Not able to access element at 0.Trying 2nd element&amp;quot;&lt;/span&gt;);&lt;br /&gt;            arrayObject.SetValue(10, 2);&lt;br /&gt;            Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;TestBase2Array(): Element at &amp;quot;&lt;/span&gt;+arrayObject.GetValue(2).ToString());&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;&lt;u&gt;dynamic keyword and non-zero based arrays&lt;/u&gt;&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Its really difficult to use 2 methods to access an array for a developer who would like to access the array as it is.So I tried assigning the output of Array.CreateInstance to a dynamic variable and used the square brackets.It never gives a compilation error.But at runtime it fails with an exception “Unable to cast object of type 'System.Int32[*]' to type 'System.Int32[]'”. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;br /&gt;  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; TestBase2ArrayUsingDynamic()&lt;br /&gt;{&lt;br /&gt;    Array arrayObject = Array.CreateInstance(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;), &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] { 5 }, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] { 2 });&lt;br /&gt;    dynamic intArray = arrayObject;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;&lt;br /&gt;        {&lt;br /&gt;            intArray[2] = 10;&lt;br /&gt;            Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;TestBase1ArrayUsingDynamic():Write &amp;amp; Read from array [0] using dynamic keyword- &amp;quot;&lt;/span&gt; + intArray[2]);&lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (Exception ex)&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;TestBase1ArrayUsingDynamic():Exception :&amp;quot;&lt;/span&gt;+ ex.Message +&lt;br /&gt;                Environment.NewLine + &lt;span style="color: #006080"&gt;&amp;quot;Not able to access non zero based array even using dynamic keyword!!!&amp;quot;&lt;/span&gt;);&lt;br /&gt;        }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;That means dynamic keyword also failed. &lt;em&gt;We need to use the SetValue and GetValue if we want to use non-zero based arrays&lt;/em&gt;. &lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;&lt;u&gt;Non-Zero based arrays and VB.Net&lt;/u&gt;&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;But in VB.Net the story is different.If you are working in VB.Net its all easy.You can use non-zero based arrays in the normal array. I don’t know whether it’s the beauty or curse of unsafe programming. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id="codeSnippetWrapper"&gt;&lt;br /&gt;  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; arrayObject = Array.CreateInstance(&lt;span style="color: #0000ff"&gt;GetType&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;), &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;() {5}, &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;() {2})&lt;br /&gt;arrayObject(2) = 10&lt;br /&gt;Console.WriteLine(arrayObject(2).ToString)&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;I don’t think we need to use non-zero based arrays in any of the situations of our normal programming life. One more thing is this non-zero based array creation is &lt;u&gt;not supported by Silverlight&lt;/u&gt;. That means if you are developing in common code base which is targeted for WPF,Silverlight and WP7 you will not encounter this scenario.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-7066586398471246735?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/NixyUPdlYzw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/7066586398471246735/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=7066586398471246735" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/7066586398471246735?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/7066586398471246735?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/NixyUPdlYzw/creating-non-zero-based-arrays-in-net.html" title="Creating non zero based arrays in .Net" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2011/09/creating-non-zero-based-arrays-in-net.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEIAQX06fip7ImA9WhdXF08.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-1605396791022723671</id><published>2011-08-30T23:19:00.000+05:30</published><updated>2011-08-30T23:19:00.316+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-30T23:19:00.316+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MSEXCEL" /><category scheme="http://www.blogger.com/atom/ns#" term="Debugging" /><category scheme="http://www.blogger.com/atom/ns#" term="MSACCESS" /><category scheme="http://www.blogger.com/atom/ns#" term="Exception" /><title>Getting right app.config file in Office Addins</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/0GnCFU2w2OvMz5Xnw8h0M76gQ2I/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0GnCFU2w2OvMz5Xnw8h0M76gQ2I/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/0GnCFU2w2OvMz5Xnw8h0M76gQ2I/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0GnCFU2w2OvMz5Xnw8h0M76gQ2I/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Recently we got one issue while deploying our project’s Office Add-in component in one of the testing machine which has Microsoft Office 2007. We first tested in Excel after initial debugging we could see that one of the registry reading from add in code&amp;#160; is failing.Then we started digging into the inner areas and could see that the registry key is getting formatted using a app.config value, not getting correctly formatted.After some time by putting couple of message boxes we confirmed that the excel add-in is taking app.config file of excel from the below location!!!&lt;/p&gt;  &lt;p&gt;&amp;lt;Install Drive&amp;gt;:\Program Files\Microsoft Office\Office12\EXCEL.EXE.config&lt;/p&gt;  &lt;p&gt;We tested the manifest files, registry keys etc…but didn’t get any clue. According to us the add in should take its own config file and never the excel’s config file.Used almost all the debugging tools we know but no luck.We even thought of putting our config entries in the excel.exe.config &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://lh3.ggpht.com/-mtf7i4GSQl4/Tj1tqUEwQjI/AAAAAAAAOWc/RfnoNRcp_yE/wlEmoticon-smile%25255B2%25255D.png?imgmax=800" /&gt;.Since that is not the right way finally started asking google.It gave the reason and solution very quickly.It is very simple .We need to change a registry entry where we specify the vsto addin path. The change seems so silly&lt;/p&gt;  &lt;p&gt;The manifest registry entry needs to be prefixed with &lt;a href="file:///.ie"&gt;file:///.ie&lt;/a&gt; instead of &amp;quot;[TARGETDIR]ExcelAddIn.vsto|vstolocal&amp;quot;: we need to use &amp;quot;file:///[TARGETDIR]ExcelAddIn.vsto|vstolocal&amp;quot;:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://stackoverflow.com/questions/1671587/word-addin-not-reading-appsetting"&gt;http://stackoverflow.com/questions/1671587/word-addin-not-reading-appsetting&lt;/a&gt; .According to Microsoft this is a &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/653444/visual-studio-sp1-or-specifically-vsto-sp1-issue-with-config-file-location"&gt;performance fix&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Simple fix but it took our half day and it was a Saturday&lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-sadsmile" alt="Sad smile" src="http://lh4.ggpht.com/-OAgmfecnCNg/Tj1ts2y31xI/AAAAAAAAOWg/H_S-tXSHVC8/wlEmoticon-sadsmile%25255B2%25255D.png?imgmax=800" /&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-1605396791022723671?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/mVg70uo2-zs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/1605396791022723671/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=1605396791022723671" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/1605396791022723671?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/1605396791022723671?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/mVg70uo2-zs/getting-right-appconfig-file-in-office.html" title="Getting right app.config file in Office Addins" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/-mtf7i4GSQl4/Tj1tqUEwQjI/AAAAAAAAOWc/RfnoNRcp_yE/s72-c/wlEmoticon-smile%25255B2%25255D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2011/08/getting-right-appconfig-file-in-office.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUECQXk6fCp7ImA9WhdXEEU.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-1555948025979390266</id><published>2011-08-23T13:51:00.000+05:30</published><updated>2011-08-23T13:51:00.714+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-23T13:51:00.714+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Trace" /><category scheme="http://www.blogger.com/atom/ns#" term="Web.config" /><category scheme="http://www.blogger.com/atom/ns#" term="Debugging" /><category scheme="http://www.blogger.com/atom/ns#" term="CAB" /><title>Simple .net trace</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/oC1N7CE5zRlbhBvnV_itN_VznTg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/oC1N7CE5zRlbhBvnV_itN_VznTg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/oC1N7CE5zRlbhBvnV_itN_VznTg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/oC1N7CE5zRlbhBvnV_itN_VznTg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This is the basic lesson we all might have learned when we started .net. But when we enter into complex applications or gain more knowledge over the time, we might have started writing our own complex logging systems or the Microsoft Logging application block. I am sure that at certain point we again think about the simple ways. That happened to me last week when I had to debug communication between our project and a completely unknown single sign on provider.&lt;/p&gt;  &lt;p&gt;The scenario is simple. We had to integrate our Silverlight web app with a sign on provider similar to google.In google systems, if we open gmail or orkut it will go to another url for getting username and password and after authentication, it will return to the requested application ie gmail or orkut url. This is the UI side which user sees.But if we speak technically from the programmer perspective, the authentication mechanism has to provide a token in the form of cookies which should be kept at the client side (browser) and for the subsequent requests the token should go along and the application(gmail or orkut) should verify that for validity.If we are the developers of both the systems, this is not at all a big task. &lt;/p&gt;  &lt;p&gt;But in our case the authentication provider is fully unknown except its name. No idea what the auth provider returns and in which header and all.And on top of all these, we have no access to this authentication provider from our development machines and we are not in a position to install the same in dev environment. This means we need to log each and every thing which happens between our application and the authentication provider. Microsoft enterprise library is the logging mechanism in our application.But if we log each and everything using the logging block, our application will become a logging application which cannot serve the actual user requests.What ever we put as config to switch on or off the logging that checking will take some CPU cycles which may degrade the server side performance. Moreover I am not a big fan of Enterprise library in terms of performance.So what should be our solution?&lt;/p&gt;  &lt;p&gt;Simple &lt;strong&gt;Trace.Write&lt;/strong&gt; statements which can be avoided at the compile time for the production installer msi files.&lt;/p&gt;  &lt;p&gt;&lt;u&gt;How to configure the trace destination file in simple way?&lt;/u&gt;     &lt;br /&gt;We talk about the method which write the log .Now where will this text go? Below is a simple config which route the trace entries to a file.&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;system.diagnostics&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt;   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;trace&lt;/span&gt; &lt;span style="color: #ff0000"&gt;autoflush&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;          &lt;span style="color: #ff0000"&gt;indentsize&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;listeners&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;       &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;add&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Listener1&amp;quot;&lt;/span&gt; &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;            &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;System.Diagnostics.TextWriterTraceListener&amp;quot;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;            &lt;span style="color: #ff0000"&gt;initializeData&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;E:\Temp\testtrace.txt&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt;       &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;remove&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Default&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;listeners&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt;   &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;trace&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;system.diagnostics&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;u&gt;Challenge – Differentiating our trace entries&lt;/u&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Use the category when &lt;a href="http://msdn.microsoft.com/en-us/library/247w289d.aspx"&gt;writing trace.&lt;/a&gt;Better use the category as &amp;lt;Namespace&amp;gt;.&amp;lt;TypeName&amp;gt;.&amp;lt;MethodName&amp;gt; and open or import the trace file in excel then filter rows based on category. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;u&gt;How to avoid the trace statements in production&lt;/u&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If we give the binaries which have the Trace code it will cause performance issues even though we are not using any listeners. It may be very slight in terms of CPU cycles which takes to check whether the trace listener is available or not.This is negligible in most cases but it may come to effect when this logging code is running a server which is supposed to server thousands of request per second.So we must avoid the Trace.write lines from the binaries at the compile time.Its easy &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In VS2010 Goto Project Properties-&amp;gt;Compile-&amp;gt;Advanced Compiler Settings-&amp;gt;Uncheck “Define Trace Constant”&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;u&gt;When to use&lt;/u&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Use this only when you don’t have any other debugging techniques available (test servers)and your logging mechanism feels complicated. Never miss the opportunity to debug using Visual studio in your own machine &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://lh5.ggpht.com/-tJIyhIQvSJU/Tj-c8OwVpGI/AAAAAAAAOWk/9zhzYpLA-oM/wlEmoticon-smile%25255B2%25255D.png?imgmax=800" /&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-1555948025979390266?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/WJ5PfJT11Hc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/1555948025979390266/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=1555948025979390266" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/1555948025979390266?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/1555948025979390266?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/WJ5PfJT11Hc/simple-net-trace.html" title="Simple .net trace" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/-tJIyhIQvSJU/Tj-c8OwVpGI/AAAAAAAAOWk/9zhzYpLA-oM/s72-c/wlEmoticon-smile%25255B2%25255D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2011/08/simple-net-trace.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DE4AQX86cCp7ImA9WhdQFUw.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-6174986714399544123</id><published>2011-08-16T23:19:00.000+05:30</published><updated>2011-08-16T23:19:00.118+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-16T23:19:00.118+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Keyword" /><category scheme="http://www.blogger.com/atom/ns#" term="object" /><category scheme="http://www.blogger.com/atom/ns#" term="WCF" /><title>Using Generic Type variables as method arguments</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/uP7xdnNASAmWshLWqTfqkjgHI2Y/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/uP7xdnNASAmWshLWqTfqkjgHI2Y/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/uP7xdnNASAmWshLWqTfqkjgHI2Y/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/uP7xdnNASAmWshLWqTfqkjgHI2Y/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Let me start with some theories before a practical scenario. We have base class named MyGenBase inherited from object which accept a generic variable and contains some Properties and there are many derived classes which are not generic.There is also a static method named Process() which needs to accept the base class as it is and manipulate the properties.ie the objects of derived classes will be coming into the Process() as arguments.So how to write the signature of the Process().If we simply use Process(proxy as MyGenBase(of T)) it cannot accept the generic variable&amp;#160; T.If we normally use just T as generic variable it cannot access the variables of MyGenBase.So the solution is to use the generic variable with constraint as follows.&lt;/p&gt;  &lt;p&gt;Process(of T)(proxy as MyGenBase(of T)) . &lt;/p&gt;  &lt;p&gt;Confused altogether? Sorry I am little bit weak in theory. Lets see a real life example.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Using ClientBase&amp;lt;T&amp;gt; as method arguement&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;This is about passing a &lt;a href="http://msdn.microsoft.com/en-us/library/ms576141(v=vs.95).aspx"&gt;ClientBase&amp;lt;T&amp;gt;&lt;/a&gt; type variable as method parameter. ClientBase&amp;lt;T&amp;gt; is a well known class and you might have&amp;#160; used or at least heard, if you have did anything in WCF.&lt;/p&gt;  &lt;p&gt;Suppose if we have to add a particular &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iendpointbehavior.aspx"&gt;behavior&lt;/a&gt; to the proxies which are created at the client side of our application based on some conditions we cannot use the application config files for sure.The only way left is add the behavior through code.For Eg: &lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt; CreateProxy() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; IDataService&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; proxy &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataServiceProxy&lt;br /&gt;        AddMyBehavior(proxy)&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;Return&lt;/span&gt; proxy&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; AddMyBehavior(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; proxy &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; DataServiceRemoteProxy)&lt;br /&gt;    &lt;span style="color: #008000"&gt;'Somecondition    If Then&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; behavior = &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; MyBehavior()&lt;br /&gt;    proxy.Endpoint.Behaviors.Add(behavior)&lt;br /&gt;    &lt;span style="color: #008000"&gt;'   End If&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Here the DataServiceProxy is the derived class of ClientBase with the generic type as IDataService ie declaration as &lt;br /&gt;&lt;br /&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;br /&gt;  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt; DataServiceRemoteProxy&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Inherits&lt;/span&gt; System.ServiceModel.ClientBase(Of IDataService)&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Implements&lt;/span&gt; IDataService&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Class&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This is very simple.But if we have more services such as EmployeeService,CustomerService etc…and we need to add the same behavior we need to think about a more generic way of AddMyBehavior.That means we need to accept common base class of DataServiceProxy and EmployeeServiceProxy which is nothing but ClientBase&amp;lt;T&amp;gt; where T may be IDataService or IEmployeeService.If we just use generic variable as T it cannot recognize the EndPoint property which is specific to the ClientBase.Since we don’t have a non generic base class of ClientBase most people uses object as parameter and writes non type safe code or dynamic keyword. &lt;br /&gt;  &lt;br /&gt;So the question here is how to make the AddMyBehavior to accept any proxy and add the behavior.In the first look it may be complicated and there will be a tendency to pass as object or use the dynamic keyword.But there is a typed way.See the below code snippet. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;br /&gt;  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;Friend&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Shared&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; AddMyBehavior(Of T &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Class&lt;/span&gt;)(&lt;span style="color: #0000ff"&gt;ByVal&lt;/span&gt; proxy &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; ClientBase(Of T))&lt;br /&gt;    &lt;span style="color: #008000"&gt;'Some condition If () Then&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; cookieBehavior = &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; MyCookieBehavior()&lt;br /&gt;        proxy.Endpoint.Behaviors.Add(cookieBehavior)&lt;br /&gt;    &lt;span style="color: #008000"&gt;'End If&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Here the ClientBase class accepts only the reference types.That’s why the Class keyword came into play. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Happy Coding!!!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-6174986714399544123?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/QLfaIjjqO7c" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/6174986714399544123/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=6174986714399544123" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/6174986714399544123?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/6174986714399544123?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/QLfaIjjqO7c/using-generic-type-variables-as-method.html" title="Using Generic Type variables as method arguments" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2011/08/using-generic-type-variables-as-method.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ak4CQXk5cSp7ImA9WhdRGU0.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-6228471063643298229</id><published>2011-08-09T22:26:00.000+05:30</published><updated>2011-08-09T22:26:00.729+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-09T22:26:00.729+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Web Development" /><category scheme="http://www.blogger.com/atom/ns#" term="IIS" /><category scheme="http://www.blogger.com/atom/ns#" term="Logging" /><title>IIS log analysis</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/lT-ll0uxOegptxbHTV0lqwwVnsk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lT-ll0uxOegptxbHTV0lqwwVnsk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/lT-ll0uxOegptxbHTV0lqwwVnsk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lT-ll0uxOegptxbHTV0lqwwVnsk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Recently I got a golden opportunity to go Microsoft campus located in Charlotte ,NC and work with Microsoft guys .It was related to capacity planning of our project.The project uses Silverlight technology and obviously there are WCF services to supply data to the Silverlight application.Our main aim was to do capacity planning for the WCF service side and also the database. There I got chance to work with some tools which are available for years but never used by me.One of the tool was &lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;amp;id=24659"&gt;IIS log parser&lt;/a&gt;.     &lt;br /&gt;As name implies it is the tool to parse iis logs using sql kind of queries.You can easily find out what are the top 10 file types your iis is serving or what are the top 10 urls which are requested more etc…If you are a web site production support person, this will be childish.But for a developer who just code web sites and haven’t seen how his code is performing in the production this will be a key for him to the production world.&lt;/p&gt;  &lt;p&gt;&lt;u&gt;&lt;strong&gt;What are IIS logs and where can I find?&lt;/strong&gt;&lt;/u&gt;     &lt;br /&gt;These are the log entries which IIS maintain for the requests it receive and serve.by default the logs will be in the %SystemDrive%\inetpub\logs\LogFiles folder in your machine.The log file writing is normally separated by number of factors.They are generated per web site , per day etc…Also we have option to specify which all fields should be included in the log files. For example we can avoid client IP address and referrer from the logging and add number of bytes sent and received.Ok now developers who doesn’t seen this might be excited to see the logs and how to configure it. Just open your IIS and select the Logging option at the right side and double click. Rest is very simple as some clicks.A screen shot below.&lt;img src="http://www.larrybrouwer.com/wp-content/uploads/2010/05/IIS7_W3C_Logging_Fields.jpg" /&gt;&lt;/p&gt;  &lt;p&gt;For more details about how to configure and analyze the logs see the below links. &lt;/p&gt;  &lt;p&gt;&lt;a title="http://technet.microsoft.com/en-us/library/cc732079%28WS.10%29.aspx" href="http://technet.microsoft.com/en-us/library/cc732079%28WS.10%29.aspx"&gt;http://technet.microsoft.com/en-us/library/cc732079%28WS.10%29.aspx&lt;/a&gt;    &lt;br /&gt;&lt;a title="http://blogs.iis.net/carlosag/archive/2010/03/25/analyze-your-iis-log-files-favorite-log-parser-queries.aspx" href="http://blogs.iis.net/carlosag/archive/2010/03/25/analyze-your-iis-log-files-favorite-log-parser-queries.aspx"&gt;http://blogs.iis.net/carlosag/archive/2010/03/25/analyze-your-iis-log-files-favorite-log-parser-queries.aspx&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-6228471063643298229?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/GNQg3S5P2uc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/6228471063643298229/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=6228471063643298229" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/6228471063643298229?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/6228471063643298229?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/GNQg3S5P2uc/iis-log-analysis.html" title="IIS log analysis" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2011/08/iis-log-analysis.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkUMQXo4eip7ImA9WhdRE0U.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-8861247165493669774</id><published>2011-08-03T21:48:00.000+05:30</published><updated>2011-08-03T21:48:00.432+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-03T21:48:00.432+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="sql" /><category scheme="http://www.blogger.com/atom/ns#" term="sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="Database" /><category scheme="http://www.blogger.com/atom/ns#" term="sql query" /><title>Collation and the temp tables</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/tM2vX_OhufS1VQYajKyK2f60DAM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/tM2vX_OhufS1VQYajKyK2f60DAM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/tM2vX_OhufS1VQYajKyK2f60DAM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/tM2vX_OhufS1VQYajKyK2f60DAM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;It’s a hack which I am going to describe in this post for the people who are working in tight delivery schedules. Hope everybody knows &lt;a href="http://msdn.microsoft.com/en-us/library/aa174903%28v=sql.80%29.aspx"&gt;what is collation&lt;/a&gt; in SQL Server and how it cause issues if we use database objects in different collations in a query. Also note the task involved in changing an existing &lt;a href="http://msdn.microsoft.com/en-us/library/ms179254.aspx"&gt;SQL Server instance to a different collation&lt;/a&gt; and how to &lt;a href="http://blogs.msdn.com/b/john_daskalakis/archive/2008/12/04/9174867.aspx"&gt;change collation of system databases such as temp database&lt;/a&gt; or any other user database.&lt;/p&gt;  &lt;p&gt;We were using SQL_Latin1_General_CP1_CI_AS collation till couple of months back and recently moved to Latin1_General_100_CI_AS_KS_WS collation. We created new database in Latin1_General_100_CI_AS_KS_WS and it worked in all the development machines without any issue .So we changed the testing servers to Latin1_General_100_CI_AS_KS_WS collation and it performed well. After some load testing we had to modify one SP which introduced &lt;strong&gt;temp tables&lt;/strong&gt;. As it is related to load testing we first applied in the test server and it rocked. But when we take the same sp to development machines the a problem raised because we didn’t change the sql server instances of our development machines to Latin1_General_100_CI_AS_KS_WS which is a good time consuming process. That means the temp database is in different collation compared to our project database.&lt;/p&gt;  &lt;p&gt;For example consider a simple scenario.We created a Address database in the Latin1_General_100_CI_AS_KS_WS collation where our sql server instance is in SQL_Latin1_General_CP1_CI_AS .We have a Person table (Id,Name) and Address Table (Id,PersonId,Address) which has person id as foreign key and we need to select details of some persons based on a particular person name list.Earlier we had a ‘in’ keyword based implementation and that we changed to temp table based implementation where the temp table is a table which has one column and it will be joined with the Address table to get the details. Ok its time to see some sql. &lt;/p&gt;  &lt;div&gt;   &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;CREATE&lt;/span&gt; &lt;span style="color: #0000ff"&gt;TABLE&lt;/span&gt; [dbo].[Person](&lt;br /&gt;    [Id] [&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;] &lt;span style="color: #0000ff"&gt;NOT&lt;/span&gt; &lt;span style="color: #0000ff"&gt;NULL&lt;/span&gt;,&lt;br /&gt;    [Name] [nvarchar](255) &lt;span style="color: #0000ff"&gt;NULL&lt;/span&gt;,&lt;br /&gt;&lt;span style="color: #0000ff"&gt;PRIMARY&lt;/span&gt; &lt;span style="color: #0000ff"&gt;KEY&lt;/span&gt; &lt;span style="color: #0000ff"&gt;CLUSTERED&lt;/span&gt; &lt;br /&gt;(&lt;br /&gt;    [Id] &lt;span style="color: #0000ff"&gt;ASC&lt;/span&gt;&lt;br /&gt;)&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;CREATE&lt;/span&gt; &lt;span style="color: #0000ff"&gt;TABLE&lt;/span&gt; [dbo].[Address](&lt;br /&gt;    [Id] [&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;] &lt;span style="color: #0000ff"&gt;NULL&lt;/span&gt;,&lt;br /&gt;    [PersonId] [&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;] &lt;span style="color: #0000ff"&gt;NULL&lt;/span&gt;,&lt;br /&gt;    [Address] [nvarchar](&lt;span style="color: #0000ff"&gt;max&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;NULL&lt;/span&gt;&lt;br /&gt;) &lt;span style="color: #0000ff"&gt;ON&lt;/span&gt; [&lt;span style="color: #0000ff"&gt;PRIMARY&lt;/span&gt;]&lt;br /&gt;&lt;span style="color: #0000ff"&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;ALTER&lt;/span&gt; &lt;span style="color: #0000ff"&gt;TABLE&lt;/span&gt; [dbo].[Address]  &lt;span style="color: #0000ff"&gt;WITH&lt;/span&gt; &lt;span style="color: #0000ff"&gt;CHECK&lt;/span&gt; &lt;span style="color: #0000ff"&gt;ADD&lt;/span&gt;  &lt;span style="color: #0000ff"&gt;CONSTRAINT&lt;/span&gt; [FK_Address_Person] &lt;span style="color: #0000ff"&gt;FOREIGN&lt;/span&gt; &lt;span style="color: #0000ff"&gt;KEY&lt;/span&gt;([PersonId])&lt;br /&gt;&lt;span style="color: #0000ff"&gt;REFERENCES&lt;/span&gt; [dbo].[Person] ([Id])&lt;/pre&gt;&lt;br /&gt;Here is the modified query to use the table variables which uses temp db.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;IF&lt;/span&gt; &lt;span style="color: #0000ff"&gt;NOT&lt;/span&gt; OBJECT_ID(&lt;span style="color: #006080"&gt;'tempdb..#Selected'&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;IS&lt;/span&gt; &lt;span style="color: #0000ff"&gt;NULL&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;DROP&lt;/span&gt; &lt;span style="color: #0000ff"&gt;TABLE&lt;/span&gt; #Selected;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;CREATE&lt;/span&gt; &lt;span style="color: #0000ff"&gt;TABLE&lt;/span&gt; #Selected&lt;br /&gt;(&lt;br /&gt;Name nvarchar(255)&lt;br /&gt;);&lt;br /&gt;--Logic &lt;span style="color: #0000ff"&gt;to&lt;/span&gt; fill the #Selected &lt;span style="color: #0000ff"&gt;table&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;select&lt;/span&gt; #Selected.Name,[Address].[Address]&lt;br /&gt;&lt;span style="color: #0000ff"&gt;from&lt;/span&gt;  #Selected &lt;span style="color: #0000ff"&gt;join&lt;/span&gt; Person &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;on&lt;/span&gt; #Selected.name = Person.Name &lt;br /&gt;        &lt;span style="color: #0000ff"&gt;join&lt;/span&gt; [Address] &lt;br /&gt;        &lt;span style="color: #0000ff"&gt;on&lt;/span&gt; Person.Id =[Address].PersonId;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;The error msg was “&lt;font color="#ff0000"&gt;Cannot resolve the collation conflict between &amp;quot;Latin1_General_100_CI_AS_KS_WS&amp;quot; and &amp;quot;SQL_Latin1_General_CP1_CI_AS&amp;quot; in the equal to operation.&lt;/font&gt;”. This means the temp DB is still in SQL_Latin1_General_CP1_CI_AS collation and our DB is in Latin1_General_100_CI_AS_KS_WS collation which doesn’t allow us to do a comparison on strings.So as a hack or quick work around in development environment, we modified the query as follows which specifies the collation on the comparison.&lt;br /&gt;&lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;IF&lt;/span&gt; &lt;span style="color: #0000ff"&gt;NOT&lt;/span&gt; OBJECT_ID(&lt;span style="color: #006080"&gt;'tempdb..#Selected'&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;IS&lt;/span&gt; &lt;span style="color: #0000ff"&gt;NULL&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;DROP&lt;/span&gt; &lt;span style="color: #0000ff"&gt;TABLE&lt;/span&gt; #Selected;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;CREATE&lt;/span&gt; &lt;span style="color: #0000ff"&gt;TABLE&lt;/span&gt; #Selected&lt;br /&gt;(&lt;br /&gt;Name nvarchar(255)&lt;br /&gt;);&lt;br /&gt;--Logic &lt;span style="color: #0000ff"&gt;to&lt;/span&gt; fill the #Selected &lt;span style="color: #0000ff"&gt;table&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;select&lt;/span&gt; #Selected.Name,[Address].[Address]&lt;br /&gt;&lt;span style="color: #0000ff"&gt;from&lt;/span&gt;  #Selected &lt;span style="color: #0000ff"&gt;join&lt;/span&gt; Person &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;on&lt;/span&gt; #Selected.name &lt;span style="color: #0000ff"&gt;collate&lt;/span&gt; Latin1_General_100_CI_AS_KS_WS= Person.Name &lt;span style="color: #0000ff"&gt;collate&lt;/span&gt; Latin1_General_100_CI_AS_KS_WS&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;join&lt;/span&gt; [Address] &lt;br /&gt;        &lt;span style="color: #0000ff"&gt;on&lt;/span&gt; Person.Id =[Address].PersonId;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Happy scripting…&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-8861247165493669774?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/ZvxyL7sHRHc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/8861247165493669774/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=8861247165493669774" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/8861247165493669774?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/8861247165493669774?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/ZvxyL7sHRHc/collation-and-temp-tables.html" title="Collation and the temp tables" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><thr:total>1</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2011/08/collation-and-temp-tables.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkQNQ3o8fCp7ImA9WhdSGE4.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-5521921856967678723</id><published>2011-07-28T10:41:00.001+05:30</published><updated>2011-07-28T10:49:52.474+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-28T10:49:52.474+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="sql" /><category scheme="http://www.blogger.com/atom/ns#" term="sql query" /><category scheme="http://www.blogger.com/atom/ns#" term="Puzzle" /><title>Conditional insert query without duplicates</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/94nbO85BBa9ywlZzoCW-AyuS5GM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/94nbO85BBa9ywlZzoCW-AyuS5GM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/94nbO85BBa9ywlZzoCW-AyuS5GM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/94nbO85BBa9ywlZzoCW-AyuS5GM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This is just a sql puzzle which raised during a long wait for the QA results on a build day.The puzzle seems simple.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Need to insert the records with out duplicates. &lt;/li&gt;    &lt;li&gt;The query should consider all the fields. &lt;/li&gt;    &lt;li&gt;The query should be single line.ie single statement of query execution. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;At first it feels simple as a simple where query. But when we start writing we realize that can we write a where clause in a insert query? Simply speaking how can we write a conditional insert query in sql.After we play with the sql server and queries we automatically come to the below query. &lt;/p&gt;  &lt;div&gt;   &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;INSERT &lt;span style="color: #0000ff"&gt;INTO&lt;/span&gt; Person (Name , EMail,Id) &lt;br /&gt;&lt;span style="color: #0000ff"&gt;select&lt;/span&gt; &lt;span style="color: #006080"&gt;'joy'&lt;/span&gt;, &lt;span style="color: #006080"&gt;'joymon@gmail.com'&lt;/span&gt;,1&lt;br /&gt;&lt;span style="color: #0000ff"&gt;WHERE&lt;/span&gt; (&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;SELECT&lt;/span&gt; &lt;span style="color: #0000ff"&gt;COUNT&lt;/span&gt;(*) &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;FROM&lt;/span&gt; Person &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;WHERE&lt;/span&gt; Name = &lt;span style="color: #006080"&gt;'joy'&lt;/span&gt; &lt;span style="color: #0000ff"&gt;and&lt;/span&gt; email=&lt;span style="color: #006080"&gt;'joymon@gmail.com'&lt;/span&gt; &lt;span style="color: #0000ff"&gt;and&lt;/span&gt; id=1) = 0;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;The table can be created using.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;CREATE&lt;/span&gt; &lt;span style="color: #0000ff"&gt;TABLE&lt;/span&gt; [dbo].[Person](&lt;br /&gt;    [Name] [&lt;span style="color: #0000ff"&gt;nchar&lt;/span&gt;](50) &lt;span style="color: #0000ff"&gt;NULL&lt;/span&gt;,&lt;br /&gt;    [Id] &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; &lt;span style="color: #0000ff"&gt;NOT&lt;/span&gt; &lt;span style="color: #0000ff"&gt;NULL&lt;/span&gt;,&lt;br /&gt;    [EMail] [&lt;span style="color: #0000ff"&gt;nchar&lt;/span&gt;](50) &lt;span style="color: #0000ff"&gt;NULL&lt;/span&gt;)&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-5521921856967678723?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/rwD1d5whdPQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/5521921856967678723/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=5521921856967678723" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/5521921856967678723?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/5521921856967678723?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/rwD1d5whdPQ/conditional-insert-query-without.html" title="Conditional insert query without duplicates" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2011/07/conditional-insert-query-without.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkENRHg-eip7ImA9WhdSEkw.&quot;"><id>tag:blogger.com,1999:blog-3053230616754516408.post-8054245122078584994</id><published>2011-07-21T08:03:00.000+05:30</published><updated>2011-07-21T08:54:55.652+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-21T08:54:55.652+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Decompiler" /><category scheme="http://www.blogger.com/atom/ns#" term="Debugging" /><title>ILSpy another replacement for Reflector</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/at9yszLDsn2fZoYDuM819CNtPqQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/at9yszLDsn2fZoYDuM819CNtPqQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/at9yszLDsn2fZoYDuM819CNtPqQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/at9yszLDsn2fZoYDuM819CNtPqQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;http://wiki.sharpdevelop.net/ilspy.ashx.&lt;br /&gt;Another reflector alternative like Telerik's &lt;a href="http://joymonscode.blogspot.com/2011/04/free-decompiler-from-telerik.html"&gt;Just Decompile&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;According to the ILSpy team..Development started after Red Gate &lt;a class="externallink" href="http://www.red-gate.com/products/dotnet-development/reflector/announcement" title="announced" target="_blank"&gt;announced&lt;/a&gt; that the free version of .NET Reflector would cease to exist by end of February 2011.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3053230616754516408-8054245122078584994?l=joymonscode.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JoymonV/sCode/~4/y6mgoML1KCE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://joymonscode.blogspot.com/feeds/8054245122078584994/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=3053230616754516408&amp;postID=8054245122078584994" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/8054245122078584994?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3053230616754516408/posts/default/8054245122078584994?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JoymonV/sCode/~3/y6mgoML1KCE/ilspy-another-replacement-for-reflector.html" title="ILSpy another replacement for Reflector" /><author><name>Joy George</name><uri>https://profiles.google.com/118323257832874630811</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-hfMp80mWU5w/AAAAAAAAAAI/AAAAAAAAOVs/62iSBL01wYo/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://joymonscode.blogspot.com/2011/07/ilspy-another-replacement-for-reflector.html</feedburner:origLink></entry></feed>

