Archive

Archive for the ‘.NET’ Category

No color coding for Classic ASP in Visual Studio 2008

December 31st, 2007 1 comment

This seems to be a bummer. Color coding and intellisense for VBScript code in Classic ASP pages have been deprecated in VS 2008.

There is a workaround for making it work for files with the .vbs extension but no solution for .asp pages. Hopefully someone would come up with a hack to get it working again.

Until then Microsoft’s answer is for us to use VS 2005 or Visual Web Developer 2005. But don’t install VWD if you already have VS 2008 installed since VWD will take over all file associations leaving 2008 broken.

You can let Microsoft know how much this sucks by ranting here: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=290845

Categories: .NET Tags:

Moq: Linq to Mock

December 19th, 2007 No comments

Daniel Cazzulino just announced the birth of Moq, now this is mocking done right.

 

// ShouldExpectCallWithArgument
var mock = new Mock<IFoo>();

mock.Expect(x => x.DoInt(1)).Returns(11);
mock
.Expect(x => x.DoInt(2)).Returns(22);

Assert.AreEqual(11, mock.Instance.DoInt(1));
Assert.AreEqual(22, mock.Instance.DoInt(2));

 

Lambda is starting to make my mouth water.

Categories: .NET Tags:

The Dangers of Static Events In User Controls

December 18th, 2007 No comments

Static events in user controls can lead to all sorts of weird behavior in your application. Especially when they are hosted in forms that are loaded and unloaded during the lifetime of your application.

public partial class FlexiAddress : UserControl
{
    public static event EventHandler<AddressChangedEventArgs> EventAddressChanged;

The danger here is that unless you unhook from the static event before your form closes what happens is that although the form is not visible it still hangs around in memory until your application exits.

So if you are showing the form by creating a new instance, every form that is created is loaded into memory and will actually cause a memory leak.

If you want to prove this to yourself the easiest way is to include a Debug.WriteLine in the even handler and then after you’ve opened and closed the hosting form a couple of times try to do an action that causes the event to be fired. You’ll notice that the Output window has one line for each instance of the form that is loaded in memory.

The solution, is to remove the hook to the event handler, the Form_Closing event is probably a good place to include this.

AddressControl.EventAddressChanged -= AddressControl_EventAddressChanged;

The better solution though is to avoid using static events.

Categories: .NET Tags:

VSTS – Multiple tests with ID <guid> found

December 18th, 2007 3 comments

When you trying to run your tests and you come across this error message “Multiple tests with ID <guid> found”, simply hit the Refresh button on the Test Manager window and you should be all set.

Categories: .NET Tags:

Debugging SQL Server 2005 Stored Procedures in Visual Studio

May 23rd, 2007 No comments

I used to use the debug feature in Query Analyzer when working with SQL Server 2000 quite a lot. There were a number of time when I did want to do this in SQL Server 2005 but couldn’t quite figure it out. I looked high and low on SQL Server Management Studio to no avail.

The reason? Debugging was moved out of SQL Server Management Studio and into Visual Studio.

Debug SQL Server Stored Procedure

Read all about it in this article by Scott Mitchell.

Categories: .NET, Tips Tags:

Code Profiling

May 23rd, 2007 No comments

Until yesterday, if anyone asked me about dynamic code profiling, I would have said that the only way to do it is to buy the Red Gate ANTS Profiler or the Jet Brains dotTrace Profiler.

Little did I know that I already had an excellent profiling tool installed right there on my machine for the last couple of years!

So what am I talking about. It’s the small menu option that you see under Tools called Performance. Aha so that’s why I never knew about this all along. The VSTS most probably wanted this to be an easter egg!

No worries though Orcas is going to fix this by renaming it to Profiler and moving it under the new Developer menu.

No wonder that this rarely shows up on Live Search or Google. The keyword profiler is nowhere to be found even in the overview page of this feature on MSDN.

So what can you do with the profiler today? Well you can use it to make your .NET applications super-duper fast. You’ll find out things like which method gets called the most and which method takes most of the time to execute and a whole number of other things.

Categories: .NET Tags:

A new direction?

February 27th, 2007 No comments

Will Don and ChrisAn talk about this? ChrisAn was in the WPF team…

Categories: .NET, Microsoft Tags:

Guidance Explorer goes online

September 27th, 2006 No comments

Wohoo. Guidance Explorer has gone online at http://www.guidancelibrary.com/GuidanceExplorerBeta/. This is the first smart client that I’m happy has turned into a website. I can now always get the latest stuff by browsing to this page instead of going through the hassle of downloading the latest client and guidance.

Now, if only I could sign in to the system and create my own custom views…

Congrats to the Guidance Explorer team!

Categories: .NET Tags:

XslCompiledTransform Performance

August 24th, 2006 No comments

Have you’ve ever written any code on .NET that does XSL transformations? Here’s another strong reason why you might think of making the jump to .NET 2.0 and start taking advantage of the .NET 2.0’s XslCompiledTransform class.

Anton Lapounov does a comparison of the major XSL transformers out there and the results are eye opening.

XslCompiledTransform

If you’ve tried building any of your pre 2.0 applications in Visual Studio 2005, you would have already seen the warning which keeps pushing you to use the XslCompiledTransform class.

The major jump in performance is due to the fact that we’re now using an XSL compiler as opposed to the rest which are all interpreters.

Categories: .NET Tags:

Automatic Brace Matching

June 6th, 2006 1 comment

The Visual Studio shortcut of the day is CTRL+] which allows you to jump between two matching braces. The name is somewhat misleading since brace matching works not just for braces but also includes parentheses and all other pair statements like #region#endregion, #if and so on.


All you have to do is move the cursor to either the left or right of a brace and press CTRL+] to toggle moving between the two ends in the code editor.



A word of warning to Visual Basic users, you guys don’t uses braces so you don’t get the Automatic Brace Matching feature. Ouch.

Categories: .NET Tags: