Archive for the ‘Development’ Category

CLR, DLLs and a blast from the past

Tuesday, July 21st, 2009

The CLR and performance folks have told us old timers that some things never change :-) , although if you read closely it does!

[A primer on setting base-addresses for managed DLLs] covers how for performance reasons you probably want to [NGen] your code (on the remote computer) and ensure you have your base-addresses setup to avoid clashes. The interesting thing is that with [ASLR] enabled on VISTA, Windows 7, Windows Server 2008 and higher it doesnt help :-) .

So for the performance conscious .net coders out there targetting fast startups definitely have a read.

Gareth

Failure to run unit tests with DLL “is not trusted”?

Sunday, July 19th, 2009

Interestingly this is the first time I’ve come across this, I presume predominately because I try to only use DLL’s I’ve compiled myself and Firefox and the UNZIP tool I used never used to have this security ‘feature’.

When I was doing some unit tests I got this message

Failed to queue test run ‘Gareth@Monster 2009-07-19 21:41:43′: Test Run deployment issue: The location of the file or directory ‘d:\home\git\filehash\filehashtest\bin\debug\System.Data.SQLite.dll’ is not trusted.

This has all to do with me trying to be a good boy and downloading the latest DLL from web to ensure I was developing and testing on the absolute latest version. This helpful ‘magic’ is the Microsoft “Attachment Manager” that was introduced in XP SP2. Now it seems that both Firefox and WinZip 10 honor this feature (http://www.winzip.com/xattmgr.htm) so if you unzip a file using Winzip that has been tagged as ‘from the internet’ the unzip then tags all the files coming out as ‘blocked’.

There are a varying number of solutions:

Option 1 – Pinpoint accuracy

Select the properties on the file in question and press “Unblock”.

Attachment Manager Blocking In Action

Attachment Manager Blocking In Action

Good if you only have 1 file to deal with, bad if you have a large number of them! Unfortunately there is no good way to do this via a multi-select option, but remember if they all came from a ZIP file un ‘block’ the ZIP before performing the UNZIP!

Option 2 – ‘The ultimate sledge hammer’ – definitely for the brave

I dont recommend this!! However if you are feeling brave (and this is a personal PC and not a corporate one!) this feature can be disabled using search for “Do not preserve zone information in file attachments” in the link http://support.microsoft.com/default.aspx/kb/883260 – its a ways down!

This won’t remove alternate streams from existing files. Also this ‘might’ have side effects so use with caution.

In theory the Attachment Manager can be disabled via gpedit.msc. I say in theory because I cant see the option I’m going to write about (http://www.lansa.com/support/notes/p0348.htm)

The steps to do that are outlined below:

  1. Run the ‘Group Policy Object Editor’ (gpedit.msc) either from the Command Prompt or using the ‘Run’ command in the Windows Start Menu
  2. Expand the node ‘User Configuration’ >> ‘Administrative Templates’ >> ‘Windows Components’ >> ‘Attachment Manager’.
  3. Right-click on the third option: Do not preserve zone information in file attachments. Choose ‘Properties’.

Option 3 – Using Streams (for the script folks – and still a little brave!)

Download the handy dandy ‘streams’ from http://technet.microsoft.com/en-us/sysinternals/bb897440.aspx. Then run “Streams -d –s c:\yourdirectorywithblockedfiles” this will recurse through all the folders deleting any streams it comes across. Beware some programs may be using streams for storage, if they are you will be deleting that meta data. But if this is only in a development folder you should be OK (make sure you have backups!)

Option 4 – Copy all the affected files to a FAT file system and copy them back

Title says it all, since streams are not supported on FAT file systems performing this copy to a FAT system and then back to NTFS ‘removes’ the offending streams.

Good luck :-)

Powershell, Its time to update to the new scripting way!

Saturday, July 18th, 2009

I suspect everyone (at least reading this) is minimally aware of Powershell. The question is how much have you used it, and I mean ‘really used it’? I know I’ve been happily been using JP Software TCC LE (formally 4DOS, then 4NT) for ages, and for those wondering I am a console junkie – not really a great fan of Explorer. As an aside I do wholeheartedly recommend the JP software TCC LE, that definitely gets my thumbs up!

So I’m finally taking the plunge as PowerShell 2.0 is about to come out. Firstly I’ll cover why I’m now making the move rather than before, then will provide some good links to help get your skills up!

Why update now?

Well Powershell has been out for a long time now, but the big differentiator is that it is now coming part of the standard Windows OS release (Windows 2008, Windows 7) rather than being an additional download. For any developer that has to support 3rd party systems (aka systems you dont own) you ideally want to stick to the standard tools installed on the machine rather than having to get a number of pre-requisites.  As it is only installed by default on a small section of machines its far from a slam dunk – but once it gets into the OS distribution we can be fairly sure its going to be mainstream and remain supported!

Memory footprint

So on to most commonly cited downside made by memory conscious folks, so lets get that out of the way!

Randomly Performed on my Windows XP (SP3) – these are definitely not exact but should show orders of magnitude.

  • Command – Cmd.exe – Mem Usage 2,572Kb, VMSize 2,008Kb
  • TCC LE – TCC.exe – Mem Usage 3400Kb, VMSize 2,944Kb
  • Powershell 1.0 – Powershell.exe – Mem Usage 25,324, VMSize 22,668Kb

So obviously it is definitely an order of magnitude heavier than historic command shell implementations. There are several reasons for this, the biggest is that the shell uses a plug-in architecture so you can seamlessly add your own ‘cmdlets’ into the shell. Understandably if you start to run cmdlets (and most everything is a cmdlet) your memory foot print starts to go up as they get loaded into the process. For example if you run “PS”  to get a list of running processes your memory footprint will change as that module is loaded and executed. So if you are only concerned about memory footprints you should stop reading now – but if you are looking for functionality this is where PowerShell really shines!

Standard Cmd.exe like Navigation

After starting up powershell (“Start/Run/Powershell”) you start with a command like prompt. In my case its:

PS C:\Documents and Settings\csharphacker>

From here you can do the normal things:

  • CD – Change Directory
  • DIR – Directory listing
  • REN – Rename
  • DEL/ERASE – Delete
  • PUSHD – Push current location to stack
  • POPD – Pop last location from stack
  • CLS – Clear Screen
  • COPY – Copy file

Also notice there is tab completion of file names :-) , now standardly available – but a killer not to have!

For Unix folks running on Windows there are Unix equivilents

  • LS – Directory List
  • RM – Remove file
  • PWD – Current directory
  • PS – Process list
  • CAT – Output contents of file

Still pretty standard stuff. As you look closer you will see that infact these are not build-in commands, but actually aliases to other commands within the shell.

CommandType     Name                            Definition
-----------     ----                            ----------
Alias           ac                              Add-Content
Alias           asnp                            Add-PSSnapin
Alias           clc                             Clear-Content
Alias           cli                             Clear-Item
Alias           clp                             Clear-ItemProperty
Alias           clv                             Clear-Variable
Alias           cpi                             Copy-Item
Alias           cpp                             Copy-ItemProperty
Alias           cvpa                            Convert-Path
Alias           diff                            Compare-Object
Alias           epal                            Export-Alias
Alias           epcsv                           Export-Csv
Alias           fc                              Format-Custom
Alias           fl                              Format-List
Alias           foreach                         ForEach-Object
Alias           %                               ForEach-Object
Alias           ft                              Format-Table
Alias           fw                              Format-Wide
Alias           gal                             Get-Alias
Alias           gc                              Get-Content
Alias           gci                             Get-ChildItem
Alias           gcm                             Get-Command
Alias           gdr                             Get-PSDrive
Alias           ghy                             Get-History
Alias           gi                              Get-Item
Alias           gl                              Get-Location
Alias           gm                              Get-Member
Alias           gp                              Get-ItemProperty
Alias           gps                             Get-Process
Alias           group                           Group-Object
Alias           gsv                             Get-Service
Alias           gsnp                            Get-PSSnapin
Alias           gu                              Get-Unique
Alias           gv                              Get-Variable
Alias           gwmi                            Get-WmiObject
Alias           iex                             Invoke-Expression
Alias           ihy                             Invoke-History
Alias           ii                              Invoke-Item
Alias           ipal                            Import-Alias
Alias           ipcsv                           Import-Csv
Alias           mi                              Move-Item
Alias           mp                              Move-ItemProperty
Alias           nal                             New-Alias
Alias           ndr                             New-PSDrive
Alias           ni                              New-Item
Alias           nv                              New-Variable
Alias           oh                              Out-Host
Alias           rdr                             Remove-PSDrive
Alias           ri                              Remove-Item
Alias           rni                             Rename-Item
Alias           rnp                             Rename-ItemProperty
Alias           rp                              Remove-ItemProperty
Alias           rsnp                            Remove-PSSnapin
Alias           rv                              Remove-Variable
Alias           rvpa                            Resolve-Path
Alias           sal                             Set-Alias
Alias           sasv                            Start-Service
Alias           sc                              Set-Content
Alias           select                          Select-Object
Alias           si                              Set-Item
Alias           sl                              Set-Location
Alias           sleep                           Start-Sleep
Alias           sort                            Sort-Object
Alias           sp                              Set-ItemProperty
Alias           spps                            Stop-Process
Alias           spsv                            Stop-Service
Alias           sv                              Set-Variable
Alias           tee                             Tee-Object
Alias           where                           Where-Object
Alias           ?                               Where-Object
Alias           write                           Write-Output
Alias           cat                             Get-Content
Alias           cd                              Set-Location
Alias           clear                           Clear-Host
Alias           cp                              Copy-Item
Alias           h                               Get-History
Alias           history                         Get-History
Alias           kill                            Stop-Process
Alias           lp                              Out-Printer
Alias           ls                              Get-ChildItem
Alias           mount                           New-PSDrive
Alias           mv                              Move-Item
Alias           popd                            Pop-Location
Alias           ps                              Get-Process
Alias           pushd                           Push-Location
Alias           pwd                             Get-Location
Alias           r                               Invoke-History
Alias           rm                              Remove-Item
Alias           rmdir                           Remove-Item
Alias           echo                            Write-Output
Alias           cls                             Clear-Host
Alias           chdir                           Set-Location
Alias           copy                            Copy-Item
Alias           del                             Remove-Item
Alias           dir                             Get-ChildItem
Alias           erase                           Remove-Item
Alias           move                            Move-Item
Alias           rd                              Remove-Item
Alias           ren                             Rename-Item
Alias           set                             Set-Variable
Alias           type                            Get-Content

So if you start to look at this list you will begin to understand why this is a bigger beast than CMD or TCC LE will ever be.  However it has to be said that these commands are not “identical” to your preferred flavor – but more of a likeness to it. So LS doesnt have exactly the same characteristics, the same was that DIR doesn’t either – but the ‘intent is the same’.

The best keyboard shortcut for me is F8 (but I want to remap it to the up arrow!)  – read more about shortcuts can be found here.

Recommended Reading Links (I should point out I am not affiliated with any of the below, but they are what I have used to get more acquainted with PowerShell) :

After reading these you should have a better understanding of the power of power shell. If using PowerShell to read/manipulate the registry, open CSV files, perform credential maintenance via script still doesnt make you want to learn it then remember that SQL 2008 has Powershell integration. So now you can browse your SQL schema using PowerShell as well.

This is where we can say for a certainty “Microsoft has started to take scripting seriously”!

Pretty cool stuff,
Gareth

Azure Pricing Announced….

Tuesday, July 14th, 2009

Finally we have the details we have all been waiting for, unfortunately its more of a wimper or even worse “me too” pricing model.

The official information can be found below:

Fundamentally the problem for me is that it is competing head to head with Amazon with no clear winner. Infact Amazon not only has a small price advantage with their Linux offering, but they have it all running with lots of infrastructure setup over many years. They are the defacto ‘standard’ and they are cheaper on Linux and only a tiny bit more expensive on Windows!

Unfortunately at first blush this doesnt seem to be a business compelling reason to switch to Azure, and evaluation which one are you going to choose? A company that has been doing it for years and has been maturing their model and offerings or the new one to the block. I’m sure Microsoft will change their pricing model – but it appears to be a surprisingly weak opening offer from Microsoft.

A new news/blog articles covering this can be found here:

Thoughts? Am I missing something fundamental here?

Gareth