MohamedG's Log

TW9oYW1lZCBFbC1HZWlzaA==

Warning: DataContractSerializer won’t call your constructor!

Consider the following naïve data contract: [DataContract] public class Data { private int[] array; public Data() { this.array = new int[13]; } public int Length { get { return this.array.Length; } } } It looks ok, right? Let’s use it then: DataContractSerializer serializer = new DataContractSerializer(typeof(Data)); Data data = new Data(); using (MemoryStream stream =… Read more

Adding HTTP Headers to WCF Calls

To add HTTP headers, request messages have to be intercepted before they are sent to the server. This can be done by implementing the IClientMessageInspector.BeforeSendRequestmethod: /// <summary> /// Represents a message inspector object that can be added to the <c>MessageInspectors</c> collection to view or modify messages. /// </summary> public class ClientMessageInspector : IClientMessageInspector { ///… Read more

Extending XElement to Match Child Elements by LocalName

If you want to ignore the child elements’ namespaces, and match by local name only, you can do something similar to the following: /// <summary> /// Represents an extension for <see cref="XElement"/>. /// </summary> internal static class XElementExtension { /// <summary> /// Gets the first (in document order) child element with the specified <paramref name="localName"/>…. Read more

Adding Custom SOAP Headers in WCF

First, you need to decide whether to create the custom header using the MessageHeader.CreateHeader method, or by extending the abstract MessageHeader class. Under the hood, the CreateHeader method returns an instance of an internal class called XmlObjectSerializerHeader, which uses a serializer to write the header: protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion) { Type type;… Read more

Changing the Foreground Color of an Indeterminate ProgressBar

You would think that the following XAML changes the indeterminate progress bar’s foreground color: <ProgressBar IsIndeterminate="True" Foreground="Aquamarine" /> Unfortunately, that doesn’t work. You will need to override the following value in the default theme resource dictionary: <ResourceDictionary.ThemeDictionaries> <ResourceDictionary x:Key="Default"> <x:String x:Key="ProgressBarIndeterminateForegroundThemeBrush">Aquamarine</x:String> </ResourceDictionary> </ResourceDictionary.ThemeDictionaries> You can add that override to App.xaml, or to a new resource… Read more

Windows Store App Settings Flyout

Prerequisites Please read the following articles first: Guidelines for app settings (Windows Store apps) Quickstart: Adding app settings using Windows Runtime In this post, I’ll be walking through how to create a custom UI for settings (required for C#, C++, and VB) that satisfies the UX design requirements. UI & UX The settings window may… Read more

Margin in XAML vs. CSS

According to W3C: “The ‘margin’ property is a shorthand property for setting ‘margin-top’, ‘margin-right’, ‘margin-bottom’, and ‘margin-left’ at the same place in the style sheet” respectively. Here’s the example W3C used to illustrate the order of properties in the shorthand: margin: 10px 20px 30px 40px; Top padding is 10px, right padding is 20px, bottom padding… Read more

DefaultNetworkCredentials in Windows Store Apps

Disclaimer: I’m still getting acquainted with Windows Store Apps, so I could be totally wrong; proceed with caution. It’s been a while since I last wrote a blog post, and it’s 4 AM right now, this may give you an idea why I had to get this out. Hopefully I may save poor souls that… Read more

Visual GCRoot via DGML

I was inspired by Lovett‘s post about Visualizing Runtime Object Graphs to create my first debugger extension that takes the output of !gcroot and creates a graph that one can interact with easily in Visual Studio 2010. So, what does my extension do? !vgcroot –? !vgcroot [/nostacks] [/do] <Object address> [<DGML output file>]   /nostacks… Read more