<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">(Un)managed world... </title><subtitle type="html" /><id>http://blogs.msdn.com/ravi_kumar/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ravi_kumar/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/ravi_kumar/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2007-12-30T12:24:00Z</updated><entry><title>My 2 cents on MSPDBSRV.exe </title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ravi_kumar/archive/2009/06/17/my-2-cents-on-mspdbsrv-exe.aspx" /><id>http://blogs.msdn.com/ravi_kumar/archive/2009/06/17/my-2-cents-on-mspdbsrv-exe.aspx</id><published>2009-06-17T22:23:00Z</published><updated>2009-06-17T22:23:00Z</updated><content type="html">&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"&gt;I read about MSPDBSRV.exe the other day for one of my cases. I found it interesting and thought of sharing it with you. &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"&gt;Here is how things work. The Visual Studio uses MSPDBSRV.exe to generate the symbols (PDB files). All the requests related to creating, accessing or writing to PDB files are handled by mspdbsrv.exe. When a process issues a PDB request and mspdbsrv.exe is not alive, that process will spawn mspdbsrv.exe; but if mspdbsrv.exe is already alive, the living mspdbsrv.exe process will be used and no new process of mspdbsrv.exe will be spawned.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"&gt;Sometimes it is possible that mspdbsrv.exe stays alive even after the build is over. In such scenarios, it is safe to add a post build event to kill the mspdbsrv.exe. For more information on post-build events, you can check this &lt;A href="http://msdn.microsoft.com/en-us/library/ke5z92ks.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ke5z92ks.aspx"&gt;&lt;FONT color=#0000ff&gt;MSDN document&lt;/FONT&gt;&lt;/A&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"&gt;Hope you found this small and informative enough (I know nobody likes to read long endless blogs)! Will try to be alive in MSDN blogs from now on. See you all. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9770270" width="1" height="1"&gt;</content><author><name>Ravi Kumar</name><uri>http://blogs.msdn.com/members/Ravi+Kumar.aspx</uri></author><category term="MSPDBSRV.exe" scheme="http://blogs.msdn.com/ravi_kumar/archive/tags/MSPDBSRV.exe/default.aspx" /></entry><entry><title>Float to int conversion may return different values.</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ravi_kumar/archive/2008/10/29/float-to-int-conversion-may-return-different-values.aspx" /><id>http://blogs.msdn.com/ravi_kumar/archive/2008/10/29/float-to-int-conversion-may-return-different-values.aspx</id><published>2008-10-29T02:08:00Z</published><updated>2008-10-29T02:08:00Z</updated><content type="html">&lt;P&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: Arial; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-themecolor: text2"&gt;Hi there! Recently I remembered that I had an MSDN blog also which I haven't updated since ages! Let me add an interesting issue which I saw recently:&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: Arial; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-themecolor: text2"&gt;The following code results in different output when built and run from Visual Studio 2003 and Visual Studio 2008:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: Arial; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-themecolor: text2"&gt;Code&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: Arial; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-themecolor: text2"&gt;=====================&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;#include &amp;lt;stdio.h&amp;gt;&lt;BR&gt;&lt;BR&gt;void main()&lt;BR&gt;{&lt;BR&gt;&lt;BR&gt;float SinglePrecisionValue;&lt;BR&gt;long result;&lt;BR&gt;&lt;BR&gt;SinglePrecisionValue = 3.40282535e+37;&lt;BR&gt;&lt;BR&gt;result = (long)SinglePrecisionValue ;&lt;BR&gt;&lt;BR&gt;printf("%ld\n", result);&lt;BR&gt;&lt;BR&gt;}&lt;BR style="mso-special-character: line-break"&gt;&lt;BR style="mso-special-character: line-break"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Output&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;=========================&lt;BR&gt;1. Result from VS2003: 0&lt;BR&gt;2. Result from VS2008: -2147483648&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: Arial; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-themecolor: text2"&gt;So what is happening here? The code tries to convert a float value to long. So why are we getting different values from different compilers? &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: Arial; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-themecolor: text2"&gt;The C++ Standard says:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-themecolor: text2"&gt;An rvalue of a floating point type can be converted to an rvalue of an integer type. The conversion truncates; that is, the fractional part is discarded. &lt;B&gt;The behavior is undefined if the truncated value cannot be represented in the destination type.&lt;/B&gt; &lt;BR style="mso-special-character: line-break"&gt;&lt;BR style="mso-special-character: line-break"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-themecolor: text2"&gt;Results are incompatible only in cases where program behavior is undefined according to C/C++ Standards. The conversion from Float to int is backward compatible till everything is according to the C++ standards. The problem happens only when truncated value cannot be represented in the destination type. This is the case here. So both the results are expected. We cannot expect undefined behavior to result in same output from two different compilers!&lt;BR style="mso-special-character: line-break"&gt;&lt;BR style="mso-special-character: line-break"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: Arial; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-themecolor: text2"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9021137" width="1" height="1"&gt;</content><author><name>Ravi Kumar</name><uri>http://blogs.msdn.com/members/Ravi+Kumar.aspx</uri></author></entry><entry><title>My Team's Blog!</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ravi_kumar/archive/2008/07/01/my-team-s-blog.aspx" /><id>http://blogs.msdn.com/ravi_kumar/archive/2008/07/01/my-team-s-blog.aspx</id><published>2008-07-01T22:50:00Z</published><updated>2008-07-01T22:50:00Z</updated><content type="html">&lt;P&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: Arial; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"&gt;Hey Folks, my team at Microsoft (Developer Support VC++ &amp;amp; C#) has come up with a blog. It will mostly have posts related to issues faced by developers and the troubleshooting steps or methods to analyze and resolve those . &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: Arial; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: Arial; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: Arial; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"&gt;Check this out: &lt;A href="http://blogs.msdn.com/dsvc"&gt;http://blogs.msdn.com/dsvc&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8678441" width="1" height="1"&gt;</content><author><name>Ravi Kumar</name><uri>http://blogs.msdn.com/members/Ravi+Kumar.aspx</uri></author><category term="Developer Support Visual C" scheme="http://blogs.msdn.com/ravi_kumar/archive/tags/Developer+Support+Visual+C/default.aspx" /><category term="DSVC" scheme="http://blogs.msdn.com/ravi_kumar/archive/tags/DSVC/default.aspx" /><category term="VC#" scheme="http://blogs.msdn.com/ravi_kumar/archive/tags/VC_2300_/default.aspx" /></entry><entry><title>Out of Memory Issues To Watch Out For When Using Regular Expressions.</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ravi_kumar/archive/2008/03/22/out-of-memory-issues-to-watch-out-for-when-using-regular-expressions.aspx" /><id>http://blogs.msdn.com/ravi_kumar/archive/2008/03/22/out-of-memory-issues-to-watch-out-for-when-using-regular-expressions.aspx</id><published>2008-03-22T02:54:00Z</published><updated>2008-03-22T02:54:00Z</updated><content type="html">&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'; mso-bidi-font-family: Arial"&gt;Hi Guys! It has been a while since I wrote my last post. I had been very busy last month with all the cases flowing in. Recently I worked on a very tricky issue related to OutOfMemoryException. This blog is about that case.&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV class=section&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;STRONG&gt;&lt;FONT size=3&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;STRONG&gt;&lt;FONT size=3&gt;How to reproduce OutOfMemoryException in this scenario&lt;/FONT&gt;&lt;/STRONG&gt;:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;Create a managed application in Visual Studio 2008 which reads a large input text file into a string. Then&amp;nbsp;use many instances of System.Text.RegularExpressions.Regex to replace parts of this string one after another.&amp;nbsp; Run this application in a 32 bit or 64 bit machine.&lt;BR&gt;&lt;BR&gt;Example code snippet (in C#): &lt;BR&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Read the content of file Test.txt into string abc.&lt;BR&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Let us assume the file test.txt is huge. (around 20 MB)&lt;BR&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string path = @"C:\Test.txt"; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; StreamReader sr = File.OpenText(path);&amp;nbsp;&lt;/SPAN&gt; 
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string strFileContents = sr.ReadToEnd(); &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string abc = strFileContents;&lt;/SPAN&gt; 
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Apply Regex objects to replace parts of the huge string &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Regex rx1 = new Regex("xyz"); if (rx1.IsMatch(abc)) { abc = rx1.Replace(abc, "XYZ"); }&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Regex rx2 = new Regex("xyz1"); if (rx2.IsMatch(abc)) { abc = rx2.Replace(abc, "XYZ1"); } &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Regex rx3 = new Regex("xyz2"); if (rx3.IsMatch(abc)) { abc = rx3.Replace(abc, "XYZ2"); } &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ................................ &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ................................ &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ................................&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;A class="" title=KSIAnchor2 name=KSIAnchor2&gt;&lt;/A&gt;
&lt;H2&gt;&lt;NOBR&gt;&lt;FONT size=3&gt;Run the app and&lt;/FONT&gt;.......&lt;/NOBR&gt;&lt;/H2&gt;
&lt;DIV class=section&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 12pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;This may throw System.OutOfMemoryException. The Exception details may be the following: &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 12pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;System.OutOfMemoryException was unhandled&amp;nbsp;&lt;/SPAN&gt; 
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 12pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp; Message="Exception of type 'System.OutOfMemoryException' was thrown."&amp;nbsp;&lt;/SPAN&gt; 
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 12pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp; Source="mscorlib"&amp;nbsp;&lt;/SPAN&gt; 
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 12pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp; StackTrace: &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at System.String.GetStringForStringBuilder(String value, Int32 startIndex, Int32 length, Int32 capacity) &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at System.Text.StringBuilder.GetNewString(String currentString, Int32 requiredLength) &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at System.Text.StringBuilder.Append(String value, Int32 startIndex, Int32 count) &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at System.Text.RegularExpressions.RegexReplacement.Replace(Regex regex, String input, Int32 count, Int32 startat) &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at System.Text.RegularExpressions.Regex.Replace(String input, String replacement, Int32 count, Int32 startat) &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at System.Text.RegularExpressions.Regex.Replace(String input, String replacement)&amp;nbsp;&lt;/SPAN&gt; 
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;A class="" title=KSIAnchor3 name=KSIAnchor3&gt;&lt;/A&gt;
&lt;H2&gt;&lt;NOBR&gt;&lt;FONT size=3&gt;Root Cause:&lt;/FONT&gt;&lt;/NOBR&gt;&lt;/H2&gt;
&lt;DIV class=section&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;There are two possible root causes of OutOfMemoryException here:&lt;BR&gt;1) The Garbage collector may not be collecting the Regex objects because they have not left scope. &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;2) This issue may happen because of the huge size of the string. &lt;/SPAN&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;The Regex.Replace method creates a second string for&amp;nbsp;the replace operation. So at that time a second copy of the really large string will be created, which may cause an OutOfMemoryException. &lt;/SPAN&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;A class="" title=KSIAnchor4 name=KSIAnchor4&gt;&lt;/A&gt;
&lt;H2&gt;&lt;NOBR&gt;&lt;FONT size=3&gt;How to fix it:&lt;/FONT&gt;&lt;/NOBR&gt;&lt;/H2&gt;
&lt;DIV class=section&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;1)&lt;/SPAN&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 7pt; FONT-FAMILY: 'Times New Roman','serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;We &lt;/SPAN&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;should always assume that objects will not be available for Garbage Collection until the reference or root has left scope, regardless of whether it will ever be used again.&amp;nbsp;The runtime cannot be relied upon to always know when an object will not be used again.&amp;nbsp;We have to rely on the language rules with respect to variable scoping, or set objects to null explicitly when they will not be used again. &lt;BR&gt;&lt;BR&gt;Example code snippet (in C#):&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Set the Regex objects to null explicitly once they will not be used in the code.&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Regex rx1 = new Regex("xyz"); if (rx1.IsMatch(abc)) { abc = rx1.Replace(abc, "XYZ"); } &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rx1 = null; &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Regex rx2 = new Regex("xyz1"); if (rx2.IsMatch(abc)) { abc = rx2.Replace(abc, "XYZ1"); } &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rx2 = null; &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Regex rx3 = new Regex("xyz2"); if (rx3.IsMatch(abc)) { abc = rx3.Replace(abc, "XYZ2"); } &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rx3 = null;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt; 
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ................................ &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ................................ &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 36pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ................................ &lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;BR&gt;2) "Chunk-up the data” such that string sizes don’t get too big.&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;A class="" title=KSIAnchor5 name=KSIAnchor5&gt;&lt;/A&gt;
&lt;H2&gt;&lt;NOBR&gt;&lt;FONT size=3&gt;Check these too:&lt;/FONT&gt;&lt;/NOBR&gt;&lt;/H2&gt;
&lt;DIV class=section&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;SPAN&gt;
&lt;P class=MsoListParagraph style="MARGIN: 7.5pt 15pt 7.5pt 32.2pt; TEXT-INDENT: -18pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;SPAN&gt;1)&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Verdana','sans-serif'"&gt;How to match a pattern by using regular expressions and Visual C#:&lt;B&gt; &lt;/B&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;A href="http://support.microsoft.com/kb/308252" mce_href="http://support.microsoft.com/kb/308252"&gt;&lt;FONT color=#800080&gt;http://support.microsoft.com/kb/308252&lt;/FONT&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Verdana','sans-serif'"&gt; &lt;/SPAN&gt;&lt;/B&gt;
&lt;P class=MsoListParagraph style="MARGIN: 7.5pt 15pt 7.5pt 32.2pt; TEXT-INDENT: -18pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;SPAN&gt;2)&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Verdana','sans-serif'"&gt;Regex class: &lt;A href="http://msdn2.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx"&gt;&lt;FONT color=#800080&gt;http://msdn2.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx&lt;/FONT&gt;&lt;/A&gt; &lt;/SPAN&gt;
&lt;P class=MsoListParagraph style="MARGIN: 7.5pt 15pt 7.5pt 32.2pt; TEXT-INDENT: -18pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;SPAN&gt;3)&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Verdana','sans-serif'"&gt;You may like this thread going on which talks about RegEx performance: &lt;A href="http://channel9.msdn.com/ShowPost.aspx?PostID=348549" mce_href="http://channel9.msdn.com/ShowPost.aspx?PostID=348549"&gt;&lt;FONT color=#800080&gt;http://channel9.msdn.com/ShowPost.aspx?PostID=348549&lt;/FONT&gt;&lt;/A&gt; &lt;/SPAN&gt;
&lt;P class=MsoListParagraph style="MARGIN: 7.5pt 15pt 7.5pt 32.2pt; TEXT-INDENT: -18pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;SPAN&gt;4)&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'"&gt;Regex Class represent an immutable regular expression: &lt;A href="http://lab.msdn.microsoft.com/restapistubs/content/6f7hht7k/en-us;vs.71/primary/mtps.failsafe" mce_href="http://lab.msdn.microsoft.com/restapistubs/content/6f7hht7k/en-us;vs.71/primary/mtps.failsafe"&gt;&lt;FONT color=#800080&gt;http://lab.msdn.microsoft.com/restapistubs/content/6f7hht7k/en-us;vs.71/primary/mtps.failsafe&lt;/FONT&gt;&lt;/A&gt;&lt;SPAN style="COLOR: black"&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;P class=MsoListParagraph style="MARGIN: 7.5pt 15pt 7.5pt 32.2pt; TEXT-INDENT: -18pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;SPAN&gt;5)&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Verdana','sans-serif'"&gt;RegEx static methods vs. instance methods: &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;A href="http://forums.sqladvice.com/post.aspx?id=2248" mce_href="http://forums.sqladvice.com/post.aspx?id=2248"&gt;&lt;FONT color=#800080&gt;http://forums.sqladvice.com/post.aspx?id=2248&lt;/FONT&gt;&lt;/A&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8330211" width="1" height="1"&gt;</content><author><name>Ravi Kumar</name><uri>http://blogs.msdn.com/members/Ravi+Kumar.aspx</uri></author><category term="RegEx OutOfMemoryException C# &amp;quot;Large String&amp;quot;" scheme="http://blogs.msdn.com/ravi_kumar/archive/tags/RegEx+OutOfMemoryException+C_2300_+_2600_quot_3B00_Large+String_2600_quot_3B00_/default.aspx" /></entry><entry><title>LINQ - What, Why and How!! (Part - 2)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ravi_kumar/archive/2008/02/09/linq-what-why-and-how-part-2.aspx" /><link rel="enclosure" type="application/vnd.openxmlformats-officedocument.pres" length="195141" href="http://blogs.msdn.com/ravi_kumar/attachment/7549912.ashx" /><id>http://blogs.msdn.com/ravi_kumar/archive/2008/02/09/linq-what-why-and-how-part-2.aspx</id><published>2008-02-09T04:48:00Z</published><updated>2008-02-09T04:48:00Z</updated><content type="html">&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: Arial; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"&gt;&lt;FONT size=3&gt;Here comes the second (and last) part of my LINQ presentation. Please check the attachment file. (LINQ - 2.pptx).&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7549912" width="1" height="1"&gt;</content><author><name>Ravi Kumar</name><uri>http://blogs.msdn.com/members/Ravi+Kumar.aspx</uri></author></entry><entry><title>LINQ - What, Why and How!! (Part - 1)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ravi_kumar/archive/2008/02/09/linq-what-why-and-how.aspx" /><link rel="enclosure" type="application/vnd.openxmlformats-officedocument.pres" length="358877" href="http://blogs.msdn.com/ravi_kumar/attachment/7549673.ashx" /><id>http://blogs.msdn.com/ravi_kumar/archive/2008/02/09/linq-what-why-and-how.aspx</id><published>2008-02-09T04:28:00Z</published><updated>2008-02-09T04:28:00Z</updated><content type="html">&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt; LINE-HEIGHT: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"&gt;&lt;SPAN lang=EN style="FONT-SIZE: 12pt; mso-ansi-language: EN; mso-bidi-font-family: Arial; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-IN"&gt;&lt;FONT face=Calibri&gt;Hey friends, I have attched part-one of my LINQ presentation (LINQ-1.pptx) here. LINQ is one of the cool new features in .NET framework 3.5. It allows us to do type-safe query of relational database, XML file and even in-memory tables. In more general terms, it applies to all sources of IEnumerable&amp;lt;T&amp;gt; types. &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt; LINE-HEIGHT: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"&gt;&lt;SPAN lang=EN style="FONT-SIZE: 12pt; mso-ansi-language: EN; mso-bidi-font-family: Arial; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-IN"&gt;&lt;FONT face=Calibri&gt;LINQ uses many new fewtures introduced in .NET Framework 3.5. For e.g.:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL type=disc&gt;
&lt;LI class=MsoNormal style="MARGIN: 0cm 0cm 10pt; LINE-HEIGHT: normal; mso-list: l0 level1 lfo1; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; tab-stops: list 36.0pt"&gt;&lt;FONT face=Calibri&gt;&lt;SPAN lang=EN style="FONT-SIZE: 12pt; mso-ansi-language: EN; mso-bidi-font-family: Arial; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-IN"&gt;Partial methods&lt;/SPAN&gt;&lt;SPAN lang=EN style="FONT-SIZE: 12pt; mso-ansi-language: EN; mso-bidi-font-family: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-IN"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0cm 0cm 10pt; LINE-HEIGHT: normal; mso-list: l0 level1 lfo1; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; tab-stops: list 36.0pt"&gt;&lt;SPAN lang=EN style="FONT-SIZE: 12pt; mso-ansi-language: EN; mso-bidi-font-family: Arial; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-IN"&gt;&lt;FONT face=Calibri&gt;Local Variable Type Inference.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0cm 0cm 10pt; LINE-HEIGHT: normal; mso-list: l0 level1 lfo1; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; tab-stops: list 36.0pt"&gt;&lt;SPAN lang=EN style="FONT-SIZE: 12pt; mso-ansi-language: EN; mso-bidi-font-family: Arial; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-IN"&gt;&lt;FONT face=Calibri&gt;Extension methods... (My Favorite!! :))&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0cm 0cm 10pt; LINE-HEIGHT: normal; mso-list: l0 level1 lfo1; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; tab-stops: list 36.0pt"&gt;&lt;SPAN lang=EN style="FONT-SIZE: 12pt; mso-ansi-language: EN; mso-bidi-font-family: Arial; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-IN"&gt;&lt;FONT face=Calibri&gt;Lambda expression.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0cm 0cm 10pt; LINE-HEIGHT: normal; mso-list: l0 level1 lfo1; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; tab-stops: list 36.0pt"&gt;&lt;SPAN lang=EN style="FONT-SIZE: 12pt; mso-ansi-language: EN; mso-bidi-font-family: Arial; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-IN"&gt;&lt;FONT face=Calibri&gt;Query expression.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0cm 0cm 10pt; LINE-HEIGHT: normal; mso-list: l0 level1 lfo1; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; tab-stops: list 36.0pt"&gt;&lt;SPAN lang=EN style="FONT-SIZE: 12pt; mso-ansi-language: EN; mso-bidi-font-family: Arial; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-IN"&gt;&lt;FONT face=Calibri&gt;Contextual Keywords, etc...&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt; LINE-HEIGHT: normal; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"&gt;&lt;SPAN lang=EN style="FONT-SIZE: 12pt; mso-ansi-language: EN; mso-bidi-font-family: Arial; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-IN"&gt;&lt;FONT face=Calibri&gt;I have tried to explain these new features in my presentation as without these, LINQ wasn't possible.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7549673" width="1" height="1"&gt;</content><author><name>Ravi Kumar</name><uri>http://blogs.msdn.com/members/Ravi+Kumar.aspx</uri></author><category term="Partial Method" scheme="http://blogs.msdn.com/ravi_kumar/archive/tags/Partial+Method/default.aspx" /><category term="Lambda Expression" scheme="http://blogs.msdn.com/ravi_kumar/archive/tags/Lambda+Expression/default.aspx" /><category term="LINQ" scheme="http://blogs.msdn.com/ravi_kumar/archive/tags/LINQ/default.aspx" /><category term="Extension Method" scheme="http://blogs.msdn.com/ravi_kumar/archive/tags/Extension+Method/default.aspx" /></entry><entry><title>Loader lock issue in mixed mode application</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ravi_kumar/archive/2008/01/17/loader-lock-issue-in-mixed-mode-application.aspx" /><id>http://blogs.msdn.com/ravi_kumar/archive/2008/01/17/loader-lock-issue-in-mixed-mode-application.aspx</id><published>2008-01-18T02:49:00Z</published><updated>2008-01-18T02:49:00Z</updated><content type="html">&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify"&gt;&lt;SPAN lang=EN-US style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;STRONG&gt;ISSUE:&lt;/STRONG&gt; &amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify"&gt;&lt;SPAN lang=EN-US style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;I am back with another mixed-mode situation.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;An issue may happen when the native class constructor calls a managed function.&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify"&gt;&lt;SPAN lang=EN-US style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;For example, Let us say we have a C# application which is calling a C++ DLL using DLL Import attribute. The C++ DLL has a class whose constructor initializes a few variables and also calls a managed function. This may lead to &lt;STRONG&gt;loader lock&lt;/STRONG&gt; issue.&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify"&gt;&lt;SPAN lang=EN-US style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;STRONG&gt;CAUSE&lt;/STRONG&gt;: &lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify"&gt;&lt;SPAN lang=EN-US style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Let us see why this issue may happen. There are two distinct mechanisms for loading an execution module (EXE or DLL):&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpFirst style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; TEXT-ALIGN: justify; mso-list: l0 level1 lfo1; mso-add-space: auto"&gt;&lt;SPAN lang=EN-US style="mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;1)&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-US style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;One for Windows, which is used for unmanaged modules,&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpLast style="MARGIN: 0cm 0cm 10pt; TEXT-INDENT: 36pt; TEXT-ALIGN: justify; mso-list: l0 level1 lfo1; mso-add-space: auto"&gt;&lt;SPAN lang=EN-US style="mso-ansi-language: EN-US; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;2)&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-US style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;One for the .NET Common Language Runtime (CLR) which loads managed assemblies. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify"&gt;&lt;SPAN lang=EN-US style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;When an assembly containing only .NET constructs is loaded into a process, the CLR loader can perform all of the necessary loading and initialization tasks itself. However, for mixed assemblies, because they can contain native code and data, the Windows loader must also be used. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify"&gt;&lt;SPAN lang=EN-US style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;The Windows loader guarantees that no code can access code or data in that DLL before it has been initialized, and that no code can redundantly load the DLL while it is partially initialized. To do this, the Windows loader uses a process-global critical section (often called the "loader lock") that prevents unsafe access during module initialization. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify"&gt;&lt;SPAN lang=EN-US style="mso-ansi-language: EN-US"&gt;&lt;FONT face=Calibri size=3&gt;If we attempt to execute managed functions when this loader lock is held, the CLR will attempt to automatically load the managed assembly, which may require the Windows loader to block on the loader lock. Since the loader lock is already held by code earlier in the call sequence, a deadlock results. However, it is possible that the required managed assembly has already been successfully loaded by other code. In that case, the deadlock will not happen. This &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Verdana','sans-serif'"&gt;makes this scenario difficult to diagnose and fix as the situation does not guarantee that a deadlock will happen.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify"&gt;&lt;SPAN lang=EN-US style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify"&gt;&lt;SPAN lang=EN-US style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;STRONG&gt;RESOLUTION:&lt;/STRONG&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify"&gt;&lt;SPAN lang=EN-US style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;So to avoid this problem, we should make sure that the native constructor doesn’t have any managed function call. We can call that managed function outside the constructor which lets the native DLL to get initialized successfully. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify"&gt;&lt;SPAN lang=EN-US style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&lt;STRONG&gt;&lt;BR&gt;Thumb Rule:&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify"&gt;&lt;SPAN lang=EN-US style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;Do NOT call a managed function in&amp;nbsp;constructor of an unmanaged class.&lt;/FONT&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7144674" width="1" height="1"&gt;</content><author><name>Ravi Kumar</name><uri>http://blogs.msdn.com/members/Ravi+Kumar.aspx</uri></author><category term="Loader lock" scheme="http://blogs.msdn.com/ravi_kumar/archive/tags/Loader+lock/default.aspx" /></entry><entry><title>An intereseting issue in mixed-mode application</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/ravi_kumar/archive/2007/12/30/an-intereseting-issue-in-mixed-mode-application.aspx" /><id>http://blogs.msdn.com/ravi_kumar/archive/2007/12/30/an-intereseting-issue-in-mixed-mode-application.aspx</id><published>2007-12-30T15:24:00Z</published><updated>2007-12-30T15:24:00Z</updated><content type="html">&lt;P style="TEXT-ALIGN: justify"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'; mso-bidi-font-family: Arial"&gt;A few definitions to start with:&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-ALIGN: justify"&gt;&lt;STRONG&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'; mso-bidi-font-family: Arial"&gt;Managed code&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'; mso-bidi-font-family: Arial"&gt;: Code executing under the control of the CLR is called managed code. For example, any code written in C# or Visual Basic .NET is managed code.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-ALIGN: justify"&gt;&lt;STRONG&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'; mso-bidi-font-family: Arial"&gt;Unmanaged code&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'; mso-bidi-font-family: Arial"&gt;: Code that runs outside the CLR is referred to as "unmanaged code." COM components, ActiveX components, and Win32 API functions are examples of unmanaged code.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-ALIGN: justify"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'; mso-bidi-font-family: Arial"&gt;Users may&amp;nbsp;have a mixed-mode application where a managed code is accessing an unmanaged code or vice-versa. There are three technologies which enable managed/unmanaged interaction:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN-LEFT: 36pt; TEXT-INDENT: -18pt; TEXT-ALIGN: justify; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana"&gt;&lt;SPAN style="mso-list: Ignore"&gt;1)&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'; mso-bidi-font-family: Arial"&gt;Platform Invoke (P/Invoke)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN-LEFT: 36pt; TEXT-INDENT: -18pt; TEXT-ALIGN: justify; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana"&gt;&lt;SPAN style="mso-list: Ignore"&gt;2)&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'; mso-bidi-font-family: Arial"&gt;COM Interop&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN-LEFT: 36pt; TEXT-INDENT: -18pt; TEXT-ALIGN: justify; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana"&gt;&lt;SPAN style="mso-list: Ignore"&gt;3)&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'; mso-bidi-font-family: Arial"&gt;C++ Interop (&lt;B style="mso-bidi-font-weight: normal"&gt;IJW&lt;/B&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-ALIGN: justify"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'; mso-bidi-font-family: Arial"&gt;I am writing about the third technology here. We should use C++ interop for wrapping complex unmanaged flat APIs, or for wrapping unmanaged flat APIs that are changing while managed code is under development. C++ interop allows direct access to unmanaged APIs—which requires no rewriting, just the inclusion of a header file. The wrapper is compiled using /clr compiler switch which generates mixed-mode native/managed output.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-ALIGN: justify"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'; mso-bidi-font-family: Arial"&gt;The header of native C++ code is included in the managed wrapper. This causes the native C++ code to get compiled as managed code. Sometimes this may cause problems.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-ALIGN: justify"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'; mso-bidi-font-family: Arial"&gt;One of such problems may happen when the application has some static or global objects. The life time of such objects is until module unloading happens. So these objects are destructed at the end, even after the CLR is shut down. To avoid any error, we should make sure that these objects are purely unmanaged. We should not have any global objects that use .NET. All managed objects should be destroyed before the CLR shuts down.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-ALIGN: justify"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'; mso-bidi-font-family: Arial"&gt;As I wrote earlier, native code gets compiled as managed when their headers are included in managed code. The native code may have global or static objects which become managed in this way. The destructor of such objects will be called after the CLR is shut down which causes BOOTUP_EXCEPTION_COMPLUS exception to be raised. The application will crash just before it exits. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-ALIGN: justify"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'; mso-bidi-font-family: Arial"&gt;To solve such issues, we should wrap the include statements of these native header files (which&amp;nbsp;declare classes whoes global objects exist) in the managed C++ code as follows: &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'; mso-bidi-font-family: Arial"&gt;//Managed code file&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Verdana','sans-serif'; mso-bidi-font-family: Arial"&gt;//compile the native file as unmanaged: &lt;B style="mso-bidi-font-weight: normal"&gt;&lt;BR&gt;#pragma managed(push, off) &lt;BR&gt;&lt;/B&gt;#include &amp;lt;xyz.h&amp;gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;//The unmanaged code header.&lt;BR&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;#pragma managed(pop)&lt;o:p&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Verdana','sans-serif'"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Verdana','sans-serif'"&gt;The above wrapper statements cause the compilation of class declared in “xyz.h” as unmanaged. This solves the issue. The application can have a global or static object of this class.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6908383" width="1" height="1"&gt;</content><author><name>Ravi Kumar</name><uri>http://blogs.msdn.com/members/Ravi+Kumar.aspx</uri></author><category term="IJW" scheme="http://blogs.msdn.com/ravi_kumar/archive/tags/IJW/default.aspx" /><category term="0xC0020001" scheme="http://blogs.msdn.com/ravi_kumar/archive/tags/0xC0020001/default.aspx" /><category term="Managed C++ wrapper" scheme="http://blogs.msdn.com/ravi_kumar/archive/tags/Managed+C_2B002B00_+wrapper/default.aspx" /></entry></feed>