简体   繁体   中英

Can't use System.Windows.Application

I was trying to add System.Windows.Application to my c# project and will gives me an error. please help me to figure it out.

 using System;
 using System.ComponentModel.Composition;
 using System.Threading;
 using System.Windows.Forms;
 **using Application = System.Windows.Application;**

 namespace DIPS.DocumentPublish.Admin.Helpers{
    public class DocumentPublishClientAdminNotificationService{
       public void Invoke(Action action)
       {
           if (action == null)
           {
               return;
           }

           if (IsInvokeRequired())
           {
               if (Application.Current?.Dispatcher != null)
               {
                   Application.Current?.Dispatcher?.Invoke(action);
                   return;
               }
           }
           action();
       }
    }
 }

error is The type or namespace name 'Application does not exist in the namespace 'System.Windows'(Are you missing an assembly reference?) cannot resolve 'Application'

You need to add a PresentationFramework reference in the project:

在此处输入图像描述

Feel free to let me know if the problem persists.

You can't use Application as the alias name, because it conflicts with the static class in the System namespace. Either use a different name ( App , etc) or remove the using statement for System.

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