【问题标题】:Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: ''System.__ComObject' does not contain a definition for 'Language''Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:“System.__ComObject”不包含“语言”的定义
【发布时间】:2021-10-24 14:52:21
【问题描述】:

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:“System.__ComObject”不包含“语言”的定义

有谁知道为什么我总是收到这个错误?我在 youtube 视频上找到了这段代码来制作计算器。请帮忙。

private void result_Click(object sender, RoutedEventArgs e)
    {

        result.Background = Brushes.BlueViolet;


        Type scriptType = Type.GetTypeFromCLSID(Guid.Parse("0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC"));
        dynamic obj = Activator.CreateInstance(scriptType, false);
        obj.Language = "javascript";
        string str = null;

        try
        {
            var res = obj.Eval(screen.Text);
            str = Convert.ToString(res);
            screen.Text = screen.Text + "=" + str;
        }
        catch (SystemException)
        {

            screen.Text = "syntax error";
        }

【问题讨论】:

  • 项目 > 添加 COM 引用 > 勾选“Microsoft Script Control 1.0”。初始化 var obj = new MSScriptControl.ScriptControl();

标签: c# calculator


【解决方案1】:

可能是您遇到了这个问题:https://github.com/dotnet/runtime/issues/13274

感谢您报告此问题。 .NET Core 3.0 不支持对 COM 对象使用 dynamic 关键字。 .Net 5 的 https://github.com/dotnet/coreclr/issues/24246 中正在跟踪此问题。解决方法是将类转换为相应的接口。

只要确保com对象和对应的接口中有语言定义即可。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-29
    • 1970-01-01
    • 1970-01-01
    • 2015-05-31
    • 1970-01-01
    相关资源
    最近更新 更多