Skip to content
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

Honor [ComVisible(false)] method atrtibutes in advance #208

Closed
gureedo opened this issue Nov 15, 2023 · 4 comments · Fixed by #217
Closed

Honor [ComVisible(false)] method atrtibutes in advance #208

gureedo opened this issue Nov 15, 2023 · 4 comments · Fixed by #217

Comments

@gureedo
Copy link

gureedo commented Nov 15, 2023

I have simple example:

public interface IMyClass {
    [ComVisible(false)] 
    public System.Security.Cryptography.X509Certificates.X509RevocationMode RevocationMode { get; set; }
}
public class MyClass: IMyClass {
    public System.Security.Cryptography.X509Certificates.X509RevocationMode RevocationMode { get; set; }
}

If I run tlbexport with --createmissingdependenttlbs false there will be warnings in output.

dscom : warning TX00000000 : The referenced library System.Security.Cryptography does not have a type library and auto generation of dependent type libs is disabled
@SOsterbrink
Copy link
Member

So to understand your Issue, your expectation is that a [ComVisible(false)] from the interface is propagated to the implementing property? And that the implementing property is automatically also [ComVisible(false)]

Because if that's the case I'll have to check whether that's the expected behavior. We tried to have the same behavior as the old tlbexp.

@SOsterbrink
Copy link
Member

SOsterbrink commented Nov 16, 2023

For the generation of the tlb we ignore the property with [ComVisible(false)]. The problem is now that we have to also check methods and properties that are invisible to COM once to calculate some things like the offset of the VTable.

So we produce an unnecessary warning during the generation process.

@gureedo
Copy link
Author

gureedo commented Nov 16, 2023

So we produce an unnecessary warning during the generation process.

Yes. Right.

@marklechtermann
Copy link
Member

The problem here is that the TypeLibExporterNotifySink is informed that a TLB was not found.
This is because a MethodWriter is created, although this is only needed to calculate the VTableOffset.

One solution would be not to create the MethodWriter in the case of a property/method that is ComVisible=false.

in InterfaceWriter.cs e.g:

private void CreateMethodWriters()
    {
         ...
        foreach (var method in methods)
        {
            var methodAttribute = method.GetCustomAttribute<ComVisibleAttribute>();
            if (methodAttribute == null || methodAttribute.Value)
            {
                // Add a null entry
                // This is needed to keep the correct order of the methods to calculate the VTableOffset
                MethodWriter.Add(null);
            }
   ...

@SOsterbrink This should solve the problem ... maybe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants