Contents tagged with Tips
-
Debugging tips
James Avery has started a new series of articles on VisualStudioHacks.com named "Ask The Pros". The first issue was about Visual Studio add-ins, the second one is about Debugging. This is a great read. It gives a lot of tips to help you make the best of the debugging tools offered by Visual Studio.
-
Visual Studio 2005 on Windows XP without SP2
If you need to install Visual Studio 2005 on Windows XP without Service Pack 2, you can follow these instructions.
SP2 is not deployed at the client where I am at the moment, so Aaron's tips where useful. I'm sure it can help a lot of people in the corporate world.
-
HTML reformatting and Visual Studio: it's a feature!
This is a followup to my post on the automatic reformatting of HTML/ASPX that happens in VS 2005. You'll be happy to learn that although it looks like it, it's not a bug at all but a feature...
At first, when you witness automatic reformatting like this, it feels like something bad happens (again). But thanks to Barry Tang and Scott Guthrie from the ASP.NET team, I'll be able to explain you why this happens. Let me try to summarize the rationale behind this...
What was happening in my case was that <li> tags that I had on distinct lines were all of a sudden all on one line after me changing something in the Design view and switching back to the Source view.
For example, when I had something like this:
<ul>
<li>aaa</li>
<li>bbb</li>
</ul>
it could become something like this after adding a letter:
<ul>
<li>aaa z</li><li>bbb</li>
</ul>
The reason for this is that VS 2005 tries not to reformat your code, but it doesn’t want to change your page rendering as well. In this case, not reformatting the HTML source would change the rendering of the page in Internet Explorer (not in Firefox though). This is due to the importance of whitespaces in HTML.
In most cases, whitespaces are very important. Let's take another example. Let's say you have the following markup in source view:
<html>
<body>
<input />
<input />
</body>
</html>
If you go to Design view, you will see a whitespace between the two inputs. Now, try removing the whitespace between them and go back to Source view. In this case, if VS preserves the newline between the two inputs when we switch back to Source view, it will put the whitespace between the two inputs right back and that would just undo what you did in design view. That’s why whitespace rules take precedence over formatting.
Something that may be confusing though is the opposite case. If you have this in source:
<html>
<body>
<input /><input />
</body>
</html>
Then switch to design, then add a space between the two inputs, then switch back to source, what do you get?
<html>
<body>
<input />
<input />
</body>
</html>
Why is this happening? This is due to another rule: the default behavior for "empty" tags is to have a line-break before and a line-break after. You can see this or change it in "Tools | Text Editor | HTML | Format | Tag Specific Options".
When you know why it happens, there is no problem. But when you don't, which is highly probable when you first work with VS 2005, you have to admit that it's funny to see that when you expect to have your tags on separate lines you end up having them on one single line, and when you expect to have them on one single line, then end up on several lines!
I hope this explaination helps you to undertand why we can see some reformatting happen. I'm sure that for everyone who see this at work without this kind of explaination will think it a bug. But it's not, it's actually a useful feature. It's just that it's not an obvious one.
The thing you have to keep in mind is that ASP.NET and Visual Studio teams think that it is more important to preserve rendering. And I agree with them.
-
Ever tried Google AdSense to get some money from your sites?
Of course, everybody knows about Google AdSense, the program that allows to monetize your web sites...
Well, now they have a referral program, hence the picture you can see on this weblog's menu.
Until now, I've been very happy with AdSense on my own sites and on this weblog. If you plan to use AdSense yourself, feel free to click on my referral banners. That would be nice :-)
-
[HOWTO] Debug Javascript with IE or Firefox
In these ajaxian days, it is really useful to be able to debug javascript like any other piece of code. Luckily, there is support for this in the tools we use everyday: Internet Explorer, Firefox, Visual Studio.
You'll find help here:
-
Guidelines, a hidden feature for the Visual Studio editor
Sara Ford tells us how to use a hidden feature of the Visual Studio editor: visual guidelines.
These guidelines are visible column indicators for the VS editor.
I tried it with Visual Studio 2003 and it works fine. Here is the value I use: RGB(255,200,200) 80
This helps you to keep your code lines within the 80-caracter wide limit.
-
ASP.NET hosting solution with gigabytes of disk space!
If you've been reading this weblog for some time, you may remember that I wrote about a web hosting solution with ASP.NET support. This is just a note to let you know that they now propose from 1000MB to 3000MB of disk space and from 2000MB to 3000MB of SQL Server space for the same price!
They also recently upgraded their mail system (POP and IMAP) with features like SSL, SPAM protection, virus protection, and more.
Ah, and they have ASP.NET 2.0 beta...
I definitely invite you to take a look at them.
-
Simulated multiple inheritance pattern for C#
David Esparza-Guerrero has a trick to simulate multiple inheritance in C#. This is not a perfect solution, but it's interesting to look at.
Too bad we can't use the same approach (using the implicit operator) to have classes implement interfaces by delegation just like Delphi does with the implements keyword. Compiler error CS0552 states that "You cannot create a user-defined conversion to or from an interface" :-( -
Windows Forms designer and DesignMode property issues
It's interesting to know how the Windows Forms designer in Visual Studio loads forms. Did you ever wonder how it is possible for you to design an instance of a form while the underlying class is not completed and compiled? Raghavendra Prabhu explains how it works.
One problem that remains unanswered is how to detect a form is in design mode, to avoid accessing to run-time resources. One would think the DesignMode property is the solution.
Let's consider the following constructor for example:
public MyClass()
{
if (!DesignMode)
{
_Connection = new DatabaseConnection("aceofbase");
_Connection.Open();
}
}
The small problem with the DesignMode property is that it is not always telling the full truth!
The DesignMode property isn't set to true in the constructor.
Remember, there's no real magic here.
Visual Studio .NET creates your object as it parses the InitializeComponent() method. Once the object is constructed, Visual Studio .NET keeps track of the objects it creates, and simply says: newlyCreatedObject.DesignMode = true
There is no definitive solution to this problem.
All kinds of workarounds are used.
- We could call GetService(typeof(IDesignerHost)) and see if it returns something.
- Other option: test System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime
- Some are comparing System.Diagnostics.Process.GetCurrentProcess().ProcessName to "devenv" to see if the form is hosted in Visual Studio. But I don't like this one because in many cases it won't work (like with VS add-ins).
-
Advanced debugging with SOS.dll
I've just discovered advanced debugging in Visual Studio using SOS.dll. It can be used to get information about the garbage collector, objects in memory, threads and locks, call stacks and more.
See how to use mixed-mode debugging and SOS.dll.
See also Using SOS in the SDK and this article from MSDN Magazine.