locked
COM+ component calling other COM+ components - “Cannot load type” RRS feed

  • Question

  • I have a two .NET assemblies which are registered as COM+ components and I'm testing them from a regular console application

    "Dim objFirst As New MyFirstComponent() 'COM+ initialisation

    Dim RC As Boolean = objFirst.GetValue()"

    The method call is executed successfully. This is the definition of MyFirstComponent;

    <ProgId("MyFirstComponent")> _
    <Guid("...")> _
    <ClassInterface(ClassInterfaceType.None)> _
    <Transaction(TransactionOption.Supported)> _
    Public Class MyFirstComponent
        Inherits ServicedComponent
        Implements IMyFirstComponent
    
        Public Function GetValue() As Boolean Implements IMyFirstComponent.GetValue
            Dim objSecond As New MySecondComponent() 'COM+ initialisation
            Dim RC As Boolean = objSecond.GetValue()
            Return RC
        End Function
    
    End Class

    At the point where MySecondComponent is initialised, I get a RemotingException with the following message;

    Cannot load type 'MySecondComponent', ..., Version=..., Culture=neutral, PublicKeyToken=...'

    All assemblies are strongly named too. I cannot work out why I can successfully fire a method call to the first component, but when it tries to subsequently load up the second component itself, it can't resolve the type.

    As a sidenote, if I run the code from the body of "GetValue()" in my dev, it executes as expected. The problem seems to only crop up once things have moved into the realm of COM+ components calling other COM+ components.

    Any quick suggestions will be highly appreciated.

    I have a two .NET assemblies which are registered as COM+ components and I'm testing them from a regular console application test harness;

    Dim objFirst As New MyFirstComponent() 'COM+ initialisation
    Dim RC As Boolean = objFirst.GetValue()

    The method call is executed successfully. This is the definition of MyFirstComponent;

    <ProgId("MyFirstComponent")> _
    <Guid("...")> _
    <ClassInterface(ClassInterfaceType.None)> _
    <Transaction(TransactionOption.Supported)> _
    Public Class MyFirstComponent
        Inherits ServicedComponent
        Implements IMyFirstComponent
    
        Public Function GetValue() As Boolean Implements IMyFirstComponent.GetValue
            Dim objSecond As New MySecondComponent() 'COM+ initialisation
            Dim RC As Boolean = objSecond.GetValue()
            Return RC
        End Function
    
    End Class

    At the point where MySecondComponent is initialised, I get a RemotingException with the following message;

    Cannot load type 'MySecondComponent', ..., Version=..., Culture=neutral, PublicKeyToken=...'

    All assemblies are strongly named too. I cannot work out why I can successfully fire a method call to the first component, but when it tries to subsequently load up the second component itself, it can't resolve the type.

    As a sidenote, if I run the code from the body of "GetValue()" in my test harness, it executes as expected. The problem seems to only crop up once things have moved into the realm of COM+ components calling other COM+ components.

    Thursday, July 25, 2019 4:01 PM

All replies

  • Where have you read that this is a valid part of .Net programming. 

       Dim objSecond As New MySecondComponent() 'COM+ initialisation

    Your statement tells to use objSecond instanced from a class named MySecondComponent. 

    AFAIK has it nothing to do with a Com+ initialisation


    Success
    Cor

    Thursday, July 25, 2019 4:55 PM
  •  Thank you for the quick response Cor. 

     Instead of this Dim objSecond As New MySecondComponent() , we have also tried to use below

    Dim objSecond As object
    objSecond = CreateObject("MySecondComponent.MyMethod")
    However, now the error which we got is "ActiveX Cannot Create Object".

    Please note that, we are deriving the COM + class from "System.EnterpriseServices.ServicedComponent".

    Please let us know if you need any further information.

    Thursday, July 25, 2019 6:23 PM
  • Hello, Any quick response will be highly appreciated!!!
    Friday, July 26, 2019 7:01 PM
  • Which version of VB and what kind of project?



    Success
    Cor


    Monday, July 29, 2019 9:33 AM
  • We are doing a VB6 to VB.net (framework 4.7) migration. 

    In VB6, the business logic is written in COM+ components which are hosted on COM+ Applications.

    As a part of this migration, we are not doing any changes to the architecture and doing As-is migration. 

    I.e., we are converting the COM+ components using "System.EnterpriseServices.ServicedComponent"  to .Net equivalent. However, while calling a COM+ component in other COM+ component, we are getting the error mentioned my first post.

    Please advice !!

    Monday, July 29, 2019 3:26 PM
  • This is tried since 2002. Most then forms controls became unusable because they where based on ActiveX the then for security reasons abandoned technology of Microsoft.

    This is the reason some started to tell that VB was not anymore VB. Which is not true, .Com was replaced by .Net

    As you know is Microsoft never selling "Not possible". However, if you see on Internet what is needed it is probably easier to swim from Liverpool to New York. Which is theoretical as well possible as long that you don't sink. 

    https://docs.microsoft.com/en-us/dotnet/framework/interop/index


    Success
    Cor

    Monday, July 29, 2019 4:52 PM
  • Hi Cor,

    I have gone through the link which you provided. However no luck as yet.

    Wednesday, July 31, 2019 3:16 PM
  •  Hi Cor,

    This issue is resolved now. Thanks  for your support.

    Thursday, October 31, 2019 3:37 PM