Wednesday, December 2, 2009

Listing all PowerShell type accelerators

Type accelerators are shortcuts (similar to aliases) for .NET type names.

For example:

[int]3.0
and
[system.int32]3.0

Are equivalent because there is a type accelerator that maps int to System.Int32. They can be very useful when dealing with longer type names such as System.Text.RegularExpressions.Regex ([regex]).

The way to list all the currently defined type accelerators is:

([type]::gettype("System.Management.Automation.TypeAccelerators"))::get | sort key

TypeAccelerators also has an Add function that can be used to define new type accelerators.

Monday, November 30, 2009

Copying the current working directory to the clipboard in PowerShell

To copy the current working directory to the clipboard, use the following command:

(get-location).ToString() | out-clipboard
Or:
(get-location).ToString() | clip

The first method requires the PowerShell Community Extensions. The second requires clip.exe, which is present on Vista (and newer) OSs, or older OSs with some resource kits installed.

Another useful trick is to start Windows Explorer in the current folder:

explorer .

Thursday, November 5, 2009

Frameworks and tools for Silverlight

To keep track of the ballooning list of frameworks and helpers that are required or helpful when working with Silverlight and/or WPF, I've started a list (in no particular order) here:

1 Silverlight Tools for VS 2008 SP1
2 Composite WPF and Silverlight (Prism)
3 Silverlight Toolkit
4 RIA Services
5 Silverlight Unit Test Framework
6 This Microsoft hotfix for a problem with unit tests in projects contained in the same solution as a Silverlight project.

Useful control toolkits:
1. Dev-express Silverlight DataGrid
2. Visifire open source data visualisation tools (charting)
3. Blacklight

Hopefully VS 2010 will roll some of these up and they won't have to be downloaded separately.

Tuesday, October 27, 2009

Prism for Silverlight

Fantastic video introduction to Prism for Silverlight.

WinDbg symbol path

Following is the path to O/S symbol files used by WinDbg.

SRV*your local symbol folder*http://msdl.microsoft.com/download/symbols

Wednesday, September 30, 2009

FxCop custom dictionary

FxCop is an excellent tool for ensuring code consistency, but sometimes I need to add domain jargon to the custom dictionary. Since there is no official XML schema for CustomDictionary.xml, the following file is the most authoritative reference:

C:\Program Files\Microsoft FxCop 1.36\CustomDictionary.xml

(If installed into the default location on a 32 bit machine.)

Tuesday, September 29, 2009

Slow builds of Windows Mobile applications

Every time I install a new machine with Visual Studio and write applications for Windows Mobile, I need to turn off the Platform Verification task to get reasonable build times, but I invariably forget how to do this.

The file is %windir%\Microsoft.NET\Framework\{newest framework version}\Microsoft.CompactFramework.Common.Targets. Open this file for editing (as administrator), and add a 'false' condition to the PlatformVerificationTask.

The line you edit should look like:
Name="PlatformVerificationTask" Condition="false">

Tuesday, September 22, 2009

WinDbg with managed code

Loading the correct version of SOS is done by: .loadby sos mscorwks.

Useful commands in SOS:
List CLR threads: !threads
Dump managed stack of current thread: !CLRStack
Dump managed stack of current thread with parameters and locals: !CLRStack -a
Dump managed and native stack of current thread: !DumpStack
Break on first chance CLR exceptions: sxe clr
Get IL of method: !ip2md address, then !u result
Display last exception info: !pe (use Event Filters to run the command whenever a CLR exception is thrown)

Another useful tool is SOSEX, which supports deadlock detection, etc.

I was unable to get WinDbg to be the postmortem debugger for all crashes - installing it only seems to work for native applications.

Native commands:
List O/S threads: ~
Change thread by: ~{threadnumber}s or ~~[{threadid}]s
Handle tracing: !htrace

This cheat sheet is also useful.

WinDbg extensions

This blog entry will be updated to keep track of useful extension DLLs used with WinDbg since I don't use WinDbg very often:

SieExtPub.dll: useful for seeing what locks and critical sections are affecting your program. Download at Debugging Tools Download.

Loading the correct version of SOS is done by: .loadby sos mscorwks.

Wednesday, September 2, 2009

SafeHandle better than IntPtr for O/S HANDLEs

During my recent travels through P/Invoke, I found SafeHandle, which is preferable to IntPtr for handle types.

See: this blog entry.

Unfortunately, as with many good things, it is not available in the Compact Framework. No HandleRef either.

Now I just need to find out whether I should be using IntPtr or UIntPtr...

GCHandle

I seem to struggle to find this little class whenever I need to, and usually only find it after exhausting all the methods on Marshal before eventually finding it using Google.

GCHandle is used to get the address (IntPtr) for an object and can pin the object so it won't be moved while native code is using it.

This blog describes why GCHandle doesn't implement IDisposable.

Trap for young players: if your object is a struct or other value type, it will be boxed and that copy will be pinned, not your original structure. This boxing happens when you pass your instance to the GCHandle constructor and it is cast to the object base class.

Welcome

This blog is somewhere for me to jot down any snippets or ideas regarding programming, and isn't really intended for others to read. Anyone else finding this useful will just be a bonus!