CS0104: 'Image' is an ambiguous reference between 'System.Web.UI.WebControls.Image' and 'System.Drawing.Image'


 CS0104: 'Image' is an ambiguous reference between 'System.Web.UI.WebControls.Image' and 'System.Drawing.Image'
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Drawing" %>
<%@Import Namespace="System.Drawing.Imaging" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script type="text/C#" runat="server">
void Page_Load() {
//The @ means "Ignore escape characters!" in the following string. It is a verbatim
//literal string - any backslashes (and newlines) in the string are not treated as
//escape characters or real line terminators.
//FileInfo f = new FileInfo( @"C:\Test.txt" );
//FileInfo f = new FileInfo("C:\\Test.txt");

string WorkingDirectory = @"C:\Test";
Image imgPhotoVert = Image.FromFile(WorkingDirectory + @"\JillandBen.jpg");
Image imgPhoto = null;
imgPhoto = FixedSize(imgPhotoVert, 300, 300);
imgPhoto.Save(WorkingDirectory + @"\newJIllandBen.jpg", ImageFormat.Jpeg);
imgPhoto.Dispose();
}

static System.Drawing.Image FixedSize(Image imgPhoto, int Width, int Height){   --ERROR PART
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destX = 0;
int destY = 0;




Ben
0
benny12345
3/24/2006 4:18:53 PM
📁 asp.net.getting-started
📃 91979 articles.
⭐ 4 followers.

💬 3 Replies
👁️‍🗨️ 6654 Views



The compiler doe snot know which base object to use to create an instance of your controls. This happens because one of your import statements called 'System.Drawing' that has an Image child object, just like 'System.Web.UI.WebControls' So use a fully qualified namespace reference.

Do you know the truth when you hear it?
0
hooligannes97
3/24/2006 4:48:01 PM

The error tells you exactly what is wrong, and leads you to the path to fix it, which is to tell the application what "Image" class to use, so
static System.Drawing.Image FixedSize(System.Drawing.Image imgPhoto, int Width, int Height){   --ERROR PART

"If you make it idiot proof, they'll build a better idiot"
0
MorningZ
3/24/2006 4:48:39 PM

prefix your Image references with the full namespace as the compiler has no way to know which Image type you mean.
you either want:
System.Web.UI.WebControls.Image
or
System.Drawing.Image
 

Mike Banavige
~~~~~~~~~~~~

Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
0
mbanavige
3/24/2006 4:48:54 PM
Reply: