日期:2014-05-18  浏览次数:20941 次

用C#编写ActiveX控件编译出错,希望各高手能指点一下,谢谢了
用C#编写ActiveX控件,右键"Propertites"在"生成选项卡"里,把"COM Interop"勾选上后编译提示错误

C:\Windows\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.XML.dll /debug+ /debug:full /optimize- /out:obj\Debug\SHAP.Card.UI.dll /resource:obj\Debug\SHAP.Card.UI.Properties.Resources.resources /resource:obj\Debug\SHAP.PRINT.RFPrintReader.resources /target:library AMT.cs BaseActiveXControl.cs ISafe.cs Properties\Resources.Designer.cs RFPrintReader.cs Properties\AssemblyInfo.cs RFPrint.cs

Compile complete -- 0 errors, 0 warnings
SHAP.PRINT.UI -> d:\Object\SHAP.Card.UI\bin\debug\SHAP.Card.UI.dll
C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets(3019,9): error MSB3213: Cannot register type library "d:\Object\SHAP.Card.UI\bin\debug\SHAP.Card.UI.tlb". 访问 OLE 注册表的错误。 (Exception from HRESULT: 0x8002801C (TYPE_E_REGISTRYACCESS))
Done building project "SHAP.PRINT.UI.csproj" -- FAILED.

但如果把右键"Propertites"在"生成选项卡"里,把"COM Interop"的选项去掉,则编译没有问题

希望各位大大,给个解决的方法



------解决方案--------------------
打开在解决方案资源管理器里你的项目下的Properties目录的AssemblyInfo.cs文件

[assembly: ComVisible(false)]
改成
[assembly: ComVisible(true)]