1

我编写了一个从 xml 文件中读取并将结果作为字符串返回的类库。但是当我想将它作为 COM+ 组件安装时,出现了错误(错误代码:80131501)。我检查了事件日志,错误的详细信息是:

将“C:\Users\User\Documents\Visual Studio 2005\Projects\InteropSOA\InteropSOA\bin\Debug\InteropSOA.dll”安装到“{28E82165-AD74-4E16-90C9-0C5CE7DA97AA}”失败并出现异常:系统.EnterpriseServices.RegistrationException:致命:找不到我们刚刚安装的组件“InteropSOA.ConfigReader”。在 System.EnterpriseServices.RegistrationDriver.InstallAssembly(RegistrationConfig regConfig, Object obSync) 在 System.EnterpriseServices.RegistrationHelper.InstallAssemblyFromConfig(RegistrationConfig& regConfig) 在 System.EnterpriseServices.RegistrationHelper.InstallAssembly(字符串程序集,字符串和应用程序,字符串分区,字符串和 tlb,InstallationFlags installFlags ) 在 System.EnterpriseServices.Internal.ComManagedImportUtil.InstallAssembly(字符串 asmpath、字符串参数名称、字符串应用程序名称)

以下是我在开发类库时完成的步骤:

  • 在参考中添加了“System.EnterpriseServices”。
  • 导入对类的引用。
  • 将类声明为“ServicedComponent”。
  • 设置项目属性(选中“使程序集 COM 可见”,选中“注册 COM 互操作”,使用强密钥文件名对程序集进行签名。)

这是我的代码:

using System;  
using System.Collections.Generic;  
using System.Text;  
using System.Xml;  
using System.Xml.XPath;  
using System.EnterpriseServices;  


namespace InteropSOA
{
public class ConfigReader : ServicedComponent
{
    // xml file name
    private string strFileName;
    // type of request
    private string strRequest = "";
    // response string
    private string strResponse = "";

    // declarations for xPath
    private XPathDocument doc;
    private XPathNavigator nav;
    private XPathExpression expr;
    private XPathNodeIterator iterator;

    private XmlTextReader reader;
    private XmlDocument xmlDoc;

    public ConfigReader(string strFile, string request)
    {
        this.strFileName = strFile;         
        this.strRequest = request;  

    }

    public ConfigReader()
    { 
        //default contructor
    }

    // reader for console program
    public void ReadXML()
    {
        doc = new XPathDocument(strFileName);
        nav = doc.CreateNavigator();
        // compile xPath expression
        expr = nav.Compile("/Msg/" + strRequest + "/*");
        iterator = nav.Select(expr);

        // interate on the node set
        try
        {
            while (iterator.MoveNext())
            {
                XPathNavigator nav2 = iterator.Current.Clone();
                strResponse += nav2.Value + "|";

            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

        strResponse = strResponse.Substring(0, strResponse.Length-1);

        Console.WriteLine("Response string = " + strResponse);
    }

    public void WriteXML(string strRequest, string strElement, string strValue)
    {
        reader = new XmlTextReader(strFileName);
        xmlDoc = new XmlDocument();
        xmlDoc.Load(reader);
        reader.Close();


        XmlNode node; 
        XmlElement root = xmlDoc.DocumentElement;
        node = root.SelectSingleNode("/Msg/" + strRequest + "/" + strElement);

        node.InnerText = strValue;

        xmlDoc.Save(strFileName);
    }

    // reader for ASP.NET
    public string ReadXMLElement()
    {
        doc = new XPathDocument(strFileName);
        nav = doc.CreateNavigator();
        // compile xPath expression
        expr = nav.Compile("/Msg/" + strRequest + "/*");
        iterator = nav.Select(expr);

        // interate on the node set
        try
        {
            while (iterator.MoveNext())
            {
                XPathNavigator nav2 = iterator.Current.Clone();
                strResponse += nav2.Value + "|";

            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

        strResponse = strResponse.Substring(0, strResponse.Length - 1);

        return strResponse;
    }
}

}

4

1 回答 1

1

通过禁用 Windows 7 UAC 解决了问题。

于 2010-03-14T10:59:38.780 回答