小小辉少 2015-08-07 15:45 采纳率: 50%
浏览 2694
已采纳

无法显式调用运算符或访问器

困扰了好久了。c#反汇编回来的程序报了2个错误,
this.msc.add_Error(new DScriptControlSource_ErrorEventHandler(OnError));
this.msc.add_Timeout(new DScriptControlSource_TimeoutEventHandler(OnTimeout));

                    错误  1   “MSScriptControl.DScriptControlSource_Event.Error.add”: 无法显式调用运算符或访问器 

完整代码如下

   using MSScriptControl;
    using System;
    using System.Runtime.InteropServices;
    using System.Threading;

    public class ScriptEngine : IDisposable
    {
        public ScriptControl msc;

        public event RunErrorHandler RunError;

        public event RunTimeoutHandler RunTimeout;

        public ScriptEngine() : this(ScriptLanguage.VBscript)
        {
        }

        public ScriptEngine(ScriptLanguage language)
        {
            this.msc = new ScriptControlClass();
            this.msc.UseSafeSubset = true;
            this.msc.Language = language.ToString();
            this.msc.add_Error(new DScriptControlSource_ErrorEventHandler(OnError));
            this.msc.add_Timeout(new DScriptControlSource_TimeoutEventHandler(OnTimeout));

        }

        public void Dispose()
        {
            Marshal.ReleaseComObject(this.msc);
        }

        public object Eval(string expression, string codeBody)
        {
            this.msc.AddCode(codeBody);
            return this.msc.Eval(expression);
        }

        public object Eval(ScriptLanguage language, string expression, string codeBody)
        {
            if (this.Language != language)
            {
                this.Language = language;
            }
            return this.Eval(expression, codeBody);
        }

        private void OnError()
        {
            if (this.RunError != null)
            {
                this.RunError();
            }
        }

        private void OnTimeout()
        {
            if (this.RunTimeout != null)
            {
                this.RunTimeout();
            }
        }

        public void Reset()
        {
            this.msc.Reset();
        }

        public object Run(string mainFunctionName, object[] parameters, string codeBody)
        {
            this.msc.AddCode(codeBody);
            return this.msc.Run(mainFunctionName, ref parameters);
        }

        public object Run(ScriptLanguage language, string mainFunctionName, object[] parameters, string codeBody)
        {
            if (this.Language != language)
            {
                this.Language = language;
            }
            return this.Run(mainFunctionName, parameters, codeBody);
        }

        public bool AllowUI
        {
            get
            {
                return this.msc.AllowUI;
            }
            set
            {
                this.msc.AllowUI = value;
            }
        }

        public ScriptLanguage Language
        {
            get
            {
                return (ScriptLanguage) Enum.Parse(typeof(ScriptLanguage), this.msc.Language, false);
            }
            set
            {
                this.msc.Language = value.ToString();
            }
        }

        public int Timeout
        {
            get
            {
                return 0;
            }
        }

        public bool UseSafeSubset
        {
            get
            {
                return this.msc.UseSafeSubset;
            }
            set
            {
                this.msc.UseSafeSubset = true;
            }
        }
    }
  • 写回答

3条回答 默认 最新

  • 小小辉少 2015-08-15 08:59
    关注

    整套程序就改剩了这2个错误,都是业余整的,断断续续整了2个多月都还没有搞懂

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。