June 2005 - Posts
In a reply to my post about the Reflector add-in, Scott Dockendorf included a link to Scott Hanselman's blog. This blog contains a huge list of development- and power user tools. You should really have a look. There's a lot of interesting stuff there.
Mind you, I will be maintaining my short-list, as a means to keep track of stuff I regularly use. But I will definitely check out some of the stuff blogged but Scott Hanselman.
A colleague of mine pointed me to an add-in for Reflector, created by Denis Bauer. It helped me retrieve some of the code from a compiled assembly, which got lost when my development machine crashed before I could check-in the code.
The Reflector.FileDisassembler is a little add-in for the new version of Lutz Roeder's .NET Reflector that you can use to dump the decompiler output to files of any Reflector supported language (C#, VB.NET, Delphi). This is extremely useful if you are searching for a specific line of code as you can use VS.NET's "Find in Files" or want to convert a class from one language to another.
I've added it to my list of Must have tools. It really rocks. And the option to convert from one language to another that way is simply great!
I started using Microsoft AntiSpyware in January both at home and the office, and have been safe from spy- and adware since. But the beta would only work until the end of June. Fortunately, Microsoft have released a new beta, which should keep us safe until the end of this year.
For those of you that still don't know Microsoft AntiSpyware, check out this page to see what it will do for you. If you want to know if you can safely use this version, read the release notes.
Download your version here!
We needed to know when Easter Sunday was in a given year for my current project. I found C++ code to do this at Code Project and converted it to a C#. I then reposted the code on Code Project. But someone found a bug in the original algorithm and posted an improvement as a response to my code. The code below is the modified result, which produces accurate results:
public static void EasterSunday(int year, ref int month, ref int day)
{ if (year < 1 || year > 9999) throw new ArgumentOutOfRangeException("year", year, "Must be between 0001 and 9999.");
int g = year % 19;
int c = year / 100;
int h = h = (c - (int)(c / 4) - (int)((8 * c + 13) / 25) + 19 * g + 15) % 30;
int i = h - (int)(h / 28) * (1 - (int)(h / 28) * (int)(29 / (h + 1)) * (int)((21 - g) / 11));
day = i - ((year + (int)(year / 4) + i + 2 - c + (int)(c / 4)) % 7) + 28;
month = 3;
if (day > 31)
{ month++;
day -= 31;
}
}
And from there, it is only a few steps to the following very useful methods:
public static DateTime EasterSunday(int year)
{ if (year < 1 || year > 9999) throw new ArgumentOutOfRangeException("year", year, "Must be between 0001 and 9999.");
int month = 0;
int day = 0;
EasterSunday(year, ref month, ref day);
return new DateTime(year, month, day);
}
public static DateTime AscensionDay(int year)
{ if (year < 1 || year > 9999) throw new ArgumentOutOfRangeException("year", year, "Must be between 0001 and 9999.");
return EasterSunday(year).AddDays(39);
}
public static DateTime WhitSunday(int year)
{ if (year < 1 || year > 9999) throw new ArgumentOutOfRangeException("year", year, "Must be between 0001 and 9999.");
return EasterSunday(year).AddDays(49);
}
I bumped into this yesterday, the Fiddler Powertoy. I'm currently not building web applications myself, but I know a lot of other people do. From the Fiddler page:
Have you ever found yourself wondering how Microsoft Internet Explorer interacts with your Web application? Have you encountered a strange performance bottleneck that you can't track down? Are you curious about which cookies are being sent, or what downloaded content is marked as cacheable?
Microsoft Fiddler can help you answer these questions, and many more. Fiddler is an HTTP debugging proxy that logs all HTTP traffic between your computer and the Internet. Fiddler enables you to inspect all HTTP traffic, set breakpoints, and "fiddle" with incoming or outgoing data. Fiddler is much simpler to use than NetMon or other network debuggers because it exposes only HTTP traffic and does so in a user-friendly format.
Fiddler includes a simple but powerful Microsoft JScript .NET event-based scripting subsystem flexible enough to support a broad array of HTTP debugging tasks. Written in C# on the Microsoft .NET Framework, Fiddler is available as an unsupported PowerToy for Internet Explorer.
There are currently two documents on Fiddler at MSDN:
-
-
I read an article on Dan Fernandez's blog describing the That object. The That object is a wrapper around the VB.Net 2.0 My class, allowing you to use various objects in the .Net framework without having to worry about which namespace it is in. It was written by IDesign and you can download it here, at there website. IDesign describes the class as follows:
The My class in VB often simplifies and streamlines many operations, from Network programming to clipboard, to audio access, and so on. What takes sometimes a programming fit in C# can be done in one line using the My class in VB. If VB has Me and My, then C# should have this and That. The That class is the C# equivalent of the VB My class. It is a static class that uses the VB implementation as much as possible, and it requires adding a referencing to Microsoft.VisualBasic.
We've been discussing string use in .Net on several occasions. You can use this link as a starting point. I just read an interesting article on MSDN, with recommendations for string use in .Net 2.0. The document focuses on string comparisons. From that document:
- DO: Use StringComparison.Ordinal or OrdinalIgnoreCase for comparisons as your safe default for culture-agnostic string matching.
- DO: Use StringComparison.Ordinal and OrdinalIgnoreCase comparisons for increased speed.
- DO: Use StringComparison.CurrentCulture-based string operations when displaying the output to the user.
- DO: Switch current use of string operations based on the invariant culture to use the non-linguistic StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase when the comparison is linguistically irrelevant (symbolic, for example).
- DO: Use ToUpperInvariant rather than ToLowerInvariant when normalizing strings for comparison.
- DON'T: Use overloads for string operations that don't explicitly or implicitly specify the string comparison mechanism.
- DON'T: Use StringComparison.InvariantCulture-based string operations in most cases; one of the few exceptions would be persisting linguistically meaningful but culturally-agnostic data.
I was scanning the MSDN blogs and me into this link to the agenda and session list. We're all eagerly awaiting the official release of Visual Studio 2005, which will contain C# 2.0, and Microsoft is already planning to show version 3.0 at the PDC. An appropriate subject for my 100th blog entry.
I would love to go this year. The agenda looks promissing, loads of interesting sessions:
- Building Rich Internet Applications with ASP.Net.
- Future directions of ASP.Net
- Future Innovations in Data Access Storage
- And of course, C# 3.0 Language Innovations
I needed to find the IP address for the local machine on of the webservices I'm responsible for is running. I found the following piece of code which solved that problem. Might come in handy for others, I think:
void temp()
{ ManagementObjectSearcher moSearch = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'"); ManagementObjectCollection moCollection = moSearch.Get();
// Every record in this collection is a network interface
foreach (ManagementObject mo in moCollection)
{ // IPAddresses, probably have more than one value
string[] addresses = (string[])mo["IPAddress"];
foreach (string ipaddress in addresses)
{ Console.WriteLine(ipaddress);
}
}
}
And there are more network settings that can be retrieved using Win32_NetworkAdapterConfiguration. Check out this link at MSDN for more information.
This week, the release dates for the following products were announced by Paul Flessner at Tech•Ed 2005. The full document on this can be found here. But the bottom line is this:
SQL Server 2005, Visual Studio 2005 and Biztalk Server 2006 will be launched in the week of November 7, 2005.
DotNetDan has created a VS 2005 version of the famous DataSet Quick Watch we all love for VS 2003. You can download it here, on The Code Project. This visualizer features:
- Visualization for
DataSets, strongly typed DataSets, DataTables, DataViews, DataRows and DataColumns.
- Modified rows display in red.
- Modified cells display in bold red.
- Added rows display in blue.
- If deleted rows exist, they can be viewed by selecting the Deleted Rows radio button.
- A Row Filter can be established for active or deleted rows, using standard row filter expressions.
- Additional cell and row properties display in the bottom grid. These properties are: cell original value, cell error message, row state, row error message.
- When visualizing a
DataRow, the respective row will be selected in the visualizer's grid.
- XML representation of the
DataSet can be in the format generated by the XmlSerializer (as used by the Web Service framework, for example) or by the DataSet's WriteXmlSchema and WriteXml methods.
Short-cut keys are simply great. We all use the most common ones (CTRL + S, CTRL + C, CTRL + X, CTRL + V). Visual Studio .Net provides several pre-defined keyboard binding schemes. These schemes can be selected from the get.MyProfile pane of the Visual Studio Home Page. You can create your own custom keyboard mapping schemes from the Keyboard pane of Environment Options in the Options dialog box. You can access the Options dialog box from the Tools menu.
Below you can find links to the default binding schemes that are currently available to Visual Studio .Net users. I think most of the .Net developers will use the Default Settings.
We all know that .Net Framework 2.0 is different from .Net Framework 1.1. But how these changes impact the applications we've built can be somewhat of a mystery. Microsoft have now created a help file that contains all of these so-called breaking changes. The changes are divided into run-time and design-time changes and contain examples for each of the languages. An C# example from the help file:
Because of the new nullable syntax, there are certain scenarios where the compiler cannot tell the difference between a conditional operator and the nullable syntax. Example:
class C
{
int F() {}
int G() {}
static void Main()
{
bool A;
for (A ? F() : G(); ; ) // breaking - will report an error
}
}
You can
download the help file here.
I couldn't resist posting this. Several sources announce that Apple will switch to the Intel platform for it's personal computers :-)
CNet - Apple to ditch IBM, switch to Intel!
New York Times - Apple plans to switch from IBM to Intel for chips
A few weeks back, I was given a WSDL for a webservice. The service itself was not available at the time. So all I could do was develop against a dummy with code generated using the WSDL tool. But last Wednesday I recieved an email informing me the webservice was now available.
I opened Visual Studio and tried to create a webreference to the new service. This failed, because my machine was behind a firewall. I could solve this using this MSDN link and this MSDN link. I then still had problems, so I tried a tip from Rob van der Meijden to use SOAPscope. That helped me identify problems in the WSDL. The URL defined in the <soap:address location /> tag did not match the actual URL. A piece of code supplied by Richard van der Pal finally solved my problem.
I added the webreference by typing the URL to the WSDL in the Add Web Reference dialog. I changed the Web Reference Name to wrCustomer. I then created a new class which inherits from the class generated by Visual Studio. The code has been edited a little to hide any specific data from my current assignment:
using System;
using System.Net;
namespace MyNameSpace
{ ///
/// Summary description for MyCustomer.
///
///
public class MyCustomer : wrCustomer.CustomerService
{ public MyCustomer()
{ //
// TODO: Add constructor logic here
//
}
protected override System.Net.WebRequest GetWebRequest(Uri uri)
{ ServicePointManager.Expect100Continue = false;
System.Net.WebRequest req = base.GetWebRequest(uri);
return req;
}
}
}
More Posts
Next page »