Comments, how-to's, examples, tools, techniques and other material regarding .NET and related technologies.
Tuesday, April 08, 2008
ControlPaint and Vista
Wednesday, April 02, 2008
Property Getters with Bad Manors
public static int Counter {
get {
int cnt = counter;
counter = 0;
return cnt;
}
}Ok, the documentation says that calling this getter will reset the counter. However...
Still, in my opinion this is bad coding practice. Getters shouldn't modify the object. The reason for that is that some IDE's use the getters for displaying object data in debugging sessions. As a consequence debugging code and looking at the member of this object influences the outcome of the debugging session. I call this bad manors of that getter.
The better approach would have been to use a method with a more intuitive name for example "ReadAndResetCounter()". That would a) avoid accidental modification during debugging sessions, b) follow the good coding practice of getters being non-modifying accessors, and c) would express the actual functionality of the code in a more understandable way.
Some recommendations as a take-away:
- Don't implement getters that modify the object
- Instead use a method with a descriptive name
That way you will make it easier for other engineers to use your code and/or library.
(Now I'm wondering how long it will take until Charlie reads this. I'm sure he will agree with me!)
Monday, March 31, 2008
"Location is not available" on Vista
- "Preparing your desktop..." for an extended period of time
- "Location is not available" after you log in
- Desktop looks more like XP and has lost the Aero look-and-feel
I don't know what the reason for this was. Maybe it was relating to my Vodem to not being able to survive stand-by and/or hibernate. Maybe it was because Vista decided to run some lengthy checks, like CHKDSK. The event logs don't give a clue.
Resolution: Reboot another time.
Monday, March 24, 2008
csUnit 2.3 available
unresolved external symbol ?.cctor@@$$FYMXXZ
Monday, March 17, 2008
csUnit, Visual Studio 2008, Vista, .NET 3.x
Thursday, March 13, 2008
csUnit Sources About To Be Moved to Subversion
Visual Studio: "Unable to find manifest signing certificate in the certificate store"
"Unable to find manifest signing certificate in the certificate store"As I was sure that I wasn't using any certificate to sign the assembly I couldn't understand the reason for this error message and the integrated help system for Visual Studio wasn't a big help either. It turned out that I had to manually go into the *.csproj file and remove the following three lines that were apparently left over from some past experiments with signing using a certificate:
<manifestcertificatethumbprint>...</manifestcertificatethumbprint> <manifestkeyfile>...</manifestkeyfile> <generatemanifests>...</generatemanifests> <signmanifests>...</signmanifests>After I had removed those lines I reloaded the project and the solution rebuilt just fine. There is more information on this subject at a Microsoft Forum.
Wednesday, January 30, 2008
const == static?
Friday, January 11, 2008
csUnit in 2008
Thursday, June 14, 2007
An attempt to attach an auto-named database for file *.mdf failed
I got an exception in line 3 along the lines1: using(SqlConnection conn = new SqlConnection(connectionString)) { 2: try { 3: conn.Open(); 4: } 5: catch(Exception ex) { 6: } 7:}
"An attempt to attach an auto-named database for file ###.mdf failed ..."(note that ### is a place holder for the actual filename). I solved it by using information from MSDN, and the working connection string looked as follows:
Data Source = .\SQLEXPRESS; Integrated Security=true; User Instance=true; AttachDBFilename=DataDirectory\###.mdf; Initial Catalog=###;Again, ### is a replacement for the actual file name. Using this connection string I can now access the database file in a user instance of SQL Server 2005 Express. Some additional comments:
- The user instance is separate from any SQL Server 2005 Express instance that may be running on the system as well. However, unless you haven't changed any permissions or default settings, even a user without administrative rights can run a program and access a user instance.
- Do not attach the database file at the same time with SQL Server Management Studio Express as you can't attach the same database file to twice to two different SQL Server (Express) instances.
- Always make sure you close the database connection. In the above code this is achived with the using statement as regardless how that block of code is left (exception or normal program flow) the Dispose() method will be called. This will always close the connection, and you have avoided a connection leak.
- If you use a connection string in you application, use the same one for all connections to the same database. If you use different connection strings, e.g. change the order of the parameters in them, these will be considered to be different and a connection pool for each will be created. The connection strings must be the same, every single character.
For more info please also see the link attached to this post. If you can't find it, try the heading!
Tuesday, June 12, 2007
Windows-Safari
Could not open a connection to SQL Server
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Wednesday, April 11, 2007
"Generating user instances in SQL Server is disabled. Use sp_configure 'user instances enabled' to generate user instances."
Tuesday, April 10, 2007
C# Grammar
Thursday, April 05, 2007
FormatException thrown by Convert.ChangeType Method
- InvalidCastException
- ArgumentNullException
Unfortunately, this list is not complete. When you try to convert the string "oops" to int32, this method throws a System.FormatException with the message "Input string was not in a correct format."
In this regard the online documentation for .NET 2.0 is incorrect. The behavior might be the same for .NET 3.0. I didn't verify the latter.
Tuesday, April 03, 2007
What's next for csUnit?
Saturday, March 31, 2007
csUnit 2.1.2 Released
- Performance: Reduced overhead by approximately 50%
- Usability: Simplified setup, and also the user interface
- Features: Support for multiple categories, and we also added a Timeout parameter to the TestAttribute
It was very exciting to introduce new concepts to the design of the application, e.g. selectors. The code has improved in various ways, and it is amazing to see how more functionality can be provided with a seemingly similar sized codebase.
In particular I would like to thank Jake Anderson, Piers Lawson, and Markus Rentschler for their contributions and support. Also I'd like to thank our sponsors from Agile Utilities and JetBrains. And last but not least I'd like to thank all the users of csUnit who provided us with extremely valuable feedback, and also helped out with experiments to solve bugs. Thank you to all of you! It is a pleaseure to work with you!
Our next release is planned for June 2007. We have quite a few very good suggestions for additional exciting features, and we are looking forward to make them happen!