[英]Custom ActiveX .NET control Fails to Recognize in WinForms/WPF Projects
I'm creating an ActiveX control library (.dll) in .NET to be used in Internet Explorer. 我正在.NET中创建一个ActiveX控件库(.dll),以便在Internet Explorer中使用。 It implements
IObjectSafety
and looks similar to this: 它实现了
IObjectSafety
,看起来类似于:
namespace ActiveXControl
{
[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[Guid("ABA9D4C3-8166-440C-90C8-2FA6CD4C3C77")]
interface ITestControl
{
string GetText();
}
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[Guid("0B3C1BB4-ED2C-4336-9E4C-72A908E74F51")]
[ProgId("ActiveXControl.TestControl")]
[ComDefaultInterface(typeof(ITestControl))]
public class TestControl : UserControl, ITestControl, IObjectSafety
{
#region ITestControl
public string GetText()
{
return "Foo";
}
#endregion
#region IObjectSafety
public enum ObjectSafetyOptions
{
INTERFACESAFE_FOR_UNTRUSTED_CALLER = 0x00000001,
INTERFACESAFE_FOR_UNTRUSTED_DATA = 0x00000002,
INTERFACE_USES_DISPEX = 0x00000004,
INTERFACE_USES_SECURITY_MANAGER = 0x00000008
};
public int GetInterfaceSafetyOptions(ref Guid riid, out int pdwSupportedOptions, out int pdwEnabledOptions)
{
ObjectSafetyOptions m_options = ObjectSafetyOptions.INTERFACESAFE_FOR_UNTRUSTED_CALLER | ObjectSafetyOptions.INTERFACESAFE_FOR_UNTRUSTED_DATA;
pdwSupportedOptions = (int)m_options;
pdwEnabledOptions = (int)m_options;
return 0;
}
public int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions)
{
return 0;
}
#endregion
}
}
When I create a .cab out of this and run it in IE it works. 当我从中创建一个.cab并在IE中运行它时,它可以工作。 But when I create a regular WPF desktop app and reference the assembly I get an unusual situation: When I first add the reference (or do a clean) the
ActiveXControl
namespace and control appear recognized in Visual Studio. 但是,当我创建一个常规的WPF桌面应用程序并引用该程序集时,会遇到一种不寻常的情况:当我第一次添加引用(或执行清除操作)时,
ActiveXControl
命名空间和控件在Visual Studio中会被识别。 As soon as I build I get the message: 构建后,我立即收到消息:
The type of namespace name 'ActiveXControl' cound not be found (are you missing a using directive or an assembly reference?)
找不到名称空间名称“ ActiveXControl”的类型(您是否缺少using指令或程序集引用?)
I've tried rebuilding the control and several variations, including a WinForms project. 我尝试过重建控件和多种变体,包括WinForms项目。 Could someone explain why this happens and what I can do to fix it?
有人可以解释为什么会发生这种情况,我该如何解决?
Solution was to go into the project properties and change the Target Framework from ".NET Framework 4 Client Profile" to just ".NET Framework 4." 解决方案是进入项目属性,并将目标框架从“ .NET Framework 4客户端配置文件”更改为“ .NET Framework 4”。 After that, it builds/runs fine.
之后,它会正常构建/运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.