我用VS2005 C#写了个COM组件。但是为什么我不能在C#项目(类库)中添加引用。出现如下错误。

ZhangHY2002 2006-04-28 05:45:28
ActiveX类型库“MySLib10.tlb(我的com)”是从.net程序集导出的,无法将其作为引用添加。

这是为什么啊?是不是我的Com写的有问题,还是c#不能调用c#写的com?
...全文
1204 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
dreadknightll 2006-04-29
  • 打赏
  • 举报
回复
C#可导入的dll有C#类库和com组件可供选择。
会不会是你导入的时候把 .dll 文件作为了C#类库导入而不是作为com组件导入?
ZhangHY2002 2006-04-29
  • 打赏
  • 举报
回复
上面朋友说的,我下午测试一下。先表示感谢了。
xqlez 2006-04-29
  • 打赏
  • 举报
回复
ZhangHY2002 2006-04-29
  • 打赏
  • 举报
回复
我测试了一下,楼上wangsaokui(起步停车)的方法也不行啊。

我的com是如下方法做的:
用VS2005创建了一个dll.然后再项目属性里设置了 “为 Com Interop注册。”并增加了强名。编译。然后就在其他的c#项目里引用com(在com标签中能找到)。就出现了上面的问题。
代码蜗牛sky 2006-04-28
  • 打赏
  • 举报
回复
加上强名称了没有?

http://www.cnxuexi.com/computer/chengxusheji/net/4405.html
Eddie005 2006-04-28
  • 打赏
  • 举报
回复
wangsaokui(无间道III)兄改名字了,差点没认出来~~~
wangsaokui 2006-04-28
  • 打赏
  • 举报
回复

using System;
using System.Reflection;
using System.Windows.Forms;
using System.EnterpriseServices;

[assembly : ApplicationName("OCDemoSvr")]
[assembly: ApplicationActivation(ActivationOption.Library)]
#if BuildBat
[assembly : AssemblyKeyFile("OCDemoSvrCS.snk")]
#else
[assembly : AssemblyKeyFile("..\\..\\OCDemoSvrCS.snk")]
#endif


namespace OCDemoServerCS
{
// Default value for the Construction string specified here
[ConstructionEnabled(Default="Default Construction String")]
public class ObjectConstructionTest : ServicedComponent
{
public ObjectConstructionTest()
{
// Constructor called first on instance creation
MessageBox.Show("Constructor called", "Object Construction Sample");
}

protected override void Construct(string constructString)
{
// Construct method called next, after constructor
MessageBox.Show("IObjectConstruct method called with value \"" + constructString + "\"", "Object Construction Sample");
}

public void DoWork ()
{
MessageBox.Show("DoWork method called", "Object Construction Sample");
}
}
}
===================================================


using System;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;

using OCDemoServerCS;


public class OCForm: Form
{
private Button constructButton;


public OCForm()
{
InitializeComponent();
}


private void InitializeComponent()
{
this.constructButton = new Button ();

constructButton.Location = new System.Drawing.Point (80, 40);
constructButton.Size = new System.Drawing.Size (96, 24);
constructButton.TabIndex = 1;
constructButton.Text = "Create Object";
constructButton.Click += new EventHandler (this.Construct_Click);

this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.Text = "Object Construction String Demo";
this.AutoScaleBaseSize = new Size (5, 13);
this.ClientSize = new System.Drawing.Size (270, 120);
this.Controls.Add (this.constructButton);
}


protected void Construct_Click (object sender, System.EventArgs e)
{
this.Cursor = Cursors.WaitCursor;

try
{
// The 'using' construct below results in a call to Dispose on exiting the
// curly braces. It could be replaced with an explicit call to Object.Dispose
// This is a C#-specific construct.
//
// It is important to dispose COM+ objects as soon as possible so that
// COM+ metadata such as context does not remain in memory unnecessarily
// and so that COM+ services such as Object Pooling work properly.
using(ObjectConstructionTest order = new ObjectConstructionTest())
{
order.DoWork();
}
}

catch (Exception ex)
{
MessageBox.Show("An exception was caught : "+ex.Message, "Error");
}

finally
{
this.Cursor = Cursors.Arrow;
}
}


public static void Main(string[] args)
{
Application.Run(new OCForm());
}
}
yuesongboy 2006-04-28
  • 打赏
  • 举报
回复
.NET组件.dll和com的.dll是不一样的

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧