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

1 Comment »

  1. thanks

    Comment by Anonymous — May 30, 2013 @ 2:01 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: