Sep 18, 2007

Minor db4o tutorial problem

Some time ago I started playing with db4objects, an object oriented database for Java and .Net.

After installing db4o it started this tutorial (C:\Program Files (x86)\Db4objects\db4o-6.3\doc\tutorial\Db4objects.Db4o.Tutorial.exe, on my 64 bits Windows Vista Box) and everything went as smooth as possible but, when I tried to restarted it in the next day, it failed and the following dialog was shown:


Looking at this dialog we can see that the program failed to delete a file called formula1.yap under C:\Program Files (x86)\Db4objects\db4o-6.3\doc\tutorial\ folder; so I launched Process Monitor and pushed Reset button in tutorial program again.


It just confirms that the tutorial is failing to delete the file but why? Worse, why have it worked when we started it for the first time?

The .Net tutorial that comes with db4o has some minor bugs related to the way Windows Vista x64 handles writes to some specific paths, more specifically to %ProgramFiles% and %ProgramFiles(x86)% folders.

It's a Windows Vista feature called UAC (for detailed information about this topic please refer to this technet article) that prevents standard users (non administrators) from writing to some folders/registry keys, basically to keep the system more stable and secure. Actually it worked in the first time because

Ok, so how to fix this problem?

Basically there are 3 different approaches that can be applied:
  • The "Quick and Dirty" way (probably the easiest and fastest one) is to run the tutorial as an administrator. To do this just right click on the tutorial program and select "run as administrator".




  • The second one consists in adding a manifest next to the tutorial program ( (warning: Windows Vista/.Net will cache the tutorial program and will not pick you fresh manifest :(. In this case you can just "touch" the tutorial program -- or move it to another folder -- and Windows will load the manifest in the next time you start it as explained here). This simply instructs Windows to start the program with administrator rights.



  • The last one (and in my opinion the correct one) consists in fixing the tutorial in order to save this file under %LocalAppData% (or %AppData%) instead of its installation folder (thats the recommended action by Microsoft).



That's all folks ;)

In a future post I'll discuss a bit more about a UAC feature called File System and Registry Virtualization and why it wasn't applied in this case.

Sep 10, 2007

Another post in the series RTFM :)

As I've said in my last post, I'm reading C# 3.0 specification. Well, it's amazing what you can learn when you do take the time to learn more about the tools (in this case, the language) you use all day long :). This time I've find out that it's possible to use reserved words as identifiers! Amazing! (and of course, dangerous as it make it harder to read your code.) But this isn't a new feature of C# 3.0; it works with C# 2.0 (.Net Framework 2.0)! Just copy the following sample and compile it using CSharp compiler from .Net Framework 2.0!
public class @class
{
   private static void Main()
   {
      int @int = 10;
      int @delegate = @int + 30;;
      System.Console.WriteLine("Values {0} {1}", @int, @delegate);
   }
}
What do you think about using reserved words as identifiers? Let the world know your opinion! :) Adriano

Sep 4, 2007

?? Operator.. What is it good for?

Hi, Other day I was poking around C# 2.0 documentation and noted a different operator I had never seen before, ?? so I thought with myself: what is it good for? Well, after reading the documentation (remember, RTFM :) I couldn't believe I didn't known this before! The ?? operator is a binary operator that checks the left operand against null. If it is null, the expression result is the right operand value otherwise (left operand is not null) it will be the left operand value. See a sample:
string name = null;
Console.WriteLine("Value: {0}", name ?? "(null)"); // Writes: Value: (null)

name = "Adriano";
Console.WriteLine("Value: {0}", name ?? "(null)"); // Writes: Value: Adriano

Also, it is useful when used in conjunction to nullable value types.
int? i = null;
Console.WriteLine("Value: {0}", i ?? -1); // Writes: Value: (null)

i = 20;
Console.WriteLine("Value: {0}", i ?? -1); // Writes: Value: 20
PS: I've just started to play with
C# 3.0 (Visual Studio 2008 beta 2) and it seams to be a very strong language. PS2: Finally I managed to get SyntaxHighlighter to work with blogger (thanks to this post) As soon as I got more information I'll post my impressions here :) See you soon!

Mudanças

Depois de ponderar algum tempo sobre o assunto estou considerando utilizar o inglês nos próximos posts. Porque esta decisão?
  • Basicamente entendo que a maioria das pessoas que possam vir a se interessar pelo conteúdo deste blog não teriam problemas para ler conteúdo (pelo menos técnico) em inglês.
  • Escrever em inglês me ajudaria a melhorar meus conhecimentos neste idioma.
  • Adotar o inglês tornaria este blog mais acessível a outras pessoas que não conhecem o português
Se você acompanha este blog e prefere que o conteúdo continue em português deixe um comentário. Dependendo do número de pessoas posso não mudar para o inglês ou então posso postar nos dois idiomas :) Adriano.