<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>MohamedG's Log</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/mohamedg/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/mohamedg/feed.xml</link>
    <description>TW9oYW1lZCBFbC1HZWlzaA==</description>
    <lastBuildDate>Tue, 31 Mar 2015 19:44:41 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Warning: DataContractSerializer won’t call your constructor!</title>
      <link>https://docs.microsoft.com/archive/blogs/mohamedg/warning-datacontractserializer-wont-call-your-constructor</link>
      <pubDate>Wed, 05 Feb 2014 23:59:17 GMT</pubDate>
      <dc:creator><![CDATA[Mohamed Mahmoud El-Geish]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mohamedg/2014/02/05/warning-datacontractserializer-wont-call-your-constructor/</guid>
      <description><![CDATA[Consider the following naïve data contract:  [DataContract]
public class Data
{
    private int[]...]]></description>
      <content:encoded><![CDATA[<p>Consider the following naïve data contract:</p>  <pre class="csharpcode">[DataContract]
<span class="kwrd">public</span> <span class="kwrd">class</span> Data
{
    <span class="kwrd">private</span> <span class="kwrd">int</span>[] array;

    <span class="kwrd">public</span> Data()
    {
        <span class="kwrd">this</span>.array = <span class="kwrd">new</span> <span class="kwrd">int</span>[13];
    }

    <span class="kwrd">public</span> <span class="kwrd">int</span> Length { <span class="kwrd">get</span> { <span class="kwrd">return</span> <span class="kwrd">this</span>.array.Length; } }
}</pre>

<p>It looks ok, right? Let’s use it then:</p>

<pre class="csharpcode">DataContractSerializer serializer = <span class="kwrd">new</span> DataContractSerializer(<span class="kwrd">typeof</span>(Data));
Data data = <span class="kwrd">new</span> Data();

<span class="kwrd">using</span> (MemoryStream stream = <span class="kwrd">new</span> MemoryStream())
{
    serializer.WriteObject(stream, data);
    stream.Position = 0; <span class="rem">// Rewind</span>

    data = (Data)serializer.ReadObject(stream);

    Console.WriteLine(data.Length); <span class="rem">// throws a NullReferenceException</span>
}</pre>

<p>Why was this.array not initialized? Well, I gave the answer away in the title; the constructor was never called. It turns out that DataContractSerializer (and BinaryFormatter, by the way), unlike XmlSerializer, creates an uninitialized (without calling any constructors) instance of the type it’s de-serializing. Then data members are de-serialized.</p>

<p>In the example above, a very simple change will fix the issue. If you’re running .Net 3.5 SP1 or later (and you should be), the DataContractSerializer can serialize types without the [DataContract] attribute, i.e. Plain Old CLR Object (POCO) types, as long as the type is public and has a parameter-less constructor (regardless of its visibility) – just like XmlSerializer. And yes, you guessed it, in this case, the constructor will be called.</p>

<p>What if you don’t want to define a parameter-less constructor, or if this isn’t a viable option? You should use one of the serialization callbacks listed in the following article: <a title="https://msdn.microsoft.com/en-us/library/ms733734(v=vs.110).aspx" href="https://msdn.microsoft.com/en-us/library/ms733734(v=vs.110).aspx">https://msdn.microsoft.com/en-us/library/ms733734(v=vs.110).aspx</a></p>

<p>Here’s an example:</p>

<pre class="csharpcode">[DataContract]
<span class="kwrd">public</span> <span class="kwrd">class</span> Data
{
    <span class="kwrd">private</span> <span class="kwrd">int</span>[] array;

    <span class="kwrd">public</span> Data()
    {
        Initialize();
    }

    <span class="kwrd">private</span> <span class="kwrd">void</span> Initialize()
    {
        <span class="kwrd">this</span>.array = <span class="kwrd">new</span> <span class="kwrd">int</span>[13];
    }

    [OnDeserializing]
    <span class="kwrd">private</span> <span class="kwrd">void</span> SetValuesOnDeserializing(StreamingContext context)
    {
        Initialize();
    }

    <span class="kwrd">public</span> <span class="kwrd">int</span> Length { <span class="kwrd">get</span> { <span class="kwrd">return</span> <span class="kwrd">this</span>.array.Length; } }
}</pre>]]></content:encoded>
    </item>
    <item>
      <title>Filtering Event Log Entries by Event Code</title>
      <link>https://docs.microsoft.com/archive/blogs/mohamedg/filtering-event-log-entries-by-event-code</link>
      <pubDate>Tue, 04 Feb 2014 22:41:00 GMT</pubDate>
      <dc:creator><![CDATA[Mohamed Mahmoud El-Geish]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mohamedg/2014/02/04/filtering-event-log-entries-by-event-code/</guid>
      <description><![CDATA[When you filter event log entries bu event code using WMI, you can run a query like the...]]></description>
      <content:encoded><![CDATA[<p>When you filter event log entries bu event code using WMI, you can run a query like the following:</p>
<p><strong>"SELECT Message FROM Win32_NTLogEvent WHERE EventCode = 7"</strong></p>
<p>And as expected, this will return the entries with event code 7. Now, let&rsquo;s look at the corresponding C# code, given that you already have a list of event log entries, you explore which property you should use to filter the list using LINQ. Conveniently, you find <a href="https://msdn.microsoft.com/en-us/library/system.diagnostics.eventlogentry.eventid(v=vs.110).aspx" target="_blank">EventLogEntry.EventID</a>, but it&rsquo;s obsolete and the compiler warning asks you to use <a href="https://msdn.microsoft.com/en-us/library/system.diagnostics.eventlogentry.instanceid(v=vs.110).aspx" target="_blank">EventLogEntry.InstanceId</a> instead. So, you follow the instructions and do so:</p>
<pre class="csharpcode">IEnumerable&lt;EventLogEntry&gt; filtered = entries.Where(e =&gt; e.InstanceId == 7);</pre>
<p>You run the code, and test it; everything works; you don&rsquo;t think about it twice.</p>
<p>Later on, you inspect certain event log entries, and you find out that your filter didn&rsquo;t catch them. So, you feel suspicious and debug the code, only to find out that InstanceId returns 3221487623, even though the same entry is showing 7 as its event code in the event viewer.</p>
<h2>What&rsquo;s going on here?</h2>
<p>It turns out, the answer was in the remarks section on MSDN:</p>
<p>The <a href="https://msdn.microsoft.com/en-us/library/system.diagnostics.eventlogentry.eventid(v=vs.110).aspx">EventID</a> property equals the InstanceId with the top two bits masked off. <strong>Two event log entries from the same source can have matching </strong><a href="https://msdn.microsoft.com/en-us/library/system.diagnostics.eventlogentry.eventid(v=vs.110).aspx"><strong>EventID</strong></a><strong> values, but have different InstanceId values due to differences in the top two bits of the resource identifier.</strong></p>
<p>Digging deeper, the obsolete EventID property only masks the top two bits, but there&rsquo;s more we don&rsquo;t care about in that case, according to MSDN again (see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363651(v=vs.85).aspx" target="_blank">Event Identifiers</a>):</p>
<p><img style="border: 0px currentcolor; margin-right: 0px; margin-left: 0px; display: inline;" title="Event ID" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/94/84/metablogapi/5736.ID_5257374E.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-94-84-metablogapi/5736.ID_5F00_5257374E.png" alt="Event ID" width="635" height="148" border="0" /></p>
<p>So to really filter by just the event code, the code will look like the following:</p>
<pre class="csharpcode">IEnumerable&lt;EventLogEntry&gt; filtered = entries.Where(e =&gt; (e.InstanceId &amp; <strong>0xFFFF</strong>) == 7);</pre>
<p>&nbsp;</p>
<h2>Why didn&rsquo;t my test catch that?</h2>
<p>Because your test wrote the event log entry using the straight-forward <a href="https://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.writeentry(v=vs.110).aspx">WriteEntry</a> method; the remarks section explains:</p>
<p>If the application wrote the event entry using one of the <a href="https://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.writeentry(v=vs.110).aspx">WriteEntry</a> methods, the InstanceId property matches the optional eventId parameter. If the application wrote the event using <a href="https://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.writeevent(v=vs.110).aspx">WriteEvent</a>, the InstanceId property matches the resource identifier specified in the <a href="https://msdn.microsoft.com/en-us/library/system.diagnostics.eventinstance.instanceid(v=vs.110).aspx">InstanceId</a> of the instance parameter. If the application wrote the event using the Win32 API ReportEvent, the InstanceId property matches the resource identifier specified in the dwEventID parameter.</p>
<p>It's worth noting that using an EventLogQuery doesn't reproduce this issue.</p>]]></content:encoded>
    </item>
    <item>
      <title>Running a SQL Statement on all Databases</title>
      <link>https://docs.microsoft.com/archive/blogs/mohamedg/running-a-sql-statement-on-all-databases</link>
      <pubDate>Thu, 17 Jan 2013 15:36:00 GMT</pubDate>
      <dc:creator><![CDATA[Mohamed Mahmoud El-Geish]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mohamedg/2013/01/17/running-a-sql-statement-on-all-databases/</guid>
      <description><![CDATA[exec sp_MsForEachDB 'SELECT "?", 1'

The ? will be replaced by the current database name. To run a...]]></description>
      <content:encoded><![CDATA[<pre class="csharpcode"><span class="kwrd">exec</span> sp_MsForEachDB <span class="rem">'SELECT "?", 1'</span>
</pre>
<p>The ? will be replaced by the current database name. To run a query that references a table, you need to make sure that the table exists first, as this query will run on system databases as well.</p>]]></content:encoded>
    </item>
    <item>
      <title>Adding HTTP Headers to WCF Calls</title>
      <link>https://docs.microsoft.com/archive/blogs/mohamedg/adding-http-headers-to-wcf-calls</link>
      <pubDate>Thu, 13 Dec 2012 23:41:00 GMT</pubDate>
      <dc:creator><![CDATA[Mohamed Mahmoud El-Geish]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mohamedg/2012/12/13/adding-http-headers-to-wcf-calls/</guid>
      <description><![CDATA[To add HTTP headers, request messages have to be intercepted before they are sent to the server....]]></description>
      <content:encoded><![CDATA[<p>To add HTTP headers, request messages have to be intercepted before they are sent to the server. This can be done by implementing the <a href="https://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientmessageinspector.beforesendrequest.aspx" target="_blank">IClientMessageInspector.BeforeSendRequest</a>method:</p>
<pre class="csharpcode"><span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// Represents a message inspector object that can be added to the &lt;c&gt;MessageInspectors&lt;/c&gt; collection to view or modify messages.</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="kwrd">public</span> <span class="kwrd">class</span> ClientMessageInspector : IClientMessageInspector
{
    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Enables inspection or modification of a message before a request message is sent to a service.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;param name="request"&gt;The message to be sent to the service.&lt;/param&gt;</span>
    <span class="rem">/// &lt;param name="channel"&gt;The WCF client object channel.&lt;/param&gt;</span>
    <span class="rem">/// &lt;returns&gt;</span>
    <span class="rem">/// The object that is returned as the &lt;paramref name="correlationState " /&gt; argument of</span>
    <span class="rem">/// the &lt;see cref="M:System.ServiceModel.Dispatcher.IClientMessageInspector.AfterReceiveReply(System.ServiceModel.Channels.Message@,System.Object)" /&gt; method.</span>
    <span class="rem">/// This is null if no correlation state is used.The best practice is to make this a &lt;see cref="T:System.Guid" /&gt; to ensure that no two</span>
    <span class="rem">/// &lt;paramref name="correlationState" /&gt; objects are the same.</span>
    <span class="rem">/// &lt;/returns&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">object</span> BeforeSendRequest(<span class="kwrd">ref</span> Message request, IClientChannel channel)
    {
        HttpRequestMessageProperty property = <span class="kwrd">new</span> HttpRequestMessageProperty();

        property.Headers["User-Agent"] = "value";
        request.Properties.Add(HttpRequestMessageProperty.Name, property);

        <span class="kwrd">return</span> <span class="kwrd">null</span>;
    }

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Enables inspection or modification of a message after a reply message is received but prior to passing it back to the client application.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;param name="reply"&gt;The message to be transformed into types and handed back to the client application.&lt;/param&gt;</span>
    <span class="rem">/// &lt;param name="correlationState"&gt;Correlation state data.&lt;/param&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">void</span> AfterReceiveReply(<span class="kwrd">ref</span> System.ServiceModel.Channels.Message reply, <span class="kwrd">object</span> correlationState)
    {
        <span class="rem">// Nothing special here</span>
    }
}</pre>
<p>This interception is a behavior or an extension of WCF endpoints, so one more method needs to be implemented to apply that behavior to the endpoint, the <a href="https://msdn.microsoft.com/en-us/library/system.servicemodel.description.iendpointbehavior.applyclientbehavior.aspx" target="_blank">IEndpointBehavior.ApplyClientBehavior</a> method:</p>
<pre class="csharpcode"><span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// Represents a run-time behavior extension for a client endpoint.</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="kwrd">public</span> <span class="kwrd">class</span> CustomEndpointBehavior : IEndpointBehavior
{
    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Implements a modification or extension of the client across an endpoint.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;param name="endpoint"&gt;The endpoint that is to be customized.&lt;/param&gt;</span>
    <span class="rem">/// &lt;param name="clientRuntime"&gt;The client runtime to be customized.&lt;/param&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">void</span> ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
    {
        clientRuntime.ClientMessageInspectors.Add(<span class="kwrd">new</span> ClientMessageInspector());
    }
            
    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Implement to pass data at runtime to bindings to support custom behavior.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;param name="endpoint"&gt;The endpoint to modify.&lt;/param&gt;</span>
    <span class="rem">/// &lt;param name="bindingParameters"&gt;The objects that binding elements require to support the behavior.&lt;/param&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">void</span> AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
    {
        <span class="rem">// Nothing special here</span>
    }

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Implements a modification or extension of the service across an endpoint.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;param name="endpoint"&gt;The endpoint that exposes the contract.&lt;/param&gt;</span>
    <span class="rem">/// &lt;param name="endpointDispatcher"&gt;The endpoint dispatcher to be modified or extended.&lt;/param&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">void</span> ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
    {
        <span class="rem">// Nothing special here</span>
    }

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Implement to confirm that the endpoint meets some intended criteria.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;param name="endpoint"&gt;The endpoint to validate.&lt;/param&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">void</span> Validate(ServiceEndpoint endpoint)
    {
        <span class="rem">// Nothing special here</span>
    }
}</pre>
<p>The last step is to add the new behavior to the WCF endpoint:</p>
<pre class="csharpcode">Endpoint.EndpointBehaviors.Add(<span class="kwrd">new</span> CustomEndpointBehavior());</pre>
<p>Voil&agrave;!</p>]]></content:encoded>
    </item>
    <item>
      <title>Extending XElement to Match Child Elements by LocalName</title>
      <link>https://docs.microsoft.com/archive/blogs/mohamedg/extending-xelement-to-match-child-elements-by-localname</link>
      <pubDate>Fri, 26 Oct 2012 01:14:42 GMT</pubDate>
      <dc:creator><![CDATA[Mohamed Mahmoud El-Geish]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mohamedg/2012/10/26/extending-xelement-to-match-child-elements-by-localname/</guid>
      <description><![CDATA[If you want to ignore the child elements’ namespaces, and match by local name only, you can do...]]></description>
      <content:encoded><![CDATA[<p>If you want to ignore the child elements’ namespaces, and match by local name only, you can do something similar to the following:</p>  <p>   <pre class="csharpcode"><span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// Represents an extension for &lt;see cref=&quot;XElement&quot;/&gt;.</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="kwrd">internal</span> <span class="kwrd">static</span> <span class="kwrd">class</span> XElementExtension
{
    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Gets the first (in document order) child element with the specified &lt;paramref name=&quot;localName&quot;/&gt;.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;param name=&quot;parent&quot;&gt;The parent element.&lt;/param&gt;</span>
    <span class="rem">/// &lt;param name=&quot;localName&quot;&gt;The local name to match.&lt;/param&gt;</span>
    <span class="rem">/// &lt;returns&gt;An &lt;see cref=&quot;XElement&quot;/&gt; that matches the specified &lt;paramref name=&quot;localName&quot;/&gt;, or &lt;c&gt;null&lt;/c&gt;.&lt;/returns&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">static</span> XElement LocalNameElement(<span class="kwrd">this</span> XElement parent, <span class="kwrd">string</span> localName)
    {
        <span class="kwrd">return</span> parent.Elements().FirstOrDefault(e =&gt; e.Name.LocalName == localName);
    }

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Returns a filtered collection of the child elements of the specified &lt;paramref name=&quot;parent&quot;/&gt;, in document order.</span>
    <span class="rem">/// Only elements that have a matching &lt;paramref name=&quot;localName&quot;/&gt; are included in the collection.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;param name=&quot;parent&quot;&gt;The parent element.&lt;/param&gt;</span>
    <span class="rem">/// &lt;param name=&quot;localName&quot;&gt;The local name to match.&lt;/param&gt;</span>
    <span class="rem">/// &lt;returns&gt;</span>
    <span class="rem">/// An &lt;see cref=&quot;IEnumerable{T}&quot;/&gt; of &lt;see cref=&quot;XElement&quot;/&gt; containing the children that have a matching &lt;paramref name=&quot;localName&quot;/&gt;,</span>
    <span class="rem">/// in document order.</span>
    <span class="rem">/// &lt;/returns&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">static</span> IEnumerable&lt;XElement&gt; LocalNameElements(<span class="kwrd">this</span> XElement parent, <span class="kwrd">string</span> localName)
    {
        <span class="kwrd">return</span> parent.Elements().Where(e =&gt; e.Name.LocalName == localName);
    }
}</pre>
You can use the same pattern to extend <a href="https://msdn.microsoft.com/en-us/library/bb341024.aspx" target="_blank">Attributes(XName)</a> and the rest of the select/search methods. For the list of methods, see: <a href="https://msdn.microsoft.com/en-us/library/system.xml.linq.xelement_methods.aspx" target="_blank">XElement Methods</a>.</p>]]></content:encoded>
    </item>
    <item>
      <title>Using Fiddler on Local Windows 8 Machine</title>
      <link>https://docs.microsoft.com/archive/blogs/mohamedg/using-fiddler-on-local-windows-8-machine</link>
      <pubDate>Tue, 23 Oct 2012 21:32:06 GMT</pubDate>
      <dc:creator><![CDATA[Mohamed Mahmoud El-Geish]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mohamedg/2012/10/23/using-fiddler-on-local-windows-8-machine/</guid>
      <description><![CDATA[If you used Fiddler before, you would know that it doesn’t work out of the box on localhost. The...]]></description>
      <content:encoded><![CDATA[<p>If you used <a href="https://www.fiddler2.com/fiddler2/" target="_blank">Fiddler</a> before, you would know that it doesn’t work out of the box on localhost. The <a href="https://www.fiddler2.com/Fiddler/help/hookup.asp" target="_blank">instructions on how to hook it up</a> didn’t work for me trying to debug traffic of a .Net app on Windows 8. After applying those steps, I had tried 127.0.0.1, localhost, ipv4.fiddler, but none of them worked. The only thing that worked for me was to use the network card’s IP address, that did it. </p>]]></content:encoded>
    </item>
    <item>
      <title>Reflector Visual Studio Extension - Enable Debugging</title>
      <link>https://docs.microsoft.com/archive/blogs/mohamedg/reflector-visual-studio-extension-enable-debugging</link>
      <pubDate>Tue, 23 Oct 2012 00:50:23 GMT</pubDate>
      <dc:creator><![CDATA[Mohamed Mahmoud El-Geish]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mohamedg/2012/10/23/reflector-visual-studio-extension-enable-debugging/</guid>
      <description><![CDATA[I’ve been using the standalone Reflector.exe for so many years now, and recently I’ve been using...]]></description>
      <content:encoded><![CDATA[<p>I’ve been using the standalone Reflector.exe for so many years now, and recently I’ve been using JustDecompile too. They have different accuracy levels and different set of distinguishing features, but the one I use in VS is Reflector. I was excited about a feature in the Visual Studio extension, I had to blog about it! Back in the day, one used to decompile an assembly into a project, then rebuild it to generate the PDBs, and finally opening it in VS to step into the code. Now, it’s done with one click (actually a right click then a click). First, you will need to get the extension from <strong>Tools &gt; Extensions and Updates</strong>. I already have it installed, with a bunch of other useful extensions that you may want to get:</p>  <p><img title="Reflector" style="border: 0px currentcolor; display: inline; background-image: none;" border="0" alt="Reflector" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/94/84/metablogapi/5187.Reflector_65C3C96D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-94-84-metablogapi/5187.Reflector_5F00_65C3C96D.png" width="955" height="660" /></p>  <p>After you’ve installed it, right click the reference you want to be able to debug in your project, then choose: <strong>Enable Debugging</strong>. Reflector will get to work and generate the PDBs and source for you:</p>  <p><img title="Enable Debugging" style="border: 0px currentcolor; display: inline; background-image: none;" border="0" alt="Enable Debugging" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/94/84/metablogapi/7167.EnableDebugging_5A2E0C2E.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-94-84-metablogapi/7167.EnableDebugging_5F00_5A2E0C2E.png" width="770" height="424" /></p>  <p><strong>Note: </strong>this doesn’t have to be a .Net Framework assembly. You can enable debugging for any managed referenced assembly. To step into the .Net Framework source, you don’t need Reflector, just enable this from <strong>Tools &gt; Options &gt; Debugging</strong>:</p>  <p><img title="CLR" style="border: 0px currentcolor; display: inline; background-image: none;" border="0" alt="CLR" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/94/84/metablogapi/2845.CLR_64EB6383.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-94-84-metablogapi/2845.CLR_5F00_64EB6383.png" width="757" height="441" /></p>  <p>Happy debugging!</p>]]></content:encoded>
    </item>
    <item>
      <title>Adding Custom SOAP Headers in WCF</title>
      <link>https://docs.microsoft.com/archive/blogs/mohamedg/adding-custom-soap-headers-in-wcf</link>
      <pubDate>Sun, 21 Oct 2012 21:10:48 GMT</pubDate>
      <dc:creator><![CDATA[Mohamed Mahmoud El-Geish]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mohamedg/2012/10/21/adding-custom-soap-headers-in-wcf/</guid>
      <description><![CDATA[First, you need to decide whether to create the custom header using the MessageHeader.CreateHeader...]]></description>
      <content:encoded><![CDATA[<p>First, you need to decide whether to create the custom header using the <a href="https://msdn.microsoft.com/en-us/library/system.servicemodel.channels.messageheader.createheader.aspx" target="_blank">MessageHeader.CreateHeader</a> method, or by extending the abstract <a href="https://msdn.microsoft.com/en-us/library/ms405928.aspx" target="_blank">MessageHeader</a> class.</p>  <p>Under the hood, the CreateHeader method returns an instance of an internal class called XmlObjectSerializerHeader, which uses a serializer to write the header:</p>  <pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
{
    Type type;
    <span class="kwrd">lock</span> (<span class="kwrd">this</span>.syncRoot)
    {
        <span class="kwrd">if</span> (<span class="kwrd">this</span>.serializer == <span class="kwrd">null</span>)
        {
            XmlObjectSerializerHeader xmlObjectSerializerHeader = <span class="kwrd">this</span>;
            <span class="kwrd">if</span> (<span class="kwrd">this</span>.objectToSerialize == <span class="kwrd">null</span>)
            {
                type = <span class="kwrd">typeof</span>(<span class="kwrd">object</span>);
            }
            <span class="kwrd">else</span>
            {
                type = <span class="kwrd">this</span>.objectToSerialize.GetType();
            }
            xmlObjectSerializerHeader.serializer = DataContractSerializerDefaults.CreateSerializer(type, <span class="kwrd">this</span>.Name, <span class="kwrd">this</span>.Namespace, 2147483647);
        }
        <span class="kwrd">this</span>.serializer.WriteObjectContent(writer, <span class="kwrd">this</span>.objectToSerialize);
    }
}</pre>

<p>If you want full control over the header writing method, and less objects created in the process, consider creating your own message header class. It can be also necessary when you want to format the header’s content in a way that’s not a straight-forward serialized version of its value. For example, if you want to write a header like the following:</p>

<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">s:Envelope</span> <span class="attr">xmlns:s</span><span class="kwrd">=&quot;https://schemas.xmlsoap.org/soap/envelope/&quot;</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">s:Header</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">CustomHeader</span> <span class="attr">xmlns</span><span class="kwrd">=&quot;https://schemas.microsoft.com/42&quot;</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">Id</span><span class="kwrd">&gt;</span>4a851a6d-c85c-4bd3-9584-c00740332aa4<span class="kwrd">&lt;/</span><span class="html">Id</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">CustomHeader</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">s:Header</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">s:Body</span> <span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">s:Envelope</span><span class="kwrd">&gt;</span></pre>

<p>Using the XmlObjectSerializerHeader will produce the following:</p>

<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">s:Envelope</span> <span class="attr">xmlns:s</span><span class="kwrd">=&quot;https://schemas.xmlsoap.org/soap/envelope/&quot;</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">s:Header</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">CustomHeader</span> <span class="attr">xmlns</span><span class="kwrd">=&quot;https://schemas.microsoft.com/42&quot;</span><span class="kwrd">&gt;</span>
      <span class="attr">&amp;lt;</span>id<span class="attr">&amp;gt;</span>4a851a6d-c85c-4bd3-9584-c00740332aa4<span class="attr">&amp;lt;</span>/id<span class="attr">&amp;gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">CustomHeader</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">s:Header</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">s:Body</span> <span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">s:Envelope</span><span class="kwrd">&gt;</span></pre>

<p>Because the XmlDictionaryWriter encoded the value’s XML special characters. What you want is to build the custom header yourself:</p>

<pre class="csharpcode"><span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// Represents a custom message header.</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="kwrd">public</span> <span class="kwrd">class</span> CustomMessageHeader : MessageHeader
{
    <span class="kwrd">private</span> <span class="kwrd">const</span> <span class="kwrd">string</span> HeaderName = <span class="str">&quot;CustomHeader&quot;</span>;
    <span class="kwrd">private</span> <span class="kwrd">const</span> <span class="kwrd">string</span> HeaderNamespace = <span class="str">&quot;https://schemas.microsoft.com/42&quot;</span>;

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Initializes a new instance of the &lt;see cref=&quot;CustomMessageHeader&quot; /&gt; class.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="kwrd">public</span> CustomMessageHeader()
    {
        Id = Guid.NewGuid();
    }

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Gets the name of the message header.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;returns&gt;The name of the message header.&lt;/returns&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">string</span> Name
    {
        get { <span class="kwrd">return</span> HeaderName; }
    }

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Gets the namespace of the message header.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;returns&gt;The namespace of the message header.&lt;/returns&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">string</span> Namespace
    {
        get { <span class="kwrd">return</span> HeaderNamespace; }
    }

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Gets the request ID.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;returns&gt;A &lt;see cref=&quot;Guid&quot;/&gt; that uniquely identifies a request.&lt;/returns&gt;</span>
    <span class="kwrd">public</span> Guid Id { get; <span class="kwrd">private</span> set; }

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Called when the header content is serialized using the specified XML writer.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;param name=&quot;writer&quot;&gt;</span>
    <span class="rem">/// An &lt;see cref=&quot;T:System.Xml.XmlDictionaryWriter&quot; /&gt; that is used to serialize the header contents.</span>
    <span class="rem">/// &lt;/param&gt;</span>
    <span class="rem">/// &lt;param name=&quot;messageVersion&quot;&gt;</span>
    <span class="rem">/// The object that contains information related to the version of SOAP associated with a message and its exchange.</span>
    <span class="rem">/// &lt;/param&gt;</span>
    <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
    {
        writer.WriteElementString(<span class="str">&quot;Id&quot;</span>, Id.ToString());
    }
}</pre>

<p>Now, to inject that custom message header, messages need to be intercepted before they are sent to the server. This can be done by implementing the <a href="https://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientmessageinspector.beforesendrequest.aspx" target="_blank">IClientMessageInspector.BeforeSendRequest</a> method:</p>

<pre class="csharpcode"><span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// Represents a message inspector object that can be added to the &lt;c&gt;MessageInspectors&lt;/c&gt; collection to view or modify messages.</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="kwrd">public</span> <span class="kwrd">class</span> ClientMessageInspector : IClientMessageInspector
{
    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Enables inspection or modification of a message before a request message is sent to a service.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;param name=&quot;request&quot;&gt;The message to be sent to the service.&lt;/param&gt;</span>
    <span class="rem">/// &lt;param name=&quot;channel&quot;&gt;The WCF client object channel.&lt;/param&gt;</span>
    <span class="rem">/// &lt;returns&gt;</span>
    <span class="rem">/// The object that is returned as the &lt;paramref name=&quot;correlationState &quot; /&gt; argument of</span>
    <span class="rem">/// the &lt;see cref=&quot;M:System.ServiceModel.Dispatcher.IClientMessageInspector.AfterReceiveReply(System.ServiceModel.Channels.Message@,System.Object)&quot; /&gt; method.</span>
    <span class="rem">/// This is null if no correlation state is used.The best practice is to make this a &lt;see cref=&quot;T:System.Guid&quot; /&gt; to ensure that no two</span>
    <span class="rem">/// &lt;paramref name=&quot;correlationState&quot; /&gt; objects are the same.</span>
    <span class="rem">/// &lt;/returns&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">object</span> BeforeSendRequest(<span class="kwrd">ref</span> Message request, IClientChannel channel)
    {
        CustomMessageHeader header = <span class="kwrd">new</span> CustomMessageHeader();

        request.Headers.Add(header);

        <span class="kwrd">return</span> header.Id;
    }

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Enables inspection or modification of a message after a reply message is received but prior to passing it back to the client application.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;param name=&quot;reply&quot;&gt;The message to be transformed into types and handed back to the client application.&lt;/param&gt;</span>
    <span class="rem">/// &lt;param name=&quot;correlationState&quot;&gt;Correlation state data.&lt;/param&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">void</span> AfterReceiveReply(<span class="kwrd">ref</span> System.ServiceModel.Channels.Message reply, <span class="kwrd">object</span> correlationState)
    {
        <span class="rem">// Nothing special here</span>
    }
}</pre>

<p>This interception is a behavior or an extension of WCF endpoints, so one more method needs to be implemented to apply that behavior to the endpoint, the <a href="https://msdn.microsoft.com/en-us/library/system.servicemodel.description.iendpointbehavior.applyclientbehavior.aspx" target="_blank">IEndpointBehavior.ApplyClientBehavior</a> method:</p>

<pre class="csharpcode"><span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// Represents a run-time behavior extension for a client endpoint.</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="kwrd">public</span> <span class="kwrd">class</span> CustomEndpointBehavior : IEndpointBehavior
{
    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Implements a modification or extension of the client across an endpoint.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;param name=&quot;endpoint&quot;&gt;The endpoint that is to be customized.&lt;/param&gt;</span>
    <span class="rem">/// &lt;param name=&quot;clientRuntime&quot;&gt;The client runtime to be customized.&lt;/param&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">void</span> ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
    {
        clientRuntime.ClientMessageInspectors.Add(<span class="kwrd">new</span> ClientMessageInspector());
    }
            
    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Implement to pass data at runtime to bindings to support custom behavior.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;param name=&quot;endpoint&quot;&gt;The endpoint to modify.&lt;/param&gt;</span>
    <span class="rem">/// &lt;param name=&quot;bindingParameters&quot;&gt;The objects that binding elements require to support the behavior.&lt;/param&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">void</span> AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
    {
        <span class="rem">// Nothing special here</span>
    }

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Implements a modification or extension of the service across an endpoint.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;param name=&quot;endpoint&quot;&gt;The endpoint that exposes the contract.&lt;/param&gt;</span>
    <span class="rem">/// &lt;param name=&quot;endpointDispatcher&quot;&gt;The endpoint dispatcher to be modified or extended.&lt;/param&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">void</span> ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
    {
        <span class="rem">// Nothing special here</span>
    }

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Implement to confirm that the endpoint meets some intended criteria.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;param name=&quot;endpoint&quot;&gt;The endpoint to validate.&lt;/param&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">void</span> Validate(ServiceEndpoint endpoint)
    {
        <span class="rem">// Nothing special here</span>
    }
}</pre>

<p>The last step is to add the new behavior to the WCF endpoint:</p>

<pre class="csharpcode">Endpoint.EndpointBehaviors.Add(<span class="kwrd">new</span> CustomEndpointBehavior());</pre>

<p>Voilà!</p>]]></content:encoded>
    </item>
    <item>
      <title>Overriding an Abstract Property vs. Passing a Parameter</title>
      <link>https://docs.microsoft.com/archive/blogs/mohamedg/overriding-an-abstract-property-vs-passing-a-parameter</link>
      <pubDate>Sun, 21 Oct 2012 19:36:54 GMT</pubDate>
      <dc:creator><![CDATA[Mohamed Mahmoud El-Geish]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mohamedg/2012/10/21/overriding-an-abstract-property-vs-passing-a-parameter/</guid>
      <description><![CDATA[An abstract class may require a value to be passed through the constructor like the following...]]></description>
      <content:encoded><![CDATA[<p>An abstract class may require a value to be passed through the constructor like the following example:</p>  <pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">abstract</span> <span class="kwrd">class</span> Node
{
    <span class="kwrd">private</span> <span class="kwrd">readonly</span> Uri _uri;

    <span class="kwrd">protected</span> Node(<span class="kwrd">string</span> address, <span class="kwrd">string</span> relativePath)
    {
        _uri = <span class="kwrd">new</span> Uri(Path.Combine(address, relativePath));
    }
}

<span class="kwrd">public</span> <span class="kwrd">class</span> Element : Node
{
    <span class="kwrd">private</span> <span class="kwrd">const</span> <span class="kwrd">string</span> relativePath = <span class="str">&quot;/path&quot;</span>;

    <span class="kwrd">public</span> Element(<span class="kwrd">string</span> address)
        : <span class="kwrd">base</span>(address, relativePath)
    {
    }
}</pre>

<p>Alternatively, it can require that derived types implement a property or a method that returns that value:</p>

<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">abstract</span> <span class="kwrd">class</span> Node
{
    <span class="kwrd">private</span> <span class="kwrd">readonly</span> Uri _uri;

    <span class="kwrd">protected</span> Node(<span class="kwrd">string</span> address)
    {
        _uri = <span class="kwrd">new</span> Uri(Path.Combine(address, RelativePath));
    }

    <span class="kwrd">protected</span> <span class="kwrd">abstract</span> <span class="kwrd">string</span> RelativePath { get; }
}

<span class="kwrd">public</span> <span class="kwrd">class</span> Element : Node
{
    <span class="kwrd">private</span> <span class="kwrd">const</span> <span class="kwrd">string</span> relativePath = <span class="str">&quot;/path&quot;</span>;

    <span class="kwrd">public</span> Element(<span class="kwrd">string</span> address)
        : <span class="kwrd">base</span>(address)
    {
    }

    <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">string</span> RelativePath { get { <span class="kwrd">return</span> relativePath; } }
}</pre>

<p>The first approach is more suitable for initializing a new instance; since the relative path value is only used once. However, if the value will be used more frequently, the property solution sounds more like it. For example, extending the <a href="https://msdn.microsoft.com/en-us/library/system.servicemodel.channels.messageheader.aspx" target="_blank">MessageHeader</a> class:</p>

<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> CustomtMessageHeader : MessageHeader
{
    <span class="kwrd">private</span> <span class="kwrd">const</span> <span class="kwrd">string</span> headerName = <span class="str">&quot;CustomHeader&quot;</span>;

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Gets the name of the message header.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;returns&gt;The name of the message header.&lt;/returns&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">string</span> Name
    {
        get { <span class="kwrd">return</span> headerName; }
    }
}</pre>]]></content:encoded>
    </item>
    <item>
      <title>Changing the Foreground Color of an Indeterminate ProgressBar</title>
      <link>https://docs.microsoft.com/archive/blogs/mohamedg/changing-the-foreground-color-of-an-indeterminate-progressbar</link>
      <pubDate>Sun, 21 Oct 2012 02:01:55 GMT</pubDate>
      <dc:creator><![CDATA[Mohamed Mahmoud El-Geish]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mohamedg/2012/10/21/changing-the-foreground-color-of-an-indeterminate-progressbar/</guid>
      <description><![CDATA[You would think that the following XAML changes the indeterminate progress bar’s foreground color:...]]></description>
      <content:encoded><![CDATA[<p>You would think that the following XAML changes the indeterminate progress bar’s foreground color:</p>  <pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">ProgressBar</span> <span class="attr">IsIndeterminate</span><span class="kwrd">=&quot;True&quot;</span> <span class="attr">Foreground</span><span class="kwrd">=&quot;Aquamarine&quot;</span> <span class="kwrd">/&gt;</span></pre>

<p>Unfortunately, that doesn’t work. You will need to override the following value in the default theme resource dictionary:</p>

<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">ResourceDictionary.ThemeDictionaries</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">ResourceDictionary</span> <span class="attr">x:Key</span><span class="kwrd">=&quot;Default&quot;</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">x:String</span> <span class="attr">x:Key</span><span class="kwrd">=&quot;ProgressBarIndeterminateForegroundThemeBrush&quot;</span><span class="kwrd">&gt;</span>Aquamarine<span class="kwrd">&lt;/</span><span class="html">x:String</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">ResourceDictionary</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">ResourceDictionary.ThemeDictionaries</span><span class="kwrd">&gt;</span></pre>

<p>You can add that override to App.xaml, or to a new resource dictionary that’s merged into App.xaml:</p>

<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Application</span>
    <span class="attr">x:Class</span><span class="kwrd">=&quot;Sample.App&quot;</span>
    <span class="attr">xmlns</span><span class="kwrd">=&quot;https://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span>
    <span class="attr">xmlns:x</span><span class="kwrd">=&quot;https://schemas.microsoft.com/winfx/2006/xaml&quot;</span><span class="kwrd">&gt;</span>
    
    <span class="kwrd">&lt;</span><span class="html">Application.Resources</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">ResourceDictionary</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">ResourceDictionary.MergedDictionaries</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">ResourceDictionary</span> <span class="attr">Source</span><span class="kwrd">=&quot;Common/StandardStyles.xaml&quot;</span> <span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">ResourceDictionary</span> <span class="attr">Source</span><span class="kwrd">=&quot;Common/CustomStyles.xaml&quot;</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">ResourceDictionary.MergedDictionaries</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">ResourceDictionary</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">Application.Resources</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">Application</span><span class="kwrd">&gt;</span></pre>

<p>CustomStyles.xaml:</p>

<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">ResourceDictionary</span>
    <span class="attr">xmlns</span><span class="kwrd">=&quot;https://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span> 
    <span class="attr">xmlns:x</span><span class="kwrd">=&quot;https://schemas.microsoft.com/winfx/2006/xaml&quot;</span><span class="kwrd">&gt;</span>
    <span class="rem">&lt;!-- Global Overrides --&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">ResourceDictionary.ThemeDictionaries</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">ResourceDictionary</span> <span class="attr">x:Key</span><span class="kwrd">=&quot;Default&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">x:String</span> <span class="attr">x:Key</span><span class="kwrd">=&quot;ProgressBarIndeterminateForegroundThemeBrush&quot;</span><span class="kwrd">&gt;</span>Aquamarine<span class="kwrd">&lt;/</span><span class="html">x:String</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">ResourceDictionary</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">ResourceDictionary.ThemeDictionaries</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">ResourceDictionary</span><span class="kwrd">&gt;</span></pre>]]></content:encoded>
    </item>
  </channel>
</rss>