简体   繁体   中英

Why when I take this class into my project don't find some namespaces\classes?

I am pretty new in C# (I came from Java) and I have the following problem: I am developing a new web application based on an old version of the same web application and I have to reuse an old class that is present in the old version of this webapplication.

The problem is that when I take this class into my new version I have some errors.

This is my class:

//using ITAttitude.Commons.Helpers;
//using ITAttitude.Commons.Logger;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI.DataVisualization.Charting;

namespace PdfReport
{
    class ChartHelper
    {

        public static String GetPdfChart(int percentage)
        {
            if (percentage == 0)
            {
                return null;
            }

            int WIDTH = 130;
            int HEIGHT = 10;

            using (Bitmap bitmap = new Bitmap(WIDTH, HEIGHT))
            {
                using (Graphics graphics = Graphics.FromImage(bitmap))
                {
                    using (LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, WIDTH, HEIGHT), Color.LightGreen, Color.Red, LinearGradientMode.Horizontal))
                    {
                        graphics.FillRectangle(brush, new Rectangle(0, 0, WIDTH, HEIGHT));

                        using (Bitmap target = new Bitmap(WIDTH * percentage / 100, HEIGHT))
                        {
                            Rectangle cropped = new Rectangle(0, 0, WIDTH, HEIGHT);

                            using (Graphics g = Graphics.FromImage(target))
                            {
                                g.DrawImage(bitmap, new Rectangle(0, 0, cropped.Width, cropped.Height), cropped, GraphicsUnit.Pixel);
                                g.Save();

                                String filename = Path.GetTempFileName() + ".png";

                                target.Save(filename);

                                return filename;
                            }
                        }
                    }
                }
            }
        }

    }
}

And these are the obtained errors messages:

Error 77 The type or namespace name 'UI' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) C:\\Develop\\EarlyWarning\\public\\Implementazione\\Ver2\\PdfReport\\ChartHelper.cs 10 18 PdfReport Error 76 The type or namespace name 'Drawing2D' does not exist in the namespace 'System.Drawing' (are you missing an assembly reference?) C:\\Develop\\EarlyWarning\\public\\Implementazione\\Ver2\\PdfReport\\ChartHelper.cs 6 22 PdfReport Error 78 Metadata file 'C:\\Develop\\EarlyWarning\\public\\Implementazione\\Ver2\\PdfReport\\bin\\Debug\\PdfReport.dll' could not be found C:\\Develop\\EarlyWarning\\public\\Implementazione\\Ver2\\UnitTestProject\\CSC UnitTestProject

It seems to me as it don't find some reference or some others classes. Why? What can I do to solve this issue?

Tnx

Your project is missing references to System.Web ,System.Drawing and System.Web.DataVisualization`.

Right click on project references and click Add References, select System.Web , System.Drawing and System.Web.DataVisualization under Assemblies/Framework.

Right click on the References folder in the project and select add reference. Search for System.Web.DataVisualization and check that and select Ok. Try building it again, your error should go away.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM