<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Miscellaneous Debris</title><subtitle type="html">Avner Kashtan&amp;#39;s Frustrations and Exultations</subtitle><id>http://weblogs.asp.net/avnerk/atom.aspx</id><link rel="alternate" type="text/html" href="http://weblogs.asp.net/avnerk/default.aspx" /><link rel="self" type="application/atom+xml" href="http://weblogs.asp.net/avnerk/atom.aspx" /><generator uri="http://communityserver.org" version="3.0.20510.895">Community Server</generator><updated>2007-09-03T15:34:00Z</updated><entry><title>Saving Your Settings</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/avnerk/archive/2009/02/10/saving-your-settings.aspx" /><id>http://weblogs.asp.net/avnerk/archive/2009/02/10/saving-your-settings.aspx</id><published>2009-02-10T14:38:51Z</published><updated>2009-02-10T14:38:51Z</updated><content type="html">&lt;p&gt;Tomorrow I am bidding my laptop farewell, and will soon buy me a new one. This results in what I like to call Settings Anxiety. I spend months tuning various aspects of my computer to my liking, and starting afresh with a new machine is wearisome. There are solutions to this, of course. I can make a full settings backup using &lt;a href="http://support.microsoft.com/kb/928635"&gt;Windows Easy Transfer&lt;/a&gt; or some such tool to store my settings and registry information and reload them on my new computer. I am, however, leery of it. First of all, I don’t trust WET to backup everything, especially 3rd party settings and application data. Secondly, I don’t want to copy all the cruft that’s accumulated in my user settings. One advantage to leaving the old computer is to start fresh.&lt;/p&gt;  &lt;p&gt;So my compromise is to do a set of manual exports for various pieces of software, to carry it with me to the new computer, whenever it arrives. I’m going to list the various programs I use here that I bothered to customize, and detail the steps needed to do a manual export. This way I can come back to it the next time I reformat.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;1. Outlook 2007&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;I use Outlook to connect to an Exchange server and to Gmail via IMAP. Both of these use OST files for local offline caching, but the primary storage is on the server. No real need for me to back this up.&lt;/p&gt;  &lt;p&gt;Unfortunately, there’s no way to export my Outlook profile’s entire Accounts list to a file, and reimport it later. It means I always have to go to Gmail’s help page to remember the port numbers they use for encrypted IMAP and SMTP, but it’s not too much of a hassle.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;2. Visual Studio 2008&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Two important customizations here – color scheme (I like grey background) and keyboard shortcuts (single-click build-current-project ftw!). Both are easily exported using &lt;strong&gt;Tools –&amp;gt; Import and Export Settings –&amp;gt; Export selected environment settings.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;3. Google Chrome&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Bookmarks, cookies and stored passwords – things I really don’t feel like retyping again and again after I got my Chrome to memorize it for me. Basically, with all major browsers importing favorites and settings from one another, you only really need to backup one browser’s settings.&lt;/p&gt;  &lt;p&gt;Unfortunately, Google haven’t quite gotten around to implementing Export Settings in Chrome – like a lot of other things. To backup my settings, I am copying the &lt;strong&gt;C:\Users\&lt;em&gt;username&lt;/em&gt;\AppData\Local\Google\Chrome\User Data&lt;/strong&gt; folder. There’s a lot of useless junk there – the cache, Google Gears data – but it should contain all the interesting bits too.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;4. RSSBandit&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;RSSBandit’s “Export Feeds” option will probably export the feed definitions, but not the actual text of the actual feeds that I already have, offline, in my reader. It &lt;em&gt;does&lt;/em&gt; support exporting the list of items in a feed, including read/unread state, though. But a better solution, assuming I am unbothered by space or time, is to use RSS Bandit’s “&lt;strong&gt;Remote Storage&lt;/strong&gt;” option to save the entire feed database to a ZIP file that can be “downloaded” into a new installation. Under &lt;strong&gt;Tools –&amp;gt; Options –&amp;gt; Remote Storage&lt;/strong&gt; set the destination (I use a file share), then do &lt;strong&gt;Tools –&amp;gt; Upload Feeds.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;When recovering, I’ve found that RSS Bandit doesn’t always succeed in reading the ZIP file – I got a “file was closed” error. What I did was simply open the ZIP file and copy all the XML files into the &lt;strong&gt;%AppData%\RssBandit &lt;/strong&gt;folder, &lt;em&gt;et voila.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;5. Windows Live Writer&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Another useful tool that wasn’t given an Export Settings option. There are two things to backup here:&lt;/p&gt;  &lt;p&gt;1. My blog settings – I have 5 different blogs I manage through WLW. Here I had to go back to the Registry. Funny how it seems so old-fashioned. Export all settings from &lt;strong&gt;HKEY_CURRENT_USER\Software\Microsoft\Windows Live\Writer.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;2. Blog drafts and recently-written posts are stored in &lt;strong&gt;My Documents\My Weblog Posts&lt;/strong&gt;. Would be a good idea to back those up as well.&lt;/p&gt;  &lt;p&gt;3. When restoring settings, it initially appears that while the blog settings are properly recovered, the drafts aren’t. All you need to do, though, is double-click on one of the .wpost files in the My Weblog Posts folder, and the Drafts and Recently Posted lists will get populated.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;6. Digsby&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Digsby, the multi-protocol IM and Social Networking tool, uses a centralized login to store the settings of my different protocols – so I only need to log in with my Digsby ID to have all my IM networks working. There are some tweaks to the client itself which I would like to not lose, but they don’t provide an Export Settings feature either, and it’s nothing I can’t live without.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;For most other things, I’d rather not bother until I actually need it.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6896838" width="1" height="1"&gt;</content><author><name>Avner Kashtan</name><uri>http://weblogs.asp.net/members/Avner-Kashtan.aspx</uri></author><category term="Miscellaneous Debris" scheme="http://weblogs.asp.net/avnerk/archive/tags/Miscellaneous+Debris/default.aspx" /></entry><entry><title>Tales from the Unmanaged Side – System.String –&gt; char* (pt. 2)</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/avnerk/archive/2009/01/13/tales-from-the-unmanaged-side-system-string-gt-char-pt-2.aspx" /><id>http://weblogs.asp.net/avnerk/archive/2009/01/13/tales-from-the-unmanaged-side-system-string-gt-char-pt-2.aspx</id><published>2009-01-13T15:04:17Z</published><updated>2009-01-13T15:04:17Z</updated><content type="html">&lt;p&gt;A while ago, I &lt;a href="http://weblogs.asp.net/avnerk/archive/2007/08/28/more-tales-from-the-unmanaged-side-system-string-gt-char.aspx"&gt;posted an entry&lt;/a&gt; about marshalling a managed System.String into an unmanaged C string, specifically a plain char*. The solution I suggested, back in 2007, involved calling Marshal::StringToHGlobalAuto method to allocate memory and copy the string data into it, and then cast the HGlobal pointer into a char*. &lt;/p&gt;  &lt;p&gt;It seems that in Visual Studio 2008 a new way of doing it was added, as part of the new &lt;a href="http://msdn.microsoft.com/en-us/library/bb384865.aspx"&gt;Marshalling Library&lt;/a&gt;. This library provides a whole set of conversions between System.String and popular unmanaged string representations, like char*, wchar_t*, BSTR, CStringT&amp;lt;wchar_t&amp;gt; and others I am even less familiar with. &lt;/p&gt;  &lt;p&gt;The smarter string representations, like std::string, have their own destructors so I can carelessly let them drop out of scope without worrying about leaks. The more primitive ones, like char*, need to be explicitly released, so that’s why the Marshalling Library contains a new (managed) class called marshal_context which gives me exactly this explicit release.&lt;/p&gt;  &lt;p&gt;Let’s compare my old code with the new:&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;char&lt;/span&gt;* unmanagedString = NULL;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    String^ managedString = gcnew String(&lt;span class="str"&gt;&amp;quot;managed string&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    &lt;span class="rem"&gt;// Note the double cast.&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    unmanagedString = (&lt;span class="kwrd"&gt;char&lt;/span&gt;*)(&lt;span class="kwrd"&gt;void&lt;/span&gt;*)Marshal::StringToHGlobalAnsi(managedString);&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;}&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;&lt;span class="kwrd"&gt;finally&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;    &lt;span class="rem"&gt;// Don't forget to release. Note the ugly casts again.&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;    Marshal::FreeHGlobal((IntPtr)(&lt;span class="kwrd"&gt;void&lt;/span&gt;*)unmanagedString);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;And the new:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;marshal_context^ context = gcnew marshal_context();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;String^ managedString = gcnew String(&lt;span class="str"&gt;&amp;quot;managed string&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;char&lt;/span&gt;* unmanagedString = context-&amp;gt;marshal_as&amp;lt;&lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;char&lt;/span&gt;*&amp;gt;( managedString );&lt;/pre&gt;

  &lt;pre&gt;&amp;#160;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Much shorter, I’m sure you’ll agree. And neater – no need for all the icky, icky casting between different pointer types. And most importantly, I don’t have to explicitly release the char* – the marshal_context class keeps a reference to all the strings that were marshalled through it, and when it goes out of scope its destructor makes sure to release them all. Very efficient, all in all.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6833885" width="1" height="1"&gt;</content><author><name>Avner Kashtan</name><uri>http://weblogs.asp.net/members/Avner-Kashtan.aspx</uri></author><category term=".NET" scheme="http://weblogs.asp.net/avnerk/archive/tags/.NET/default.aspx" /><category term="CodeSnippets" scheme="http://weblogs.asp.net/avnerk/archive/tags/CodeSnippets/default.aspx" /><category term="C++/CLI" scheme="http://weblogs.asp.net/avnerk/archive/tags/C_2B002B002F00_CLI/default.aspx" /></entry><entry><title>Static Constructor throws the same exception again and again</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/avnerk/archive/2008/12/16/static-constructor-throws-the-same-exception-again-and-again.aspx" /><id>http://weblogs.asp.net/avnerk/archive/2008/12/16/static-constructor-throws-the-same-exception-again-and-again.aspx</id><published>2008-12-16T10:17:39Z</published><updated>2008-12-16T10:17:39Z</updated><content type="html">&lt;p&gt;Here’s a little gotcha I ran into today – if you have code in a class’s static constructor that throws an exception, we will get a TypeInitializationException with the original exception as the InnerException – so far, nothing new. &lt;/p&gt;  &lt;p&gt;However, if we keep on calling methods on that object, we’ll keep receiving TypeInitializationExceptions. If it cannot be initialized, it cannot be called. Every time we try, we’ll receive the &lt;em&gt;exact same exception&lt;/em&gt;. However, the static ctor will &lt;em&gt;not&lt;/em&gt; be called again. What appears to happen is that the CLR caches the TypeInitializationException object itself, InnerException included, and rethrows it whenever the type is called.&lt;/p&gt;  &lt;p&gt;What are the ramifications? Well, we received an OutOfMemoryException in our static ctor, but the outer exception was caught and tried again. So we got an OutOfMemoryException again, even though the memory problem was behind us, which sent us down the wrong track of looking for persistent memory problems. Theoretically, it could also be a leak – the inner exception holding some sort of reference that is never released, but that’s an edge case.&lt;/p&gt;  &lt;p&gt;Here’s some code to illustrate the problem. The output clearly shows that while we wait a second between calls, the inner exception contains the time of the original exception, not any subsequent calls. Debugging also shows that the static ctor is called only once.&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 5; i++)&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;            &lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;            {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;                Thread.Sleep(1000);&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;                StaticClass.Method();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;            }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;            &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;            {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;                Console.WriteLine(ex.InnerException.Message);&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;            }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;        }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;        Console.ReadLine();&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;}&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; StaticClass&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  25:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  26:  &lt;/span&gt;    &lt;span class="kwrd"&gt;static&lt;/span&gt; StaticClass()&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  27:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  28:  &lt;/span&gt;        &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Exception(&lt;span class="str"&gt;&amp;quot;Exception thrown at &amp;quot;&lt;/span&gt; + DateTime.Now.ToString());&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  29:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  30:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  31:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Method()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  32:  &lt;/span&gt;    { }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  33:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  34:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6790065" width="1" height="1"&gt;</content><author><name>Avner Kashtan</name><uri>http://weblogs.asp.net/members/Avner-Kashtan.aspx</uri></author><category term=".NET" scheme="http://weblogs.asp.net/avnerk/archive/tags/.NET/default.aspx" /><category term="CodeSnippets" scheme="http://weblogs.asp.net/avnerk/archive/tags/CodeSnippets/default.aspx" /><category term="C#" scheme="http://weblogs.asp.net/avnerk/archive/tags/C_2300_/default.aspx" /></entry><entry><title>Upgrading all projects to .NET 3.5</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/avnerk/archive/2008/05/25/upgrading-all-projects-to-net-3-5.aspx" /><id>http://weblogs.asp.net/avnerk/archive/2008/05/25/upgrading-all-projects-to-net-3-5.aspx</id><published>2008-05-25T08:56:14Z</published><updated>2008-05-25T08:56:14Z</updated><content type="html">&lt;p&gt;A simple macro to change the Target Framework for a project from .NET 2.0 to .NET 3.5, hacked together in a few minutes. This will fail for C++/CLI projects, and possibly VB.NET projects (haven't checked). Works fine for regular C# projects, as well as web projects:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;For&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Each&lt;/span&gt; proj &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Project &lt;span style="color: #0000ff"&gt;In&lt;/span&gt; DTE.Solution.Projects
   &lt;span style="color: #0000ff"&gt;Try&lt;/span&gt;
       proj.Properties.Item(&lt;span style="color: #006080"&gt;&amp;quot;TargetFramework&amp;quot;&lt;/span&gt;).Value = 196613
       Debug.Print(&lt;span style="color: #006080"&gt;&amp;quot;Upgraded {0} to 3.5&amp;quot;&lt;/span&gt;, proj.Name)
   &lt;span style="color: #0000ff"&gt;Catch&lt;/span&gt; ex &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Exception
       Debug.Print(&lt;span style="color: #006080"&gt;&amp;quot;Failed to upgrade {0} to 3.5&amp;quot;&lt;/span&gt;, proj.Name)
   &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Try&lt;/span&gt;

&lt;span style="color: #0000ff"&gt;Next&lt;/span&gt; proj&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Why 196613, you ask? Well, when I see such a number my first instinct is to feed it into calc.exe and switch it to hexadecimal. And I was right: 196613 in decimal converts to 0x00030005 - You can see the framework version hiding in there. Major version in the high word, minor in the low word. The previous TargetFramework number was 131072 - 0x00020000, or 2.0.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;(Nitpickers might point out that I could simply set it to &amp;amp;30005 rather than messing with the obscure decimal number. They would be correct - but I got to this number through the debugger, so that's how it will stay)&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6219753" width="1" height="1"&gt;</content><author><name>Avner Kashtan</name><uri>http://weblogs.asp.net/members/Avner-Kashtan.aspx</uri></author><category term=".NET" scheme="http://weblogs.asp.net/avnerk/archive/tags/.NET/default.aspx" /><category term="CodeSnippets" scheme="http://weblogs.asp.net/avnerk/archive/tags/CodeSnippets/default.aspx" /><category term="Visual Studio" scheme="http://weblogs.asp.net/avnerk/archive/tags/Visual+Studio/default.aspx" /><category term="C#" scheme="http://weblogs.asp.net/avnerk/archive/tags/C_2300_/default.aspx" /><category term="C++/CLI" scheme="http://weblogs.asp.net/avnerk/archive/tags/C_2B002B002F00_CLI/default.aspx" /></entry><entry><title>Sneaking past the SharePoint Usage Log</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/avnerk/archive/2008/04/16/sneaking-past-the-sharepoint-usage-log.aspx" /><id>http://weblogs.asp.net/avnerk/archive/2008/04/16/sneaking-past-the-sharepoint-usage-log.aspx</id><published>2008-04-16T15:13:16Z</published><updated>2008-04-16T15:13:16Z</updated><content type="html">&lt;p&gt;I'm writing a piece of code that regularly polls a MOSS server and checks several files. This can happen quite a few times a day, and this totally skews my Usage Reports for my sites. &lt;/p&gt;  &lt;p&gt;Does anyone know of a way to tell MOSS to ignore calls made by a specific user, a specific IP (my code runs on a dedicated server), a specific UserAgent or whatever?&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6103478" width="1" height="1"&gt;</content><author><name>Avner Kashtan</name><uri>http://weblogs.asp.net/members/Avner-Kashtan.aspx</uri></author><category term="SharePoint" scheme="http://weblogs.asp.net/avnerk/archive/tags/SharePoint/default.aspx" /></entry><entry><title>Any signs of life for the SharePoint Extensions for Visual Studio?</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/avnerk/archive/2008/01/23/any-signs-of-life-for-the-sharepoint-extensions-for-visual-studio.aspx" /><id>http://weblogs.asp.net/avnerk/archive/2008/01/23/any-signs-of-life-for-the-sharepoint-extensions-for-visual-studio.aspx</id><published>2008-01-23T19:57:31Z</published><updated>2008-01-23T19:57:31Z</updated><content type="html">&lt;p&gt;Has anything been released - or, in fact, talked about - since August's release of the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=3e1dcccd-1cca-433a-bb4d-97b96bf7ab63&amp;amp;displaylang=en"&gt;v1.1 CTP&lt;/a&gt;?&lt;/p&gt;  &lt;p&gt;Haven't done any web-part development in a while and wanted to get back in the game. I last used the v1.0 extensions, and was surprised that nothing much has changed in that field except for the CTP release, and even that can't be downloaded - I just get a broken link.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5640711" width="1" height="1"&gt;</content><author><name>Avner Kashtan</name><uri>http://weblogs.asp.net/members/Avner-Kashtan.aspx</uri></author><category term=".NET" scheme="http://weblogs.asp.net/avnerk/archive/tags/.NET/default.aspx" /><category term="SharePoint" scheme="http://weblogs.asp.net/avnerk/archive/tags/SharePoint/default.aspx" /></entry><entry><title>Seeking advice - strong names and config files</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/avnerk/archive/2007/12/20/seeking-advice-strong-names-and-config-files.aspx" /><id>http://weblogs.asp.net/avnerk/archive/2007/12/20/seeking-advice-strong-names-and-config-files.aspx</id><published>2007-12-20T11:48:49Z</published><updated>2007-12-20T11:48:49Z</updated><content type="html">&lt;p&gt;I'll use my blog for a bit of fishing for advice and guidance on an issue that's been bugging me.&lt;/p&gt; &lt;p&gt;We've been moving towards using strong names on all of our assemblies. The benefits are obvious, and it's a must before we deploy to clients out in the wild.&lt;/p&gt; &lt;p&gt;The problem is that we have several different processes running, each with its own app.config or web.config file. These config files contain references to custom configuration sections, whether they're application configuration, Enterprise Library extensions or whatnot. Seeing as my DLLs are signed, I have to use the fully qualified assembly name in all my references. This means that in a nightly build scenario where my version number is bumped continuously, I have to change 5-6 references in 5-6 configuration files with every build. &lt;/p&gt; &lt;p&gt;Doing this kind of string manipulation on a large scale scares me, since it can break, or we miss something. I've tried using &amp;lt;assemblyBinding&amp;gt; and &amp;lt;bindingRedirect&amp;gt; directives, but they require a specific version to point to as well.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;I'm sure I'm not the first person to encounter this problem. What are the solutions that you use to bypass this? Scripts as part of the automated installation? Moving all configuration sections to a separate assembly whose version is static? What's the least painful way to manage this?&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5477771" width="1" height="1"&gt;</content><author><name>Avner Kashtan</name><uri>http://weblogs.asp.net/members/Avner-Kashtan.aspx</uri></author><category term=".NET" scheme="http://weblogs.asp.net/avnerk/archive/tags/.NET/default.aspx" /><category term="General Software Development" scheme="http://weblogs.asp.net/avnerk/archive/tags/General+Software+Development/default.aspx" /></entry><entry><title>System.Diagnostics.EventLogEntry and the non-equal Equals.</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/avnerk/archive/2007/11/25/system-diagnostics-eventlogentry-and-the-non-equal-equals.aspx" /><id>http://weblogs.asp.net/avnerk/archive/2007/11/25/system-diagnostics-eventlogentry-and-the-non-equal-equals.aspx</id><published>2007-11-25T18:12:21Z</published><updated>2007-11-25T18:12:21Z</updated><content type="html">&lt;p&gt;Just a quick heads-up in case you're stumped with this problem, or just passing by:&lt;/p&gt; &lt;p&gt;The System.Diagnostics.EventLogEntry class implements the Equals method to check if two entries are identical, even if they're not the same instance. However, contrary to best practices, it does NOT overload the operator==, so these two bits of code will behave differently:&lt;/p&gt; &lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;EventLog myEventLog = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; EventLog(&lt;span style="color: #006080"&gt;"Application"&lt;/span&gt;);
EventLogEntry entry1 = myEventLog.Entries[0];
EventLogEntry entry2 = myEventLog.Entries[0];

&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; correct = entry1.Equals(entry2);
&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; incorrect = entry1 == entry2;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;After running this code, &lt;em&gt;correct &lt;/em&gt;will be true while &lt;em&gt;incorrect &lt;/em&gt;will be false.&lt;/p&gt;
&lt;p&gt;Good to know, if you're reading event logs in your code.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5336119" width="1" height="1"&gt;</content><author><name>Avner Kashtan</name><uri>http://weblogs.asp.net/members/Avner-Kashtan.aspx</uri></author><category term=".NET" scheme="http://weblogs.asp.net/avnerk/archive/tags/.NET/default.aspx" /><category term="CodeSnippets" scheme="http://weblogs.asp.net/avnerk/archive/tags/CodeSnippets/default.aspx" /><category term="C#" scheme="http://weblogs.asp.net/avnerk/archive/tags/C_2300_/default.aspx" /></entry><entry><title>Displaying live log file contents</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/avnerk/archive/2007/11/21/displaying-live-log-file-contents.aspx" /><id>http://weblogs.asp.net/avnerk/archive/2007/11/21/displaying-live-log-file-contents.aspx</id><published>2007-11-21T14:12:54Z</published><updated>2007-11-21T14:12:54Z</updated><content type="html">&lt;p&gt;I'm writing some benchmarking code, which involves a Console application calling a COM+ hosted process and measuring performance. I want to constantly display results on my active console, but since some of my code is running out-of-process, I can't really write directly to the console from all parts of the system. Not to mention the fact that I want it logged to a file as well.&lt;/p&gt; &lt;p&gt;So I cobbled together a quick Log class that does two things - it writes to a shared log file, keeping no locks so several processes can access it (I do serialize access to the WriteLine method itself, though). I don't mind the overhead of opening/closing the file every time, since this isn't production code.&lt;/p&gt; &lt;p&gt;The second method is the interesting one - it monitors the log file and returns every new line that is appended to it. If no lines are available, it will block until one is reached. The fun part was using the &lt;font face="Courier New"&gt;yield return&lt;/font&gt; keyword, which I've been looking for an excuse to use for quiet a while now.&lt;/p&gt; &lt;p&gt;Note that there are many places this code can go wrong or should be improved. There is no way to stop it running, only when the application is stopped. I bring this as the basic idea, and it can be cleaned up and improved later:&lt;/p&gt; &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt; &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; IEnumerable&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; ReadNextLineOrBlock()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt;         {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;             &lt;span style="color: #008000"&gt;// Open the file without locking it.&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (FileStream logFile = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; FileStream(Filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (StreamReader reader = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; StreamReader(logFile))&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;             {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;while&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;                 {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;                     &lt;span style="color: #008000"&gt;// Read the next line.&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;                     &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; line = reader.ReadLine();&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;                     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.IsNullOrEmpty(line))&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;                     {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;                         &lt;span style="color: #0000ff"&gt;yield&lt;/span&gt; &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; line;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;                     }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt;                     &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt;                     {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  17:&lt;/span&gt;                         Thread.Sleep(100);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  18:&lt;/span&gt;                     }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  19:&lt;/span&gt;                 }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  20:&lt;/span&gt;             }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  21:&lt;/span&gt;         }&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This method can now be called from a worker thread:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; StartListenerThread()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt;         {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;             Thread t = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Thread(&lt;span style="color: #0000ff"&gt;delegate&lt;/span&gt;()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;             {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;while&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;                 {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;                     &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; line &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; Log.ReadNextLineOrBlock())&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;                     {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;                         &lt;span style="color: #008000"&gt;// I added some formatting, too.&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;                         &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (line.Contains(&lt;span style="color: #006080"&gt;"Total"&lt;/span&gt;))&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;                             Console.ForegroundColor = ConsoleColor.Green;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;                         &lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;                         Console.WriteLine(line);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt;                         Console.ForegroundColor = ConsoleColor.White;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt;                     }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  17:&lt;/span&gt;                 }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  18:&lt;/span&gt;             });&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  19:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  20:&lt;/span&gt;             t.Start();&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  21:&lt;/span&gt;         }&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5305166" width="1" height="1"&gt;</content><author><name>Avner Kashtan</name><uri>http://weblogs.asp.net/members/Avner-Kashtan.aspx</uri></author><category term=".NET" scheme="http://weblogs.asp.net/avnerk/archive/tags/.NET/default.aspx" /><category term="CodeSnippets" scheme="http://weblogs.asp.net/avnerk/archive/tags/CodeSnippets/default.aspx" /><category term="C#" scheme="http://weblogs.asp.net/avnerk/archive/tags/C_2300_/default.aspx" /></entry><entry><title>Another minor C#/C++ difference - adding existing files</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/avnerk/archive/2007/10/28/another-minor-c-c-difference-adding-existing-files.aspx" /><id>http://weblogs.asp.net/avnerk/archive/2007/10/28/another-minor-c-c-difference-adding-existing-files.aspx</id><published>2007-10-28T14:35:24Z</published><updated>2007-10-28T14:35:24Z</updated><content type="html">&lt;p&gt;Another minor detail that bit me for a few minutes today. I'm posting this so I'll see it and remember, and possibly lodge it in other people's consciousness.&lt;/p&gt; &lt;p&gt;Using Visual Studio 2005, adding an existing .cs file to a C# project will cause a copy of that file to be created in the project directory. If I want to link to the original file, I need to explicitly choose Add As Link from the dropdown on the Add button. &lt;/p&gt; &lt;p&gt;C++ projects, however, have the opposite behavior. Adding an existing item in a different folder will add a link to the original file in the original location. To create a copy, manually copy it to the project dir.&lt;/p&gt; &lt;p&gt;That is all.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=4801261" width="1" height="1"&gt;</content><author><name>Avner Kashtan</name><uri>http://weblogs.asp.net/members/Avner-Kashtan.aspx</uri></author><category term="Visual Studio" scheme="http://weblogs.asp.net/avnerk/archive/tags/Visual+Studio/default.aspx" /><category term="C#" scheme="http://weblogs.asp.net/avnerk/archive/tags/C_2300_/default.aspx" /><category term="C++/CLI" scheme="http://weblogs.asp.net/avnerk/archive/tags/C_2B002B002F00_CLI/default.aspx" /></entry><entry><title>Another Sharepoint Web Services rant : untyped data vs. incompletely typed data</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/avnerk/archive/2007/09/06/another-sharepoint-web-services-rant-untyped-data-vs-incompletely-typed-data.aspx" /><id>http://weblogs.asp.net/avnerk/archive/2007/09/06/another-sharepoint-web-services-rant-untyped-data-vs-incompletely-typed-data.aspx</id><published>2007-09-06T13:18:37Z</published><updated>2007-09-06T13:18:37Z</updated><content type="html">&lt;p&gt;Working with the Web Services in WSSv2 and v3 is an exercise in sheer frustration. I've written before about serious and &lt;a href="http://weblogs.asp.net/avnerk/archive/2007/07/02/no-per-item-permissions-in-wssv3-s-web-services.aspx"&gt;glaring&lt;/a&gt; &lt;a href="http://weblogs.asp.net/avnerk/archive/2007/07/18/some-more-glaring-omissions-in-the-sharepoint-2007-sdk-and-web-services.aspx"&gt;omissions&lt;/a&gt; in the Web Services API that Sharepoint exposes, but it's not only the things missing, it's the lack of consistency in the APIs that ARE implemented that's annoying.&lt;/p&gt; &lt;p&gt;For most of the APIs, the return value for most methods is an XmlNode, usually documented pretty well in the SDK. It means we have to fiddle with XML to extract data, but it's not so bad. For instance the Lists WS's GetListCollection()&amp;nbsp;returns a known, documented, schema-linked XML containing many properties for a given list.&lt;/p&gt; &lt;p&gt;For some reason, though, the SiteData web service chooses to return data as typed objects instead - oddly named objects at that (_sList, _sWebWithMetadata[], and so forth), but only for SOME data. The GetSite() method, for instance, will return a typed metadata object for the site metadata and the list of Lists, but a completely untyped STRING containing XML data for the list of groups and group members. &lt;/p&gt; &lt;p&gt;Futhermore, these XML snippets are sometimes undocumented, and you have to try it out to see what you get. What you get, sometimes, is the same XML you would get from a call to a different web service, but stripped of the namespace - so even though it's the same structure, you can't use the same code to parse both.&lt;/p&gt; &lt;p&gt;Similarly the GetListCollection() method in SiteData. It returns a typed array of _sList objects which map to the XML that's returned from the ListsWS method, only for some reason, some oft the XML attributes are NOT mapped, and are inaccessible. So if I want to see whether a list is Hidden or not, I am unable to use the typed objects and have to resort to the loose XML manipulation. &lt;/p&gt; &lt;p&gt;Seriously, these rants are adding up. Does anyone know who's in charge of the web services for Sharepoint and why they're so badly designed? No consistency, missing functionality, bad documentation - what's going on here? This isn't v1, either, but very little seems to have changed since the original documentation for WSS v2 in 2003.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=3766279" width="1" height="1"&gt;</content><author><name>Avner Kashtan</name><uri>http://weblogs.asp.net/members/Avner-Kashtan.aspx</uri></author></entry><entry><title>Return of the GC Hole: Another one from the C++/CLI trenches</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/avnerk/archive/2007/09/06/return-of-the-gc-hole-another-one-from-the-c-cli-trenches.aspx" /><id>http://weblogs.asp.net/avnerk/archive/2007/09/06/return-of-the-gc-hole-another-one-from-the-c-cli-trenches.aspx</id><published>2007-09-06T11:09:18Z</published><updated>2007-09-06T11:09:18Z</updated><content type="html">&lt;p&gt;A few days ago I wrote of a &lt;a href="http://weblogs.asp.net/avnerk/archive/2007/08/28/a-c-coder-in-a-c-cli-world-part-1.aspx"&gt;GC hole&lt;/a&gt; I accidently created in my C++/CLI code (with thanks to commenter &lt;a href="http://weblogs.asp.net/avnerk/archive/2007/08/28/a-c-coder-in-a-c-cli-world-part-1.aspx#3645664"&gt;Nish&lt;/a&gt; for the name of the phenomenon). I had the following&amp;nbsp;code snippet set inside a private function:&lt;/p&gt; &lt;p&gt;&lt;font face="courier new"&gt;&amp;nbsp;&amp;nbsp; pin_ptr&amp;lt;Byte&amp;gt; pinnedBuffer = &amp;amp;data[0];&lt;br&gt;&amp;nbsp;&amp;nbsp; char* buffer = (char*)pinnedBuffer;&lt;/font&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;p&gt;Because the pin_ptr went out of scope when the function ended, I had a pointer to a memory location that was quickly moved by the GC, and got me a whole buffer full of garbage. To avoid that, I moved those two lines of code to my main method and pinned it throughout that method.  &lt;p&gt;I thought that was the end of that, but today I noticed that I was still getting garbage occasionally in my buffer. This stumped me for a bit - it seemed like the pin_ptr wasn't doing its job&amp;nbsp;- until I noticed how my C++ code looked: &lt;p&gt;&lt;font face="courier new"&gt;public void DoStuff (array&amp;lt;Byte&amp;gt;^ data)&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="courier new"&gt;char* buffer;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="courier new"&gt;if (data.Length &amp;gt; 0)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;pin_ptr&amp;lt;Byte&amp;gt; pinnedBuffer = &amp;amp;data[0];&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;buffer = (char*)pinnedBuffer;&lt;br&gt;}&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Courier New"&gt;// Now do stuff&lt;/font&gt;&lt;/p&gt; &lt;p&gt;For C++ programmers this is probably obvious. For me and other C# devs, not so much.&amp;nbsp;C++'s scoping rules say that when the &lt;em&gt;if&lt;/em&gt; block terminates, the pin_ptr&amp;lt;Byte&amp;gt; goes out of scope immediately. This causes the pinned memory to be released, and allows the GC to move my array. Meanwhile my unmanaged code goes over the &lt;em&gt;buffer &lt;/em&gt;and reads data. If I'm lucky, the GC won't start until I'm finished and all is well. If the GC IS active, I can either get garbage data (whatever is now pointed to by &lt;em&gt;buffer&lt;/em&gt;) or, even worse, an access violation if I now point to protected memory. &lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=3765107" width="1" height="1"&gt;</content><author><name>Avner Kashtan</name><uri>http://weblogs.asp.net/members/Avner-Kashtan.aspx</uri></author></entry><entry><title>Windows Services, services.msc and the "This Service is marked for deletion" error.</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/avnerk/archive/2007/09/05/windows-services-services-msc-and-the-quot-this-service-is-marked-for-deletion-quot-error.aspx" /><id>http://weblogs.asp.net/avnerk/archive/2007/09/05/windows-services-services-msc-and-the-quot-this-service-is-marked-for-deletion-quot-error.aspx</id><published>2007-09-05T09:14:54Z</published><updated>2007-09-05T09:14:54Z</updated><content type="html">&lt;p&gt;In my current project, we have a windows service that we are developing and debugging, which involves a lot of installing/uninstalling the service. One common problem when uninstalling a service is that while the uninstallation is successful, you still see the service listed in the Services console(services.msc). If you try to start it, stop it or uninstall it again (using installutil.exe or &lt;em&gt;sc delete&lt;/em&gt;) you get an uninformative "This service has been marked for deletion".&lt;/p&gt; &lt;p&gt;The &lt;a href="http://support.microsoft.com/kb/823942"&gt;KB article&lt;/a&gt;&amp;nbsp;about this problem suggests you restart the computer, which is pretty much overkill. Sure, it'll work, but you'll never find out what caused it in the first place. Turns out it's a pretty simple affair: just make sure you close the Services console,&amp;nbsp;which apparently holds a handle of some sort to it.&amp;nbsp;You don't have to do it &lt;em&gt;before&lt;/em&gt; you uninstall. The minute you close the console, all services marked for deletion will be deleted, and all will be well. &lt;/p&gt; &lt;p&gt;When doing it on a server, it's important to make sure you've closed all Services consoles on all active sessions. I've seen this error happen when no console was open, and it was fixed by running Task Manager and killing all instances of mmc.exe. I could have logged on to the other sessions and closed it gracefully, but I was lazy. Did the trick.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=3746342" width="1" height="1"&gt;</content><author><name>Avner Kashtan</name><uri>http://weblogs.asp.net/members/Avner-Kashtan.aspx</uri></author><category term="General Software Development" scheme="http://weblogs.asp.net/avnerk/archive/tags/General+Software+Development/default.aspx" /><category term="Installer" scheme="http://weblogs.asp.net/avnerk/archive/tags/Installer/default.aspx" /></entry><entry><title>Dynamically creating a Sharepoint Web-Service proxy instance</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/avnerk/archive/2007/09/03/dynamically-creating-a-sharepoint-web-service-proxy-instance.aspx" /><id>http://weblogs.asp.net/avnerk/archive/2007/09/03/dynamically-creating-a-sharepoint-web-service-proxy-instance.aspx</id><published>2007-09-03T16:55:35Z</published><updated>2007-09-03T16:55:35Z</updated><content type="html">&lt;p&gt;In my current code, I find myself accessing many Sharepoint web services. In one run of code I can access 5-6 different web services on dozens of different sites, not necessarily even on the same server. Given that I find myself writing a lot of boilerplate code looking like this:&lt;/p&gt; &lt;p&gt;&lt;font face="Courier New"&gt;using (SiteData siteDataWS = new SiteData())&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp; siteDataWS.Credentials = CredentialsCache.DefaultNetworkCredentials;&lt;br&gt;&amp;nbsp;&amp;nbsp; siteDataWS.Url = currentSite.ToString() + "/_vti_bin/SiteData.asmx";&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp; // Do something with the WS.&lt;br&gt;}&lt;/font&gt;&lt;/p&gt; &lt;p&gt;Seeing as this is quite wearisome, I've decided to go an genericize it. Given also that the name of the ASMX file for all Sharepoint services is the same as the name of the class to be instantiated, it gets even shorter:&lt;/p&gt; &lt;p&gt;&lt;font face="courier new"&gt;1: &amp;nbsp;public static WSType CreateWebService&amp;lt;WSType&amp;gt; (Uri siteUrl) where WSType : SoapHttpClientProtocol, new()&lt;br&gt;&lt;font face="courier new"&gt;2: &lt;/font&gt;{&lt;br&gt;&lt;font face="courier new"&gt;3: &lt;/font&gt;&amp;nbsp;&amp;nbsp; WSType webService = new WSType();&lt;br&gt;&lt;font face="courier new"&gt;4: &lt;/font&gt;&amp;nbsp;&amp;nbsp; webService.Credentials = CredentialCache.DefaultNetworkCredentials; &lt;/font&gt; &lt;p&gt;&lt;font face="courier new"&gt;&lt;font face="courier new"&gt;5: &lt;/font&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;string webServiceName = typeof(WSType).Name;&lt;br&gt;&lt;font face="courier new"&gt;6: &lt;/font&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;webService.Url = string.Format("{0}/_vti_bin/{1}.asmx", siteUrl, webServiceName); &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="courier new"&gt;&lt;font face="courier new"&gt;7: &lt;/font&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return webService;&lt;br&gt;&lt;font face="courier new"&gt;8: &lt;/font&gt;}&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="tre"&gt;Line 1: Define a generic method that receives the type of Web Service and returns an instance of it. Note the generic constraints - the type must be a Web Service Proxy (SoapHttpClientProtocol) and must be instantiable. The last one is necessary for line 3 to compile.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="tre"&gt;Line 5: Get the name of the type&amp;nbsp;- for our example above it would be "SiteData" - and build the URL based on the site URL and the web service name.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="terb"&gt;Now I can transform the above snippet to this:&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Courier New"&gt;using (SiteData siteDataWS = WebServiceHelper.CreateWebService&amp;lt;SiteData&amp;gt;(currentSite))&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp; // Do something with the WS.&lt;br&gt;}&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="treb"&gt;Drastic change? No, not really.&amp;nbsp;But it keeps things clean.&lt;/font&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=3721575" width="1" height="1"&gt;</content><author><name>Avner Kashtan</name><uri>http://weblogs.asp.net/members/Avner-Kashtan.aspx</uri></author><category term=".NET" scheme="http://weblogs.asp.net/avnerk/archive/tags/.NET/default.aspx" /><category term="SharePoint" scheme="http://weblogs.asp.net/avnerk/archive/tags/SharePoint/default.aspx" /><category term="CodeSnippets" scheme="http://weblogs.asp.net/avnerk/archive/tags/CodeSnippets/default.aspx" /><category term="C#" scheme="http://weblogs.asp.net/avnerk/archive/tags/C_2300_/default.aspx" /><category term="Generics" scheme="http://weblogs.asp.net/avnerk/archive/tags/Generics/default.aspx" /></entry><entry><title>Visual Studio help-launcher rant</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/avnerk/archive/2007/09/03/visual-studio-help-launcher-rant.aspx" /><id>http://weblogs.asp.net/avnerk/archive/2007/09/03/visual-studio-help-launcher-rant.aspx</id><published>2007-09-03T12:34:00Z</published><updated>2007-09-03T12:34:00Z</updated><content type="html">&lt;p&gt;Yes, I know I am far from the first to bemoan the &lt;em&gt;atrocious&lt;/em&gt; behavior of Visual Studio 2005 when you press the F1 button, even accidently. The first time you do it - or other times, if it deems the contents sufficiently changed for some reason - you are treated to an obnoxious and uncancellable dialog saying Help is updating itself and showing an uninformative neverending progress bar. &lt;/p&gt; &lt;p&gt;Worse yet, this window, despite being non-modal (due to running in a different process, dexplorer.exe) still blocks the calling thread on devenv.exe, preventing me from working for up to 5 minutes(!) at a time. No Abort button, no way to tell it to skip this pointless operation - launching help from VS is simply&amp;nbsp;a giant waste of time.&lt;/p&gt; &lt;p&gt;What I now discovered is that I can't even use the task manager to kill the dexplore.exe process, because Visual Studio actively monitors it and RELAUNCHES it, apparently from scratch, if I try to do so.&lt;/p&gt; &lt;p&gt;So tell me, what program manager decided that this particular feature, launching the Help window in a completely different process, was so &lt;em&gt;amazingly &lt;/em&gt;important that it was allowed to take over my Visual Studio completely for whole minute while I just sat there and twiddled my thumbs?&lt;/p&gt; &lt;p&gt;Infuriating.&lt;/p&gt; &lt;p&gt;UPDATE: &lt;/p&gt; &lt;p&gt;Tools -&amp;gt; Customize -&amp;gt; Keyboard -&amp;gt; Show Commands Containing -&amp;gt; Help.F1Help -&amp;gt; Remove.&lt;/p&gt; &lt;p&gt;There. F1 is disabled. Peace is resumed.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=3719759" width="1" height="1"&gt;</content><author><name>Avner Kashtan</name><uri>http://weblogs.asp.net/members/Avner-Kashtan.aspx</uri></author></entry></feed>