Skip to content

nonComVisibleBaseClass Error #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
CConnes opened this issue Nov 2, 2015 · 3 comments
Closed

nonComVisibleBaseClass Error #213

CConnes opened this issue Nov 2, 2015 · 3 comments

Comments

@CConnes
Copy link

CConnes commented Nov 2, 2015

Hi,
I used moq version 4.0.10827 to mock an Com object and when i upgrade to 4.2.1510.2205 i get an nonComVisibleBaseClass error when the test execute:

    [Guid("0339CD56-9BA3-477D-801B-E5F73D37EABE")]
    [TypeLibType(4160)]
    public interface IDaemonCli
    {
        // methods & propperties ...
        [DispId(1)]
        void CloseLog();
       ....
    }

[CoClass(typeof(DaemonCliClass))]
[Guid("0339CD56-9BA3-477D-801B-E5F73D37EABE")]
public interface DaemonCli : IDaemonCli
{
}

[ClassInterface(0)]
[Guid("D94FBC81-06EC-4EAA-B73F-794051487691")]
[TypeLibType(2)]
public class DaemonCliClass : IDaemonCli, DaemonCli
{
        // ... definitions of all methods of the com obj
       [DispId(1)]
       public virtual void CloseLog();
       ....
}

The mock is created as this :

[TestClass]
[Serializable]
    public abstract class Test : IDisposable
    {
         protected static Mock<DaemonCli> DaemonClientMock { get; private set; }
         static Test()
        {
            Test.DaemonClientMock = new Mock<DaemonCli>();
            // here are all the setup on the DaemonClientMock
        }

The mock is injected in the tested code as this :

typeof(LoggedServiceBase).GetProperty(
                PropertySupport.ExtractPropertyName(() => this.batchClassService.Logger),
                BindingFlags.Public | BindingFlags.Instance)
                .SetValue(this.batchClassService, Test.DaemonClientMock.Object, null);

The Exception is raised when the mock is used by the tested class:

freeMindCom.SetLog(this.Logger);

Any help would be appreciated.
Thanks

@CConnes
Copy link
Author

CConnes commented Nov 10, 2015

Any advice ?
May i have to implement an additional interface on the mock ?

CConnes

@kzu
Copy link
Member

kzu commented Nov 10, 2015

The way you're "injecting" the mock is totally weird (dependencies should be explicitly passed via ctors or public property setters, failing that.

Other than that, I've never done COM with Moq, so I've no idea. Maybe ask on Castle.DynamicProxy?

@CConnes
Copy link
Author

CConnes commented Nov 13, 2015

Thanks, i 'll make a try on Castle.

@CConnes CConnes closed this as completed Nov 13, 2015
@devlooped devlooped locked and limited conversation to collaborators Sep 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants