Browse by Tags

Tagged Content List
  • Blog Post: 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...
  • Blog Post: Running a SQL Statement on all Databases

    exec sp_MsForEachDB 'SELECT "?", 1' 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.
  • Blog Post: 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.BeforeSendRequest method: /// <summary> /// Represents a message inspector object that can be added to the <c>MessageInspectors<...
  • Blog Post: 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>...
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: 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 are destined to...
  • Blog Post: 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...
  • Blog Post: Tiny C++ Unit Test Framework

    I was working on a small project for personal use that I wrote in C++ and I wanted to test it. Since it’s a tiny project, I didn’t bother installing a well-known test framework that ships with a plethora of features. I just wanted a simple test runner that can show me a failure when it happens. Basically...
  • Blog Post: ExtensionDataObject is not Marked as Serializable

    If you use Data Contracts , then probably your classes implement the IExtensibleDataObject interface to allow (de)serialization of different versions of the data contract. I won’t go into details about the use of ExtensionDataObject , the type of the ExtensionData property you need to implement. I just...
  • Blog Post: How to: Create Interfaces with Static Methods via IL?

    If you try to add a static member to an interface, you will get the following error: The modifier 'static' is not valid for this item In this case, you should create an abstract class instead of an interface, because interfaces are contracts and should not implement any methods. However, it’s...
  • Blog Post: On Testability

    Acceptance testing is basically black-box testing done by the QA team to sign off. It’s very important to have clear pre-defined goals for acceptance testing as early as possible during the planning phase. In fact, the requirements specifications should define negative scenarios and expected failure...
  • Blog Post: How to: Use Locks and Prevent Deadlocks?

    Multi-threading is used in almost all real-life applications. I summed up my thoughts on use of locks and deadlock prevention in the following related topics: Thread Safety From a thread safety perspective, resources (memory) is classified as either thread-exclusive, read-only, or lock-protected...
  • Blog Post: How to: Debug Deadlocks Using Windbg?

    Attach the debugger to the process Load SOS ~* e !clrstack to view the CLR stack of all the threads and where they are Look for System.Threading.Monitor.Enter(System.Object) in the top frames Load SOSEX.dll from http://www.stevestechspot.com/SOSEXUpdatedV11Available.aspx !dlk to detect...
  • Blog Post: WCF Service Throttling

    Throttling, generally speaking, is tricky. Get the limits low and you may be prone to DoS and clients timing out trying to connect to your service in vain; Get them high and you may end up with an overloaded service that’s eating up machine resources until it crashes. There’s a sweet spot in between...
  • Blog Post: C++: Calling a Virtual Function From a Constructor is not Polymorphic

    In C++, if you call a virtual function form a constructor, it won’t be polymorphic, meaning that the following code won’t behave as you may have expected: class Foo { public : Foo() { whoAmI() ; } virtual void whoAmI() { cout << "Foo::whoAmI()" << endl ; } } ; class Bar : public Foo { public...
  • Blog Post: Passing C++ Arrays by Value

    Just in case you needed to, you can wrap an array into a struct/class and pass it by value to a function: template < typename T, int N> struct array { T value[N]; T & operator []( int i) { return value[i]; } }; template < typename T, int N> void passByValue(array<T, N> a) { cout...
  • Blog Post: Proxy Design Pattern

    One of the useful design patterns is the proxy design pattern, it allows you to control access to an object via a proxy and also saves you the startup and cleanup overheads as you instantiate only what you use upon request (lazy initialization). Take a look at the following example: #include<iostream>...
  • Blog Post: Nested For-each Loops in SQL

    Usually, it's not recommended that you use loops in SQL unless you need to. You should use set-based queries instead. However, if you need to, there are many ways to loop, one of them is using cursors. For example, let's say that you have multiple DBs and you need to select count(*) from some tables...
  • Blog Post: scanf() vs cin

    It has been a while since the last time I wrote some C code, since I come from a C++ background, hence I seldom use scanf(). Without going into many details for the reasons why one should use scanf or cin , I just want to point out one difference on return values. When should I stop the loop, here’s...
  • Blog Post: Windbg

    Using Windbg, aka Debugging Tools for Windows , is a great way for debugging, crash analysis, and reading dump files. If you’re not a keyboard person who likes to write commands and be in the driver’s seat, you might not like it at the first glance, but after using it, you’ll appreciate its power. To...
  • Blog Post: !exploitable

    !exploitable is a crash analyzer plug-in for windows debugger (windbg) that does post-mortem analysis of a crash and assists its security risk, very cool! The project is licensed under Microsoft Public License (Ms-PL) and you can download it at codeplex . The analyzer rates the crash one of the following...
  • Blog Post: How to: Tell if files are identical using TFS APIs?

    In a previous post, I answered this question using Diff APIs, which will require the items to be downloaded first. Here's a faster way to do it (thanks to MichalMa ): Use GetItem or GetItems method to get the Item objects for the files. If ContentLength and HashValue for the items match, and HashValue...
Page 1 of 2 (32 items) 12