Latest posts
Slow Virtual PC network with Windows 7
5/21/2010 7:01:12 AM
Ok yet again this is one of those notes to myself blog entries that might help someone else with a problem of network performance with a virtual PC.
Unlike my friend Liam Westley who is now a MVP for virtualization after moving to windows 7 recently I decided that I'd just use the Virtual PC that comes with windows 7 rather than fighting with either Hyper-V or Installing the older Virtual Server family.
I've spent some time looking into a problem where when I uploaded to Windows 2003 server I had running in a VM the upload speed was terrifyingly slow (Using BITS as it happens but UNC connections weren't any better) from my laptop, downloads seem to be OK. Worse still other people who uploaded to the server got the kind of performance figures I was expecting to see.
Anyway turns out the problem is TCP task offloading this kb article 888750 at Microsoft covers how to turn off task offloading and somewhat explains the problem.
Basically you create a DWORD key called DisableTaskOffload in HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters and set it to 1 then reboot your PC.
Importing keys for VS2010
5/10/2010 12:54:25 PM
Visual studio 2010 has removed the prompt for a password when you use codesigning with a .pfx file. This means you'll often get this error message:
C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\Microsoft.Common.targets(1970,9): error MSB3325: Cannot import the following key file: mykey.pfx. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name:
VS_KEY_C0D0ACB5FAE2DFE3 [C:\\Source\\MyProject.csproj]
C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\Microsoft.Common.targets(1970,9): error MSB3321: Importing key file "mykey.pfx" was canceled. [C:\\Source\\MyProject.csproj]
This is down as a connect bug here https://connect.microsoft.com/VisualStudio/feedback/details/524792/importing-key-file-was-canceled?wa=wsignin1.0 and sadly no one gives the correct answer.
This is somewhat cryptic and doesn't actually tell you how to fix the problem. So here for future reference is the answer (obviously change the file name and key to match your error message) run it from the command line:
sn.exe -i mykey.pfx VS_KEY_C0D0ACB5FAE2DFE3
Hope this helps.
Just noticed that you use certmgr.exe for installation of pfx for ClickOnce deployment purposes
New mobile phone time
12/10/2009 4:55:01 AM
It's hit that time again where the contract is up on my mobile phone and it's time for a new phone. This time I've decided to take TMobiles lower price contract and use the savings to buy a sim-free phone.
So a quick look around the pre-xmas market shows a few phones that look promising (main requirement is 800x480 screen size as a minimum). The phones that made my shortlist are below:
iPhone 3GS - I really can't bring myself to buy one for personal use, tethering costs 10 a month on O2 and the screen is now a little low-res and the lack of easy development (I'd need a mac) and apples attitude really puts me off.
Status - Not for me, but my wife wants one.
HTC HD2 - Well it looks lovely, has all the features that I want BUT it's got Windows Mobile 6.5 as the underlying OS and the play I've had with the emulator didn't inspire me (Although with HTC UI I'm not sure this is a huge problem).
Status - Probably if it was Windows Mobile 7
Acer Liquid A1 - I had this on back order for a while BUT acer don't seem to have delivered just yet and it's running the older Android Donut 1.6 OS (Most of the motorola comments apply here as well) BUT it does have a budget price. Its also somewhat unclear if it will ever get upgrading to eclair.
Status - Might be a dead end phone, if hackers don't crack root (last seen hackers got root).
Motorola Milestone - I cancelled the order for the Acer Liquid and moved over to this once it became available from expansys. It's running Android Eclair and has been billed in the US as an iPhone killer. Problem is the one feature that I absolutely require from a smart phone seems to be missing tethering the phone as a modem for my laptop (I work in police stations where getting internet access is rare). Now there are third party solutions for this but they either cost money OR require root access to the phone. Looking at the US based forums for it's sister phone the Droid this seems to be a trick that no-one has managed yet (there seems to be a part way solution). Finally there is no sync with Outlook unless your running exchange.
Status - Would be a contender but late delivery, no Outlook sync and potential lack of root kills it.
Nokia N900 - This phone is what I ended up getting. It hits several sweet spots for me. Tethering is there out of the box (you do need the nokia PC suite installed) so no messing around trying to get a new kernel with iptables loaded. There is a keyboard which means I'm not relying on a on-screen one it's small and yet again a three line qwerty I'd have preferred a seperate number row, but at least when you enter a phone number it sees the top row as numbers. The killer item for me was that it comes with xterm and vi gotta love any phone with those in box. The only downside is the software still feels a little unfinished in places, for example as I'm typing this my screen brightness keeps changing, I suspect this is flickering sunlight confusing a sensor but who knows.
Status - I like it but probably currently for geeks only. May well improve dramatically with next few firmware releases.
In summary all of these phones have promise and for me the nokia is great fit. For my wife the iPhone is probably a better phone. Both of the android contenders fail at the moment due to lack of true openess (they are very close but the need to hack them to get root isn't a good sign)
Finding the BOM
1/9/2009 12:34:02 PM
Michael Kaplan posted a small challenge on his blog to write some small code to find out the Byte Order Marker or BOM in the start of a file. So I kicked up the C# compiler and wrote this little bit of code:
public enum Encoding
{
Unknown = 0, BomBigEndianUcs4, BomUcs4, BomUtf8,
BomUtf16, BomBigEndianUtf16
}
// We use Bit 3 as a end of data marker, true means end
// bit 5 happens to be same value as bit 3
private static byte[] matchData =
{
0x00,0x00,0xF6,0xFF, // 0- 00 00 FE FF Bom UCS4 Big endian
0xF7,0xF6,0x00,0x08, // 4- FF FE 00 00 Bom UCS4 Little endian
0xE7,0xB3,0xBF, // 8- EF BB BF Bom UTF8
0xF7,0xFE, // 12 - FF FE Bom UTF16 Little endian
0xF6,0xFF // 14 - FE FF Bom UTF16 Big endian
};
public static Encoding DetectType(byte[] data)
{
int i = 0;
int offset = 0;
Encoding currentEncoding = Encoding.BomBigEndianUcs4;
while (i < matchData.Length)
{
byte compare = (byte)((matchData[i] & 0xf7) | ((matchData[i] & 0x20) >> 2));
if ((offset >= data.Length) || (data[offset] != compare))
{
offset = 0;
while ((matchData[i] & 0x08) == 0) i++;
currentEncoding++;
}
else
{
if ((matchData[i] & 0x08) == 0x08) return currentEncoding;
offset++;
}
i++;
}
return Encoding.Unknown;
}
Now it's not clear what this will get translated into post JIT so I converted it into C (changing the enum slightly to save a bit of space) and ran that through MSC in assembler output mode and got back a figure of 89 bytes for the code and 14 bytes for the table which I think is pretty good.
typedef enum
{ Unknown = 0, BomBigEndianUcs4=3, BomUcs4=7, BomUtf8=10,
BomUtf16=12, BomBigEndianUtf16=14
} Encoding;
// We use Bit 3 as a end of data marker, true means end
// bit 5 happens to be same value as bit 3
static unsigned char matchData[] =
{
0x00,0x00,0xF6,0xFF, // 0- 00 00 FE FF Bom UCS4 Big endian
0xF7,0xF6,0x00,0x08, // 4- FF FE 00 00 Bom UCS4 Little endian
0xE7,0xB3,0xBF, // 8- EF BB BF Bom UTF8
0xF7,0xFE, // 12 - FF FE Bom UTF16 Little endian
0xF6,0xFF // 14 - FE FF Bom UTF16 Big endian
};
static Encoding DetectType(unsigned char data[],int length)
{
int i = 0;
int offset = 0;
while (i < sizeof(matchData))
{
unsigned char compare = ((matchData[i] & 0xf7) | ((matchData[i] & 0x20) >> 2));
if ((offset >= length) || (data[offset] != compare))
{
offset = 0;
while ((matchData[i] & 0x08) == 0) i++;
}
else
{
if ((matchData[i] & 0x08) == 0x08) return i;
offset++;
}
i++;
}
return Unknown;
}
Following on from that I extended the code to support the detection of all of the stuff in Appendix F of the XML specification.
public enum Encoding
{
Unknown=0,BomBigEndianUcs4,BomUcs4,BomUtf8,
BigEndianUcs4,Ucs4Odd,BigEndianUcs4Odd,
Ucs4,BomUcs4Odd,BomBigEndianUcs4Odd,
BigEndianUtf16,Utf16,Ascii,EBCDIC,
BomUtf16,BomBigEndianUtf16
}
// We use Bit 3 as a end of data marker, true means end
// bit 5 happens to be same value as bit 3
// If we're doing a full appendix F of the XML docs then
// we change this and use bit 6 for the last EBCDIC entry and
// UTF16 Bom Entries
private static byte[] matchData =
{
0x00,0x00,0xF6,0xFF, // 0- 00 00 FE FF Bom UCS4 Big endian
0xF7,0xF6,0x00,0x08, // 4- FF FE 00 00 Bom UCS4 Little endian
0xE7,0xB3,0xBF, // 8- EF BB BF Bom UTF8
0x00,0x00,0x00,0x3c, // 11 - 00 00 00 3c UCS4 Big endian
0x00,0x00,0x34,0x08, // 15 - 00 00 3c 00 UCS4 Odd Little
0x00,0x34,0x00,0x08, // 19 - 00 3c 00 00 UCS4 Odd Big
0x34,0x00,0x00,0x08, // 23 - 3c 00 00 00 UCS4 Little endian
0x00,0x00,0xF7,0xFe, // 27 - 00 00 FF FE Bom UCS4 Odd Little
0xF6,0xF7,0x00,0x08, // 31 - FE FF 00 00 Bom UCS4 Ddd Big
0x00,0x34,0x00,0x3f, // 35 - 00 3c 00 3f UTF16 Big endian
0x34,0x00,0x37,0x08, // 39 - 3c 00 3f 00 UTF16 Little endian
0x34,0x37,0x70,0x6d, // 43 - 3c 3f 78 6d Ascii
0x44,0x67,0xa7,0x9c, // 47 - 4c 6f a7 94 EBCDIC
0xF7,0xFE, // 51 - FF FE Bom UTF16 Little endian
0xF6,0xFF // 53 - FE FF Bom UTF16 Big endian
};
public static Encoding DetectType(byte []data)
{
int i = 0;
int offset = 0;
Encoding currentEncoding = Encoding.BomBigEndianUcs4;
while (i < matchData.Length)
{
byte compare = (byte)((matchData[i] & 0xf7) | (i>=47?((matchData[i]&0x40) >> 3):(matchData[i]&0x20) >> 2));
if ((offset >= data.Length) || (data[offset] != compare))
{
offset = 0;
while ((matchData[i] & 0x08) == 0) i++;
currentEncoding++;
}
else
{
if ((matchData[i]&0x08)==0x08) return currentEncoding;
offset++;
}
i++;
}
return Encoding.Unknown;
}
Which I think isn't too bad a bit of code, if you could live without the EBCDIC detection you can drop the bytes from the table and the ternary statement and I'd guess your code wouldn't be too big.
I'll have a think about alternative methods over the weekend and see if I can beat the 103 bytes of assembler that my first attempt generated.
server swap
10/18/2008 4:18:15 PM
I've decided to move my personal websites from a shared hosting environment to a vps solution, so far it seems to be going well. I have a couple of issues: moving a DNS registration from my ex-hoster and seeing if I can port 587 opened so I can use it for outbound smtp.