Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4111206
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:02:11+00:00 2026-05-20T22:02:11+00:00

I have a generic base wrapper class to wrap a couple of com components

  • 0

I have a generic base wrapper class to wrap a couple of com components we’re using:

public class WrapperBase<T> : IDisposable
    where T : new()
{
    private T comObject = default(T);
    private ComponentParameters parameters = null;

    protected WrapperBase()
    {
        comObject = new T();
        Initialize();
    }

    public void SetParameters(ComponentParameters parameters)
    {
        // ...
        this.parameters = parameters;
    }

    // ... 
}

Now I have a concrete wrapper class which inherits from this base class:

public class UserWrapper : WrapperBase<CUserClass>
{
    public UserWrapper() : base() { }

    public void SomeUserWrapperMethod() 
    { 
        // ... 
    }
}

The type used (CUserClass) is a COM interop type. This type is available after adding the COM object as a reference to the project.

Now I use this class in another assembly (which references the assembly in which the above types are defined):

using (var user = new UserWrapper())
{
    user.SomeUserWrapperMethod();
}

The above code compiles fine, but if I’m actually calling the SetParameters method (which is only defined in the Wrapperbase class):

using (var user = new UserWrapper())
{
    user.SetParameters(someParameters);
}

I get a (double) compilation error:

  • error CS0012: The type ‘ComponentsAssembly.CUserClass’ is defined
    in an assembly that is not referenced. You must add a reference to assembly
    ‘Interop.ComponentsAssembly,
    Version=1.0.0.0, Culture=neutral,
    PublicKeyToken=…’.
  • ComponentWrappers.dll: (Related file)
    error CS0310: ‘ComponentsAssembly.CUserClass’ must be a
    non-abstract type with a public parameterless constructor in order to
    use it as parameter ‘T’ in the generic type or method ‘Contact.Wrappers.WrapperBase’

I’ve tried adding a reference to the component, but I still get the same error message.

This used to work before I changed the WrapperBase to a generic type, but then there was a lot of code identical in all the concrete wrappers, so I refactored it, making the WrapperBase generic in the process.

I can actually solve this by adding a constructor to the concrete class which takes a “ComponentParameters” as a parameter and calls the SetParameters internally:

public class UserWrapper : WrapperBase<CUserClass>
{
    public UserWrapper() : base() { }

    public UserWrapper(ComponentParameters parameters) : base()
    {
        SetParameters(parameters)
    }
}

And then using it like this:

using (var user = new UserWrapper(someParameters))
{
    user.SomeUserWrapperMethod();
}

But I’d rather have both methods working (using a constructor and explicitly calling SetParameters).

Can anybody explain to me what exactly is happening here, as I’ve been banging my head against the wall for the last couple of hours.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T22:02:12+00:00Added an answer on May 20, 2026 at 10:02 pm

    Try this: when you add the COM reference in ComponentWrappers.dll, it generates an interop assembly for it and puts it in the build location (bin/release whatever) for that assembly. In main, navigate to that location and add a a .NET reference (not COM reference) and navigate to that build location and take the interop as the reference.

    I think it may be getting confused because you added it as COM in both places and it generated an interop in each…

    The other option is to completely prevent the COM artifact from having any public visibility outside your assembly. To do this you’d have to hide it internally in a class, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base class which is non-generic with a derived generic class. The
I have a generic class in C# with 2 constructors: public Houses(params T[] InitialiseElements)
I have a generic list... public List<ApprovalEventDto> ApprovalEvents The ApprovalEventDto has public class ApprovalEventDto
I have a generic class that should allow any type, primitive or otherwise. The
I have a generic Repository<T> class I want to use with an ObjectDataSource. Repository<T>
I have a generic class that I'm trying to implement implicit type casting for.
I have a 'generic' boiler plate static method for checking for InvokeRequired and invoking
I have a generic list of objects in C#, and wish to clone the
I have a generic list of objects in C#, for example sake, here's what
I have a generic method with this (dummy) code (yes I'm aware IList has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.