简体   繁体   中英

c# Error Message - Type Or namespace definition or end of file expected

All, I am writing ac# script where I want to check if a windows pop-up titled "Script Error" is visible and return True or False. To do this I have had to use static extern which I believe I am using incorrectly but not sure how to correct.

Please can someone advise how to resolve the error I am seeing:

Error Message - Type Or namespace definition or end of file expected

**Please note the parenthesis which are causing the issue I have labelled Error Parethesis however I am not entirely sure these are causing the overall issue.

Please see full code below:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Xml;

namespace Dynamic.Script_8D737880D773F26
{ **Error Parathesis
   // Script generated by Pega Robotics Studio 8.0.2032.0
   // Please use caution when modifying class name, namespace or attributes
  [OpenSpan.TypeManagement.DynamicTypeAttribute()]
  [OpenSpan.Design.ComponentIdentityAttribute("Script-8D737880D773F26")]
  public sealed class Script
  {
    [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
    static extern IntPtr FindWindowByCaption(IntPtr zeroOnly, string lpWindowName);
  }
  {
    public bool ScriptErrorVisible()
    {
      if (FindWindowByCaption(IntPtr.Zero, "Script Error") != IntPtr.Zero)
      {
         return true;
      }
      else
      {
        return false;
      }
    }
   }
} **Error Parenthesis

It looks like you had a couple of hanging brackets. Try this.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Xml;

namespace Dynamic.Script_8D737880D773F26
{
    // Script generated by Pega Robotics Studio 8.0.2032.0
    // Please use caution when modifying class name, namespace or attributes
    [OpenSpan.TypeManagement.DynamicTypeAttribute()]
    [OpenSpan.Design.ComponentIdentityAttribute("Script-8D737880D773F26")]
    public sealed class Script
    {
        [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
        static extern IntPtr FindWindowByCaption(IntPtr zeroOnly, string lpWindowName);

        public bool ScriptErrorVisible()
        {
            if (FindWindowByCaption(IntPtr.Zero, "Script Error") != IntPtr.Zero)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

    } 
}

As the others have said, a good place to start would be to indent properly. To actually explain your issue rather than just post the answer, see the below explanation:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Xml;

namespace Dynamic.Script_8D737880D773F26
{
    // Script generated by Pega Robotics Studio 8.0.2032.0
    // Please use caution when modifying class name, namespace or attributes
    [OpenSpan.TypeManagement.DynamicTypeAttribute()]
    [OpenSpan.Design.ComponentIdentityAttribute("Script-8D737880D773F26")]
    public sealed class Script
    {
        [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
        static extern IntPtr FindWindowByCaption(IntPtr zeroOnly, string lpWindowName);
    } // << Your class ends here

    { // << Opened brackets without declaring a class
        public bool ScriptErrorVisible()
        {
            if (FindWindowByCaption(IntPtr.Zero, "Script Error") != IntPtr.Zero)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    } // << This would close the class, but you haven't declared one
} // << This ends the namespace

So this is the answer:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Xml;

namespace Dynamic.Script_8D737880D773F26
{
    // Script generated by Pega Robotics Studio 8.0.2032.0
    // Please use caution when modifying class name, namespace or attributes
    [OpenSpan.TypeManagement.DynamicTypeAttribute()]
    [OpenSpan.Design.ComponentIdentityAttribute("Script-8D737880D773F26")]
    public sealed class Script
    {
        [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
        static extern IntPtr FindWindowByCaption(IntPtr zeroOnly, string lpWindowName);

        public bool ScriptErrorVisible()
        {
            if (FindWindowByCaption(IntPtr.Zero, "Script Error") != IntPtr.Zero)
            {
                return true;
            }
            else
            {
                return false;
            }
        } // << Closes the ScriptErrorVisible method
    } // << Closes the Script class
} // << Closes the Dynamic.Script_8D737880D773F26 namespace

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