QText 2.30 (Beta 1)

This was mostly clean-up of QText. Lot of common modules were changed with new versions and general bug-fixing was done. I did my best not to break something and hopefully I succeeded in that. Some new features did manage to get in and I will here introduce two of them.

Open containing folder is added on tab’s context menu. It will allow you to open folder directly in explorer. It may come handy when one needs to export file to another location.

Another feature long over due is copy/paste as text. It is added on text’s context menu and it will finally allow you to strip clipboard content of all formatting either before copy or after paste.

Download and try it.

InternalsVisibleTo

InternalsVisibleTo is interesting attribute. It will make all it’s internal (or friend) fields open to the special one. In this case “special one” is another assembly.

Let’s try to elaborate this with example. Assembly A.exe has reference to B.dll. A.exe can see all public fields and nothing more. However, if designer of B.dll adds InternalsVisibleTo attribute, A.exe will be able to see his fields marked with internal also.

One can argue that this violates “black box” principle and I would agree. This attribute is not to be used regularly. I can think only two reasons why you should use this.

First one is component test. If you “befriend” your test assembly (A.exe) and B.dll this means that testing of target assembly is not limited to public interface. You suddenly have power to test internal workings.

Another usage is for those solutions that have multiple projects in different language. Sometimes you just have components already available in one language (e.g. C#) while main project is in another (e.g. VB.NET). Instead of rewriting everything, simple make new assembly and have all it’s content internal with InternalsVisibleTo exception for main project.

For this case benefits are doubtful since you might as well make those classes public and everything will work as it should. However, I like to make it internal in order to prevent others accessing it. If you just leave public assemblies laying around chances are that someone will use it.

That may be new guy on project that doesn’t know history of that class and he will just see opportunity to hook into already existing interface. He will not know that this was not intended to be public interface and that it wasn’t tested as such and probability is high that something will break.

While public assemblies hopefully get interface testing that they deserve, original idea of this assembly was to be glue between languages. It may be that everything works great while it has benefit of all calls being made from main project but, once you directly access it, you will stumble on quite a lot of problems and border case error that weren’t issue before. And if you ship it, you get to support public interface that was never designed as such.

If you still want to use this attribute after all this warnings, just add it in AssemblyInfo.cs (or your own favorite place):

[assembly: InternalsVisibleTo("A, PublicKey=00240000048000009400000006020000002400005253413100040000010001002de64bdf2fb7ba60913800e843fe50288f7c1467051bb0a70eca140d1e3900530a51931ead28a80d50c7b4bd7a6ec868f601dee366fef644d129a43d6eb8090c1fd097d4e13b80b1069eafab518233e0f21e14e89ee73e47486a7faf4ea2a4ad5dd48a80d1477fdd3c1715c8b46e876bbc2c27595914a0c1437d44e656e4c2d3")]

As you can see, attribute will take one argument consisting of two parts separated by comma (,). First is name of your project (in this case “A”) and other is public key of that strong-signed assembly (yes, this attribute will not work on assemblies that are not strong-signed).

In order to get that last piece of puzzle, one can use Microsoft’s Strong Name utility:

sn -Tp .\A.exe

Microsoft (R) .NET Framework Strong Name Utility  Version 3.5.30729.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Public key is
00240000048000009400000006020000002400005253413100040000010001002de64bdf2fb7ba
60913800e843fe50288f7c1467051bb0a70eca140d1e3900530a51931ead28a80d50c7b4bd7a6e
c868f601dee366fef644d129a43d6eb8090c1fd097d4e13b80b1069eafab518233e0f21e14e89e
e73e47486a7faf4ea2a4ad5dd48a80d1477fdd3c1715c8b46e876bbc2c27595914a0c1437d44e6
56e4c2d3

Public key token is b80ce85f4244428f

Of course, to do this you will need to have “C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin” (or whichever directory holds sn.exe on your system) in path.

7 Is a (Hopefully) Lucky Number

Illustration

It seems that Microsoft likes number 7.

New version of Microsoft’s OS for mobile phones looks like nothing we’ve seen on their mobiles before. And, taking all into consideration, I must say it is a good thing.

There is video on Channel 9 with whole demo and I will just make short summary here.

Biggest change is start screen. It works like all screens on modern phones and OEMs will not be able to change it anymore. At last there will be common interface among phones and not whole variety that we used to see.

Internet Explorer got rework. Finally it works like mobile browser should. It has all touch-gestures you would expect. Even complicated pages can be rendered and while one page is being loaded, you can switch to other tab to check something else. Yes, you read it correctly, it has multi-tab support.

E-mail and calendar along with Exchange integration are still remain strong sides. Nice addition is ability to have business and personal calendar displayed side-to-side.

And finally there are more stricter hardware requirements. It requires capacitative screen, accelerometer, GPS… It also restricts screen resolutions to manageable number. Older versions of Windows Mobile had bunch of screen resolutions and rations added over years and it was pain-in-the-ass to support them all.

Viewing all these things make my heart hurt a little since there is no talk about my favorite non-touch screen devices. It seems that their days are numbered (and that number is not seven).

I do hope that this operating system will have better adoption than Windows Vista had and that Microsoft takes back some of Smartphone cake. They do have best development environment for mobile phones. I hope that they will finally have Smartphone worth enough for it.

P.S. You might also wish to check Windows Phone 7 Series website.

VHD Attach 1.50

Illustration

It has been a while since I released VHD Attach. It worked perfectly for me and, judging from comments on Internet, for quite a few other people.

One thing that gave me most grief was necessity of going through UAC prompts. This “feature” is gone now. VHD Attach will install itself as service during setup and thus all UAC prompts will be avoided.

Another feature long overdue is ability to work properly on Windows 7 that are not of English descent. Although most of features weren’t affected, this is definitely step forward.

You can download new version here.

How to Create Self-installing Service

Creating Windows Service quite often comes as natural choice when some long-term task needs to be done or, god forbid, you need something running while there is nobody to log on. Although services are useful, there are two things that annoy me and they are just too non-obvious to do. One is debugging services and another one is installing them.

For quite a while I’ve been using installutil.exe in order to install services. Since I am fan of being able to put things on system without actually installing them, that meant that I went through hoops to write C# code which will find installutil.exe in all it’s possible locations, under any combination of service packs and then to parse output once it gets executed.

I am not proud that it took me literally years to get idea to open installutil.exe in Reflector. And there, under whole glory, there was single function that does everything. And to make things even better parameters for this function are same as parameters for installutil.exe itself.

In order to install service, it is enough to pass name of executable (executing assembly in this example) and magic will happen:

ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });

Uninstall is same story. Additional “unistall” (or “u”) flag is all it takes:

ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });

Design of whole thing leaves lot to be desired. It just doesn’t feel like .NET - it feels like whole thing was pushed in after somebody noticed that there is no installer and there are only 2 hours before final version of .NET comes out.

One could get into refactoring whole thing out and making “proper” installer without too much effort. However, personally I will not do it. Although this function annoys me, I am also assured that Microsoft takes care of testing it and that it will work on every supported version of .NET Framework on every supported platform. Services are difficult enough without risking installation issues on some obscure combination.

Things that are not (badly) broken should not be fixed.

P.S. Not to forget, you need reference to System.Configuration.Install.dll in your program.