I'd like to share my top ten list of MSDN articles which have been published 2006. What follows is a completely subjective top-10 and ofcourse I can only take those articles into consideration which I have read.
Customizing generated Web Service proxies in Visual Studio 2005
Deliver The Power Of Spy++ To Windows Forms With Our New Tool
Improving Application Startup Time
Base Class Library Performance Tips and Tricks
Take Exception To Critical Errors With Custom Application Blocks
The Performance Benefits of NGen
All About Enums
What's new in System.Xml 2.0
Parameterized ThreadStart, EventWaitHandle, and More
Create A Simple Mutation Testing System With The .NET Framework
I just installed a VPC running Windows 2003 Server.
Virtual PC is emulating a Soundblaster 16 but Windows 2003 does not provide any drivers.
Thus to get sound working (either for playback or recording) you need to manually install the appropriate drivers.
The two driver files you need are wdma_ctl.inf and ctlsb16.sys.
Windows XP is having those two files. To get them do the following:
From a command prompt:
expand "%windir%\driver cache\i386\driver.cab" -F:ctlsb16.sys c:\
This will extract the ctlsb16.sys to your root c:\
The wdma_ctl.inf is located at C:\WINDOWS\inf
Now copy those two files over to the Virtual PC and point to the appropriate location during installation of the soundcard.
Oh yes, the following took me a while to find out ;)
The WSE-enabled proxy class is not thread-safe. When the proxy class is used to make multiple asynchronous calls to a Web service method, each call must be completed using the EndXX method before another call may be made.
WSE proxies contain state that is used for each method call. This
is the RequestSoapContext and ResponseSoapContext. Making 2 or more
concurrent calls from different threads means that each of those threads
will be attempting to access this state and this may produce conflicts.
Therefore you are not able to have overlapping asynchronous calls from a single proxy. If you want to have multiple async calls from the same client, you need to have separate proxies for each request.
Lately the Visual Studio 2005 Designer drives me crazy.
When I worked with multiple Forms and Custom User Controls, it took just a while and I could not open the Design View anymore.
Switching to the Design view, brought up a friendly error message:
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information
First hit at google brings you to Microsoft support, where you can order an hotfix to correct this problem. The hotfix patches the Microsoft.visualstudio.design.dll.
If you look for other workarounds most people suggest restarting Visual Studio or Clean & Rebuild your solution with all Forms closed.
However, I found one interesting piece of information over at Rupreet’s Weblog:
I believe the problem is caused by the Indexing Service locking the obj and bin files, trying to reindex their contents. Simply select your Projects folder in Explorer, go to Properties..., click the Advanced button and disable the checkbox to allow the indexing of the folder and subdirectories and files
Let’s see if this is actually true. It would be great.
Does anyone has ordered and applied the hotfix yet? Or any other experience how to handle this annoyance ?
Are Team System and Team Suite the same thing?
No, they are not. Let me explain the difference between Team System and Team Suite.
As you might know, a level above the Visual Studio 2005 Professional Version, you find the Visual Studio Team Editions.
Each Team Edition offers special features, which Microsoft assumes useful, for the specific roles they identified in software development.
Team Edition for Software Architects provides tools for visually constructing solutions that are designed from the onset for the environments in which they will be used allowing teams to develop and deploy applications faster and more effectively. The modeling framework allows architects to visualize prescribed architectures and network infrastructures.
Team Edition for Software Developers provides advanced development tools that enable teams to incorporate quality, early and often throughout the life cycle. Performance analysis tools measure, evaluate, and target performance-related issues in code, helping identify performance bottle-necks early on.
Team Edition for Software Testers introduces a set of test tools that are integrated into the Visual Studio environment that help you build high quality applications. The test management tools allow testers to author, execute, and manage tests and related work items all from within Visual Studio
So now Team Suite simply is the unification of all those 3 products. Simply speaking if you install Team Suite you have access to all the features from with the IDE.
The Visual Team Sytem Edition does include the Team Suite but has to offer two more products:
The Team Foundation Server is what powers the collaboration aspects of the Visual Studio Team System. When used in conjunction with Visual Studio Team System, Team Foundation Server enable you to effortlessly manage and track the progress and health of your projects.
Some great features of Team Foundation Server are
-
Version Control
-
Work Item Tracking
-
Reporting
-
Build
-
Team Communication
The Team Test Load Agent generates supplemental test load for use with Visual Studio 2005 Team Edition for Software Testers that enables organizations to simulate more users and more accurately test the performance of Web applications and servers
To summarize the above: With Team Suite you install all the roles you find in a software development cycle. With Team System, especially with Team Foundation Server you will connect all those roles and enhance how they work together.
If you are developing ASP.NET you can easily use the Application_Error event within the Global.asax Syntax file for your global exception handling needs.
However, this approach is not available for Web Services applications. The Application_Error event is not fired if your web method throws an exception. The reason for this is that the HTTP handler for XML Web services consumes any exception that occurs while an XML Web service is executing and turns it into a SOAP fault prior to the Application_Error
event is called.
To achieve global exception handling you have to build a SOAP extension. The SOAP extension can check for the existence of an exception in the ProcessMessage method.
public class SoapExceptionHandler : System.Web.Services.Protocols.SoapExtension
{
public override void ProcessMessage(System.Web.Services.Protocols.SoapMessage message)
{
if (message.Stage == SoapMessageStage.AfterSerialize)
{
if (message.Exception != null)
{
Logger.Write(message.Exception.InnerException);
}
}
}
public override object GetInitializer(Type serviceType)
{
return null;
}
public override object GetInitializer(LogicalMethodInfo methodInfo,
SoapExtensionAttribute attribute)
{
return null;
}
public override void Initialize(object initializer){ }
}
Obviously, you can do a lot more than just log the Exception.
A common approch is to add or remove information to the SoapFault Message to control what data is send over to the client. However, you should override ChainStream if you plan to do so. There is a good posting called Inside Of Chain Stream. The ChainStream methods allows your SOAP extension to access to the memory buffer containing the SOAP response.
Another good article over at haacked.com deals with excpetion injection using custom soap extensions or take a look at Jan Tielens Throwing SoapExceptions article.
Once you have your custom soap extension you can either register it in your web.config via the <soapExtensionTypes> tag or you create an SoapExtensionAttribute to get more fine grained control about the execution of the SoapExtension.
The Attribute would look like this:
[AttributeUsage(AttributeTargets.Method)]
public class ExceptionHandlingAttribute : SoapExtensionAttribute
{
public override Type ExtensionType{get { return typeof(SoapExceptionHandler); }}
public override int Priority{get{return 0;}set{}}
}
You can apply this attribute to your XML Web service methods and thus enable your newly created SoapExtension.
[WebMethod]
[ExceptionHandling]
public void Foo(){}
Managing and reducing the complexity of your software is important. Complexity makes your software more error prone and harder to maintain.
I believe in this tenet and I am a disciple of the KISS (Keep it Simple, Stupid aka Keep it super simple) principle.
However, the obvious question at hand is: How to measure complexity and thus identify where the KISS principle is violated ?
One popular method to identify complexity is to calculate the Cyclomatic Complexity (CC).
Before talking about the tools that can help to calculate the cyclomatic complexity let me briefly explain the basics around this method.
This metric was developed by Thomas McCabe. He analyzed thousand of software projects and concluded that the reliability and stability of a program is strongly correlated to its control flow complexity.
He introduced the following formula:
M = E - N + P
M = cyclomatic complexity
E = the number of edges of the graph
N = the number of nodes of the graph
P = the number of connected components.
His paper describing this method in detail was published 1976. During that time flowcharts where pretty popular, obviously you don’t make much use of them today anymore.
A more proper way for current projects is to calculate the cyclomatic complexity using the subsequent approach:
For each occurrence of the following keywords or symbols you add one point:
if, while, for, and (&&), or ( ||) , switch
Depending on your language syntax those keywords and symbols may vary.
More generally speaking, the following statements increase the complexity by one level:
- conditional statement
- looping statement
- for each logical operator used in a condition
- for each case in case or switch statement
If you counted all statements add one extra point and you have your cyclomatic complexity score.
Here is a simply example:
public void ShowNavbar()
{
IWorkspace workspace =Workspaces[WorkspaceNames.LeftWorkspace];
if (_Navbar != null)
{
Items.Remove(_Navbar);
}
_Navbar = Items.AddNew<NavbarView>();
workspace.Show(_Navbar);
}
This method has one if statement, so one point. Add the extra point and you get 2 as cc score.
Let’s take a look at a few tools that do analyze your code and provide the cyclomatic complexity score.
Needless to say, cyclomatic complexity is only one metric those tools offer. The other metrics (e.g Lines Of Code (LOC), perentage of comments, etc…) are equally useful and you get most out of the tools if you identify those metrics most valuable for you.
SourceMonitor from Campwood Software
One of my favorite tools to collect metrics for a software project is called SourceMonitor from Campwood Software.
As you can see from this screenshot SourceMonitor neatly display statistics about your projects including the cyclomatic complexity.
Another great feature I love is the possibility to produce kiviat charts.
Those charts do provide an easy way of viewing your projects metrics. Shown below as an example of an Kiviat chart from my current project:
With the help of the Kiviat diagram you can easily tell how well your source code meets quality guidelines for a group of metrics. You will be able to select which metrics are included in the diagram as well as the upper and lower values that should be used to define quality for each metric.
Reflector Code Metrics Addin
Another tool which is great for codemetrics is a Reflector Addin developed by Jonathan de Halleux.
You can download it via projectdistributor.net
The outstanding feature is the ability to write your own metrics without recompiling the PlugIn.
You find an easy to follow explanation how to write your own metric here.
Other tools
Personally I have only used SourceMonitor and the reflector addin for calculating metrics. However, when talking about this posting with co-workers and friends they pointed me to some other good free products.
I list them here, so you can check them out. If you know about any others drop a comment please !
VIL
vil provides metrics, visualization, querying, and analysis of .NET assemblies, classes, and methods for all .NET languages, including C# and Visual Basic.NET
NDepend
NDepend
NDepend analyses .NET assemblies of an application and generates design quality metrics. NDepend allows you to automatically measure the quality of a design in terms of its extensibility, reusability and maintainability to effectively manage and control the assemblies’ dependencies of your .NET applications. Moreover, NDepend helps you to get a thorough view of the topology of your application, at component at type and at member level.
Let’s assume you have all (most) of the framework versions installed on your machine.
How can you determine which application uses which framework version ?
Reminder: There is plenty of information about how to determine which framework version is installed.
The question at hand, is about which framework version does an application actually use !
Microsoft published an kb about : How to determine which versions of the .NET Framework are installed and whether service packs have been applied
For your information, here is a full list of version numbers:
However, most people just differentiate between v. 1.0/1.1 (what they mean is 1.1.4322.2032) and v 2.0 (which is 2.0.50727.42).
Now back to the original question. How can you determine what framework version an application uses ?
There is an tool called clrver.exe which is shipped with the SDK for .Net 2.0 , you can find the tool under C:\Programme\Microsoft Visual Studio 8\SDK\v2.0\Bin
If you use the clrver.exe tool without arguments you get the following output:
C:\Programme\Microsoft Visual Studio 8\VC>clrver.exe
Versions installed on the machine:
v2.0.50727
You can use all / <pid> argument to get more detailed information.
-all - Displays all processes on the machine using the CLR.
<PID> - Displays the version of the CLR used by the specified process.
Thus you can get detail information about the running processes.
3920 devenv.exe v2.0.50727
2084 WebDev.WebServer.EXE v2.0.50727
2944 Obab.UI.ProfessorenClientCab.vshost.exe v2.0.50727
Unfortunatley, you can only get the information from running applications. There is no way to let clrver.exe determine the required/used framework version from the application file itself.
Over at Devfish , you find an interesting arcticle about the above topic and what is more important, you can even download a simple tool to determine the version information directly from a file.You pass that tool a filename and it outputs the Version information and what version of the CLR runtime the file requires. The source code for that tool can be found here.
I wonder why clrver.exe does not supply this functionality out-of-the-box ?
If you add a new item to your project, Visual Studio applies a default template which is responsible for creating the sceleton of the selected item.
It might come in handy to modify the default "create new item" behaviour and customize it so it fits your individual needs. The process to do so is pretty straightforward. All templates are stored in a folder called ItemTemplateCache. If you e.g. want to modify the default template for "Add new class" you need to modify the Class.cs which is located: C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ItemTemplatesCache\CSharp\1033\Class.cs
You don’t have to worry about messing things up, you can always restore the item templates with the devenv /installvstemplates command. It copies the item from zip files located at
C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ItemTemplates\CSharp\1033\Class.zip.
You can ofcourse make more permanent changes, by modify the content of the zip file itself.
One nice features in VS 2005 is that the Document Outline Window is available for Windows Forms. In Visual Studio 2003 it was only available for Web Forms.
You open the the Document Outline either via View | Other Windows | Document Outline or with the Ctrl+W,U keyboard shortcut.
The cool thing about the Document Outline Window is the ability to list all controls in a nested tree like view. Thus arranging and modifing controls is getting much easier.
You can quickly rename a specific control or edit its properties via the context menu.
I start most of my application using start - run. This a very convenient shortcut for running applications.
Sometimes your favorite application does not start via "start - run" or you might want to modify an existing shortcut.
Technically when you use the run dialog windows is executing the ShellExecute command.
When the method is executing there are several places that it can look in an attempt to find the file it should execute.
Those places are:
The Windows directory (no subdirectories are searched) The Windows\System32 directory Directories listed in the PATH environment variable The App Paths registry key Applications are encouraged to use the App Paths key to provide an application-specific path rather than adding to the global system path.
If you start regedit look at the following hive key:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths\app.exe
You can adjust everthing to your needs here.
C# 2.0 offers a new null coalescing operator: ?? You can look it up in C# Language Specification (12.3.3.29).
The ?? Operator “take the first value if it is not null, otherwise the second.”
I consider this a pretty smart way to do some null comparision where you would usually use an if==null construct.
Here is a quick example:
string user = “Hannes”;
Foo.bar = user ?? “unkown”;
This will set Foo.Bar to “Hannes”.
int? x = null;
int? y = 2;
int result = x ?? y;
This will set result to 2;
The operator works on nullable value types and on reference types.
I assume if you like the tenary operator you will love the new null coalescing operator.
The following three lines are logically identically:
if (s != null){ConsoleWriteLine(s);}else{ConsoleWriteLine("null");}
Console.WriteLine(s == null ? s : "null");
Console.WriteLine(s ?? "null");
Nice isn't it?
If you are developing with Visual Studio 2005 you probably have seen the *.vshost.exe files inside of your bin folder or you saw the process running while debugging. The vshost.exe file is coming from Visual Studio and serves a very good purpose. The vshost.exe is a new Visual Studio 2005 feature and is actually a hosting process.
It serves mainly three purposes:
- Improve Performance
The hosting process improves performance by handling creation of the AppDomain and initalization of the debugger. - Allow partial trust debugging
Simulating a partial trust environment within Visual Studio requires special setup of the AppDomain. Vhost.exe takes care of this. - Allow design time expression evaluation.
Supports the Immediate Window.
The *.vshost.exe files are exclusively used by the VS 2005 IDE, they serve no other purpose.
If you want to disable the generation of the vshost files you can do so under your projects settings.
In general, when the hosting process is disabled the time needed to begin debugging increases.
As you probably know shared assemblies are stored in the global assembly cache (GAC) which is located at c:\windows\assembly.If you navigate to this folder you might be surprised to see that is looks a lil different then you might expect.
What you actually see in the windows explorer is an aggregated view of different folders. Open up a dos prompt and navigate to c:\windows\assembly
Technically a shell namespace extension is used to achive this. With the help of a shell namespace extensions you can create some custom functionality for Windows Explorer. One common use is to enable Explorer to present a list of items that do not exist in one real folder, but actually reside in a number of places. The view on the folder makes it look like these items are in one place, so managing them becomes easier.
The shfusion.dll is used to provide the user interface you see in explorer. If you disable the namespace extensions explorer is using the default extension to display the content of the gac.
Three ways to disable the namespace extension:
1. Rename the Desktop.ini
What you can’t see from the screenshot above is that there is a hidden file called Desktop.ini which is invoking the namespace extension.
You could rename the file with the following commands:
attrib desktop.ini -h -r -s
rename desktop.ini desktop.ini.bak
2. Add DisableCacheViewer Registry Key
Another way to disable to create a new dword key under HKLM\Software\Microsoft\Fusion\ with the nane DisableCacheViewer and set it’s [DWORD] value to 1.
3. Rename the Shfusion.dll
Last but not least you could rename the Shfusion.dll which is located in the %windir%\Microsoft.NET\Framework\vx.x.xxxx folder, where xxxx is the build number of the .NET Framework you are using.
Plain old explorer view
If you open windows explorer after one of the above procedures you will see your familiar folder structure.
Once you disabled the namespace extension you no longer have drag and drop support for installing assemblies to the gac. Thus you probably want to re-enable the namespace extension once you have looked around.
One thing I love most about Maxthon is the integrated capability to handle mouse gestures. Mouse gestures are simple symbols that you "draw" on your screen using your mouse. When you perform a mouse gesture that can be recognised, the according associated action will be performed.
Once you get used to mouse gestures, you find yourself trying to use them everywhere even if the application does not support them. It is pretty addictive.
The missing mouse gesture recognization was the first thing that struck me when using the new beta of IE7.
A quick search revealed a nifty little tool called StrokeIt.
With the help of StrokeIt you can define mouse gestures for every application.
I added another stroke command since I like to search for highlighted text with a simple mouse gesture.
The command is nothing more than a combination of keyboard shortcuts.
I have to admit that that this solution is far from perfect. Thus if anyone has better solution please drop a comment !
StrokeIt is free for individual and not-for-profit charitable entity use.
If you are missing mouse gestures in IE7 or in general give StrokeIt a try.