Com+的使用

 1.添加引用System.EnterpriseServices,并且using System.EnterpriseServices;

2.Public class public class ComSample:ServicedComponent //类要从ServicedComponent继承

在类的前面要添加 [Transaction(TransactionOption.Required)],以启用事务

3.编写需要的类

4.修改AssemblyInfo.cs文件

[assembly: ComVisible(true)]
[assembly: AssemblyVersion("1.0.*")]//*时版本号变化
//[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly:AssemblyKeyFileAttribute("..//..//Enterprise.snk")]//强命名,snk文件在项目的根目录,可以与别的类库共用一个snk文件

5.强命名

在vs.net2005自带的 命令行工具(不使用自带的工具要对环境变量进行配置)

sn -k 路径/Enterprise.snk

路径就是项目所在的绝对路径

6.注册到.NetFramework

regsvcs 路径/bin/debug/*.dll

路径含义同上

7.可以在webform中调用了,引用.dll文件,实例化类,正常使用。

8.在使用过程中出现的错误:

错误二的原因就是没有注册到.netframework中,

解决办法:6步操作

错误一的原因是AssemblyInfo.cs文件中的[assembly: ComVisible(false)]默认是false

解决办法:[assembly: ComVisible(true)]

错误一、

 说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.EnterpriseServices.RegistrationException: 在程序集中找到无效的 ServicedComponent 派生类。
(类必须是公共的、具体的、有公共的默认构造函数并满足所有其他 ComVisibility 要求)

源错误:

行 19:     protected void Button1_Click(object sender, EventArgs e)
行 20:     {
行 21:         ComPlusSample.ComSample c = new ComPlusSample.ComSample();
行 22:         try
行 23:         {

源文件: d:/Inetpub/wwwroot/test01/COMPLUS.aspx.cs    行: 21

堆栈跟踪:

[RegistrationException: 在程序集中找到无效的 ServicedComponent 派生类。
(类必须是公共的、具体的、有公共的默认构造函数并满足所有其他 ComVisibility 要求)]
   System.EnterpriseServices.RegistrationDriver.InstallAssembly(RegistrationConfig regConfig, Object obSync) +1011
   System.EnterpriseServices.RegistrationHelper.InstallAssemblyFromConfig(RegistrationConfig& regConfig) +464
   System.EnterpriseServices.RegistrationHelper.InstallAssembly(String assembly, String& application, String partition, String& tlb, InstallationFlags installFlags) +107
   System.EnterpriseServices.RegistrationHelper.System.EnterpriseServices.Thunk.IThunkInstallation.DefaultInstall(String asm) +38
   System.EnterpriseServices.Thunk.Proxy.RegisterAssembly(Assembly assembly) +91
   System.EnterpriseServices.Thunk.Proxy.LazyRegister(Guid id, Type serverType, Boolean checkCache) +194
   System.EnterpriseServices.Thunk.Proxy.CoCreateObject(Type serverType, Boolean bQuerySCInfo, Boolean& bIsAnotherProcess, String& uri) +203
   System.EnterpriseServices.ServicedComponentProxyAttribute.CreateInstance(Type serverType) +161
   System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(Type serverType, Object[] props, Boolean bNewObj) +73
   COMPLUS.Button1_Click(Object sender, EventArgs e) in d:/Inetpub/wwwroot/test01/COMPLUS.aspx.cs:21
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

“/test01”应用程序中的服务器错误。

在程序集中找到无效的 ServicedComponent 派生类。
(类必须是公共的、具体的、有公共的默认构造函数并满足所有其他 ComVisibility 要求)

 


版本信息: Microsoft .NET Framework 版本:2.0.50727.42; ASP.NET 版本:2.0.50727.42

错误二、说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.UnauthorizedAccessException: 对注册表项“HKEY_CLASSES_ROOT/ComPlusSample.ComSample”的访问被拒绝。

ASP.NET 未被授权访问所请求的资源。请考虑授予 ASP.NET 请求标识访问此资源的权限。ASP.NET 有一个在应用程序没有模拟时使用的基进程标识(通常,在 IIS 5 上为 {MACHINE}/ASPNET,在 IIS 6 上为网络服务)。如果应用程序正在通过 <identity impersonate="true"/> 模拟,则标识将为匿名用户(通常为 IUSR_MACHINENAME)或经过身份验证的请求用户。

要将 ASP.NET 访问权限授予某个文件,请在资源管理器中右击该文件,选择“属性”,然后选择“安全”选项卡。单击“添加”添加适当的用户或组。突出显示 ASP.NET 帐户,选中所需访问权限对应的框。

源错误:

行 19:     protected void Button1_Click(object sender, EventArgs e)
行 20:     {
行 21:         ComPlusSample.ComSample c = new ComPlusSample.ComSample();
行 22:         try
行 23:         {

源文件: d:/Inetpub/wwwroot/test01/COMPLUS.aspx.cs    行: 21

堆栈跟踪:

[UnauthorizedAccessException: 对注册表项“HKEY_CLASSES_ROOT/ComPlusSample.ComSample”的访问被拒绝。]
   Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str) +2116035
   Microsoft.Win32.RegistryKey.CreateSubKey(String subkey, RegistryKeyPermissionCheck permissionCheck, RegistrySecurity registrySecurity) +2119992
   Microsoft.Win32.RegistryKey.CreateSubKey(String subkey) +15
   System.Runtime.InteropServices.RegistrationServices.RegisterManagedType(Type type, String strAsmName, String strAsmVersion, String strAsmCodeBase, String strRuntimeVersion) +223
   System.Runtime.InteropServices.RegistrationServices.RegisterAssembly(Assembly assembly, AssemblyRegistrationFlags flags) +298
   System.EnterpriseServices.RegistrationDriver.ClassicRegistration(Assembly asm) +110

[RegistrationException: 注册程序集“ComPlusSample, Version=1.0.2368.27504, Culture=neutral, PublicKeyToken=60fbfb1d3574ca7a”失败。]
   System.EnterpriseServices.RegistrationDriver.ClassicRegistration(Assembly asm) +175
   System.EnterpriseServices.RegistrationDriver.InstallAssembly(RegistrationConfig regConfig, Object obSync) +381

[RegistrationException: 要执行此任务,您必须具有管理凭据。请与您的系统管理员联系以获得帮助。]
   System.EnterpriseServices.RegistrationDriver.InstallAssembly(RegistrationConfig regConfig, Object obSync) +1011
   System.EnterpriseServices.RegistrationHelper.InstallAssemblyFromConfig(RegistrationConfig& regConfig) +464
   System.EnterpriseServices.RegistrationHelper.InstallAssembly(String assembly, String& application, String partition, String& tlb, InstallationFlags installFlags) +107
   System.EnterpriseServices.RegistrationHelper.System.EnterpriseServices.Thunk.IThunkInstallation.DefaultInstall(String asm) +38
   System.EnterpriseServices.Thunk.Proxy.RegisterAssembly(Assembly assembly) +91
   System.EnterpriseServices.Thunk.Proxy.LazyRegister(Guid id, Type serverType, Boolean checkCache) +194
   System.EnterpriseServices.Thunk.Proxy.CoCreateObject(Type serverType, Boolean bQuerySCInfo, Boolean& bIsAnotherProcess, String& uri) +203
   System.EnterpriseServices.ServicedComponentProxyAttribute.CreateInstance(Type serverType) +161
   System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(Type serverType, Object[] props, Boolean bNewObj) +73
   COMPLUS.Button1_Click(Object sender, EventArgs e) in d:/Inetpub/wwwroot/test01/COMPLUS.aspx.cs:21
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102


版本信息: Microsoft .NET Framework 版本:2.0.50727.42; ASP.NET 版本:2.0.50727.42

“/test01”应用程序中的服务器错误。

对注册表项“HKEY_CLASSES_ROOT/ComPlusSample.ComSample”的访问被拒绝。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值