There are some nice things to know about Visual Studio.Net 2008 that can make life easier as a programmer. In the series ‘Debugger tips VS.Net’ I am gonna talk about the debug techniques VS.Net 2008 offers. Tracepoints is the subject of this post. A tracepoint is a breakpoint with a custom action associated with it. When the tracepoint is hit the custom action is performed. An example of such a action is writing a traceline to the output window.

How can you add a tracepoint? This is easy: go to the line of code where you want the tracepoint and press F9. This will add a breakpoint. The picture below shows a breakpoint.

 

Then right click the breakpoint and choose When hit from the menu that appears.

 

The When Breakpoint Is Hit dialog appears. In this dialog you can choose to print a message. This will add tracelines to the ouput window every time the tracepoint is hit. The message can be formatted and You can include programmatic information using DebuggerDisplayAttribute syntax. You can choose to run a macro when the tracepoint hits too. In the screenshot below the DumpStacks macro from the samples is picked. Select Continue Execution if you don’t want the tracepoint to break execution of your program.

 

 A tracepoint has its own icon. It is a red diamond in the margin of the code edit window.

 That was it.

kick it on DotNetKicks.com

 Software development is an art.

The ?? operator C# operator returns the left side if it is not null. It returns the right side if the left side is null. It is very handy in situations where you can expect a value to be null but you want to use a default value if it is. Here is an example:

        string valueCouldBeNull = GetTheValue() ?? "The default value";
        Console.WriteLine("The result is " + valueCouldBeNull);
 

When assigning nullable types to non-nullable types you can avoid compile-time exceptions using the ?? operator.

kick it on DotNetKicks.com

Yesterday I was asked a question. A collegue asked how to convert an UTF-16 xml file to an UTF-8 one. He was using xslt for the conversion. I took a look at his code and everything looked fine. He was using a StringBuilder, StringWriter and a XmlWriter. He had set the encoding settings for the XmlWriter to UTF-8. Should work. Shouldn’t it? No, it does not work because a .Net string has a UTF-16 encoding and it cannot be changed, of course. So even though my collegue was setting the encoding it would not be used anyway.

Another approach was needed and I found one. The XmlWriter accepts a stream also. A MemoryStream can be used. It is just a buffer of bytes and won’t do anything with the content. Here is some example code. The first example uses a StringBuilder and doesn’t work. The second example uses the MemoryStream.

Example 1 (does not work):

StringBuilder sb = new StringBuilder();
using (XmlWriter xw = XmlWriter.Create(new StringWriter(sb)))
{
    XslCompiledTransform xct = new XslCompiledTransform();
    xct.Load(@"cdcatalog.xsl");
    xct.Transform(@"cdcatalog.xml", xw);
    xw.Flush();
}
Console.WriteLine(sb.ToString());

 

Example 2 (works):

MemoryStream ms = new MemoryStream();
using (XmlWriter xw = XmlWriter.Create(new StreamWriter(ms)))
{
    XslCompiledTransform xct = new XslCompiledTransform();
    xct.Load(@"cdcatalog.xsl");
    xct.Transform(@"cdcatalog.xml", xw);
    xw.Flush();
}
string xmlOutput = Encoding.UTF8.GetString(ms.GetBuffer());
Console.WriteLine(xmlOutput);

 

You can download an example project here.

  kick it on DotNetKicks.com

I like VB.Net. Do not tell anyone. Wink I programmed in it for many years and it is a powerful language. Just as powerful as C#. It just does not look like C. It looks like BASIC. Ok, yes, uuuuuhhmm, anyway there are some issues with the performance when using VB.Net in VS.Net 2008. Embarassed The VB team solved those issues. Read about it here.

Yesterday I installed the first service pack for Vista. But at first I had a problem installing it. Right after starting the installer it  showed a message that I did not have the right language version of Vista installed. Weird, I thought, this is the english version. The message mentioned something about incompatible language packages also, but I did not pay attention to that. Disappointed I searched the internet with Google to find out if there were other people with the same problem. There were none but one. (S)He mentioned language packages also. Hmmm, wait a minute, I thought, I installed the dutch language package. Is this the problem? Yes, it was. After uninstalling the language package the installation went fine.

How do you uninstalling a language package? In the control panel search for ‘Regional setting and language options’. Also see the figure below. Double click it and go to the ‘keyboards and Languages’ tab. In the middle of the tab you see the ‘Install/uninstall languages…’ button . After clicking it a wizard lets you select language packages to uninstall. 

This afternoon I was experimenting a bit with Filedisk. Filedisk is a tool to mount files on the filesystem as a drive. I succeeded to mount a file, but the file I created was 0 bytes long. When I tried to format the mounted file I got an error message saying the file was te small to create the filesystem. It took me a moment before realizing that the error message was correct. The file I mounted was 0 bytes long after all. I needed to create a file with some body but I could not find a application that could do that. I made my own program to do that. It is called CreateFile. You can download it here (src). You use it like this:

CreateFile filename [/Size:xxxx]

The size is entered in bytes. You can leave out the size argument. The default size is used when you do. The default size is 1024 bytes.

 P.S.: There is also a GUI version of FileDisk. It is called Filedisk Iso Mounter and you can find it here

If you like the application, maybe also like to donate.

The .Net Framework source and symbols for Windows Server 2008 and Windows Vista SP1 are available. The sources released are of the 2.0.50727.1433 build of the .Net Framework, which is the .Net 3.5 RTM build.

After this release a small change was made to the .Net Framework. The buildnumber of this version is 2.0.50727.1434. This was included with Windows Vista SP1 and Windows Server 2008. The source and symbols must match exactly with the version of the .Net Framework on a developer’s machine which means that someone running these os releases colud not reference the sources anymore for the parts Microsoft released. The new symbols and source have now been deployed for the following:

  • mscorlib.dll
  • system.dll
  • system.data.dll
  • system.drawing.dll
  • system.web.dll
  • system.windows.forms.dll

The rest of the released source and symbols were not updated.