Friday, April 30, 2010

Windows Event Log Message Text File

It took me a while to find the format of the message text file, but here it is.

Don't forget that you need a newline after the last full-stop in the file.

Thursday, April 29, 2010

ETW in .NET

After searching for a while, I found the classes for using Event Tracing for Windows in .NET. They are in the System.Diagnostics.Eventing namespace.

Note that these classes only work on Vista and Server 2008 (and newer).

Wednesday, April 28, 2010

Differences between csc (devenv) and msbuild

The drive letter in the stack frame text is lower case when built using msbuild, and upper case when build in VS 2008.

Monday, April 26, 2010

WCF Tools

WCF test client: WcfTestClient.exe.

Trace viewer: SvcTraceViewer.exe.

Friday, April 23, 2010

Contract first WCF tips

Generate types from xsd using WSCF Blue with options set to correct capitalisation.

On the interface:
Apply the ServiceContractAttribute with the service namespace.
Apply the XmlSerializerFormat(SupportsFaults = true) attribute.

On the interface's operation:
Apply FaultContractAttribute.
Apply OperationContractAttribute.

On the service class:
Apply any behaviour attributes, such as for error handling.
Apply the ServiceBehaviourAttribute, and set ConcurrencyMode = ConcurrencyMode.Multiple, IncludeExceptionDetailInFaults = false.

The operation should take a type such as:

[MessageContract(IsWrapped = false)]
public class Input
{
    [MessageHeader(Name = "headerData")]
    public Header Header { get; set; }

    [MessageBodyMember(Name = "inputData")]
    public Body Body { get; set; }
}

The response must be similar:

[MessageContract(IsWrapped = false)]
public class Response
{
    [MessageHeader(Name = "headerData")]
    public Header Header { get; set; }

    [MessageBodyMember(Name = "responseData")]
    public Body Body { get; set; }
}

Thursday, April 22, 2010

Preventing method inlining in c#

I sometimes want to prevent inlining of methods byt the JIT in C#. Usually this is because I need the call stack to be preserved, for example when using Assembly.GetCallingAssembly.

This is the attribute:
[MethodImpl(MethodImplOptions.NoInlining)]

Wednesday, April 21, 2010

Detailed performance summary in MSBuild

Use the /ds switch to get a summary of build nodes and the projects they built, with timings.

Sunday, April 18, 2010

Different types of SafeHandle

I ran into the following error:
"Cannot marshal 'return value': Returned SafeHandles cannot be abstract."

The Microsoft.Win32.SafeHandles namespace has several different handle types.

Thursday, April 8, 2010

Change to folder that PowerShell script is located

To change to the folder or directory that the executing PowerShell script is located:

pushd (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)

Alternatively:

$scriptFolder = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent

Note that $PSScriptRoot is preferable for PowerShell 3.0.