a developer's notes – a semi-technical web development BLOG

September 14, 2011

Ambiguous Reference Between Two NameSpaces

Filed under: ASP.NET,C# — Duy Nguyen @ 11:25 pm
Tags: , , , , , , ,

If you get an ambiguous reference error when using two different namespaces that contain the same object, you will need to use a type alias.

For example: Say you want to use the System.Drawing.Image type in your ASP.NET project. So you decide to add the System.Drawing namespace like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

You will get an ambiguous reference if you have that namespace along with the System.Web.UI.WebControls namespace.

Why? Because both namespaces contain an “Image” object.

Resolution: Use a type alias. In your using statement write using Image = System.Drawing.Image;.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Image = System.Drawing.Image;

Now when you hover over your Image type, you will see that you are now referencing the Image from System.Drawing.Image.

Advertisements

Navigating in Visual Studio

Filed under: General Tips — Duy Nguyen @ 9:30 am
Tags: , , , , , , , , , ,

Have you ever jump around from code to code only to find yourself not knowing what class file you were at or what method you were navigating from? I get lost all the time when I am digging around in code.

I used to use bookmarks to place where I want to remember. They are great but what if you forgot to create one? Is there a “Back” button like you have on your windows browser?

In Visual Studio there is! Check out the Navigate Backwards and Navigate Forwards button!

You can simply click backwards to see where your last mouse cursor was. I usually hit F12 on a method or class to see its definition. And sometimes I find myself down a rabbit hold. Just click on the Navigate backwards to get back where you were!

If they are missing, customize the Standard toolbar. The Navigate Forward and Navigate Backwards is on the “View” Category.

Create a free website or blog at WordPress.com.