views:

474

answers:

1

I've written a class library that reads from an xml file and return the result as a string. But when I want to install it as a COM+ component, an error occurred (Error Code: 80131501). I checked the event log and the details of the error is:

Installation of 'C:\Users\User\Documents\Visual Studio 2005\Projects\InteropSOA\InteropSOA\bin\Debug\InteropSOA.dll' into '{28E82165-AD74-4E16-90C9-0C5CE7DA97AA}' failed with an exception: System.EnterpriseServices.RegistrationException: FATAL: Could not find component 'InteropSOA.ConfigReader' we just installed. at System.EnterpriseServices.RegistrationDriver.InstallAssembly(RegistrationConfig regConfig, Object obSync) at System.EnterpriseServices.RegistrationHelper.InstallAssemblyFromConfig(RegistrationConfig& regConfig) at System.EnterpriseServices.RegistrationHelper.InstallAssembly(String assembly, String& application, String partition, String& tlb, InstallationFlags installFlags) at System.EnterpriseServices.Internal.ComManagedImportUtil.InstallAssembly(String asmpath, String parname, String appname)

Below are the steps I've done while developing the class library:

  • Added "System.EnterpriseServices" to Reference.
  • Imported the reference to the class.
  • Declared the class as "ServicedComponent".
  • Set project properties ("Make assembly COM-visible" checked, "Register for COM Interop" checked, Signed the assembly with a strong key file name.)

Here are my codes:

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;
    }
}

}

A: 

Problem solved by disabling Windows 7 UAC.

Regina Foo