Quinn Quisling
Quinn Quisling

Reputation: 9

"using System.Windows.Media" not recognized even though PresentationCore.dll is Referenced

I running Windows XP Service Pack 3. Visual Studio 2010. C# project.

I included a "Using System.Windows.Media" and "Using System.Windows.Media.Imaging" in a Class Project. I also Added the PresentationCore.dll Reference. This was done at the Solution Window.

The so-called "Intellisense" is red-lining all of the functions that come from those namespaces. Nothing I do fixes it. Why doesn't the compiler recognize the PresentationCore reference?????

I need a solution to this problem FAST.

Thank you to anyone who is kind enough to help me.

using System.Windows
using System.IO;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace TextEditor
{
    public partial class App : Application
    {
        AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionOccurred;
    }

    private static void UnhandledExceptionOccurred(object sender, UnhandledExceptionEventArgs e)
    {
        Window win = Current.MainWindow;

        RenderTargetBitmap bmp = new RenderTargetBitmap((int) win.Width, (int) win.Height, 96, 96, PixelFormats.Pbgra32);

        bmp.Render(win);

        string errorPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ErrorReports");

        if(!Directory.Exists(errorPath))
            Directory.CreateDirectory(errorPath);

        BitmapEncoder encoder = new PngBitmapEncoder();
        encoder.Frames.Add(BitmapFrame.Create(bmp));

        string filePath = Path.Combine(errorPath, string.Format("{0:MMddyyyyhhmmss}.png", DateTime.Now));

        using(Stream stream = File.Create(filePath))
        {
             encoder.Save(stream);
        }

    }
}

Upvotes: 0

Views: 3258

Answers (1)

Kath
Kath

Reputation: 1854

Firstly, you cannot put method separately from the class even if the method is static. Try to do something like that:

    namespace TestProject
    {
        public partial class App : Application
        {
            public void Init()
            {
                AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionOccurred;
            }

        private static void UnhandledExceptionOccurred(object sender, UnhandledExceptionEventArgs e)
        {
            Window win = Current.MainWindow;

            RenderTargetBitmap bmp = new RenderTargetBitmap((int)win.Width, (int)win.Height, 96, 96, PixelFormats.Pbgra32);

            bmp.Render(win);

            string errorPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ErrorReports");

            if (!Directory.Exists(errorPath))
                Directory.CreateDirectory(errorPath);

            BitmapEncoder encoder = new PngBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(bmp));

            string filePath = Path.Combine(errorPath, string.Format("{0:MMddyyyyhhmmss}.png", DateTime.Now));

            using (Stream stream = File.Create(filePath))
            {
                encoder.Save(stream);
            }
        }
    }
}

Upvotes: 1

Related Questions