【问题标题】:Error CS0234: The type or namespace name 'CustomMarshalers' does not exist in the namespace 'System.Runtime.InteropServices'错误 CS0234:命名空间“System.Runtime.InteropServices”中不存在类型或命名空间名称“CustomMarshalers”
【发布时间】:2016-08-06 03:28:22
【问题描述】:
using System;    
using System.Collections; 
using System.Reflection; 
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.CustomMarshalers;

namespace mshtml
{
    [DefaultMember("item"), CompilerGenerated, Guid("3050F21F-98B5-11CF-BB82-00AA00BDCE0B"), TypeIdentifier]
    [ComImport]
    public interface IHTMLElementCollection : IEnumerable
    {
        void _VtblGap1_3();
        [DispId(-4)]
        [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(EnumeratorToEnumVariantMarshaler))]
        IEnumerator GetEnumerator();
    }
}

上面的代码给了我以下错误:

错误 CS0234:命名空间“System.Runtime.InteropServices”中不存在类型或命名空间名称“CustomMarshalers”(您是否缺少程序集引用?)

请告知如何解决?这是一个反编译的代码,我是 C# 的初学者。

【问题讨论】:

  • 我只是将您的代码复制粘贴到一个新项目中,一切都很好。没有错误。您的项目中可能缺少一些 DLL 引用?
  • 不确定,我错过了什么
  • 仅用于测试,只需创建一个新项目并将您的代码复制粘贴到那里。
  • 是的,您缺少参考。添加引用对话框中的第二个 :) 永远不要反编译 mshtml,这没有意义,您的机器上已经有了 PIA。项目 > 添加参考 > 程序集 > 扩展 > 选择 Microsof.mshtml。并且首先要专注于编写自己的代码,你永远不会从尝试破解其他人的代码中学到任何有用的东西。

标签: c#


【解决方案1】:

您必须包含 CustomMarshalers.dll
示例:
使用项目添加引用 -> 添加引用 -> 浏览 -> 转到位置 "C:\Windows\assembly\GAC_32\CustomMarshalers\2.0.0.0__b03f5f7f11d50a3a" -> 选择 CustomMarshalers.dll

【讨论】:

    【解决方案2】:

    很抱歉复活了一个旧线程。使用 Framework 4.72,您可以使用 Project -> Add Reference -> Assemblies -> 选中 CustomMarshalers 旁边的框。

    【讨论】:

    • 请注意,Stack Exchange 并没有像许多论坛那样真正具有“线程死灵法”规则。只要你能提供一个好的、独特的答案,问题的年龄并不重要。
    猜你喜欢
    • 2019-06-27
    • 1970-01-01
    • 1970-01-01
    • 2012-10-13
    • 2019-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多