Default Public Readonly property in VB assembly does not appear when referenced in C #

I am having problems when I try to use a property from a VB assembly in a C # application. The VB assembly was created in .NET 1.1, and the application in which I am trying to use it is .NET 4.5 in C #. I looked at the VB assembly code and noted that a property in the assembly that does not appear for use when instantiating an object in a C # application is declared as Default Public ReadOnly Property. If I delete the keyword Default, the property will appear in the C # object. But the problem here is that dll is used in many other applications created in VB, and in these applications this problem does not exist. I have no way to change this dll just for my code.

Here is an example of what is happening to me:

VB Host Code

Default Public ReadOnly Property MyProperty(ByVal value As String) As String
    Get
        ...
    End Get
End Property

And in the C # object instance, this property never appears until I remove the keyword from it Default.

+4
source share
1 answer

I created a test project in C # and did the following:

        var foo = new Class1();
        Console.WriteLine(foo.MyProperty("Hello")); // Compile-time error
        Console.WriteLine(foo.get_MyProperty("Hello")); // Compile-time error: 'Test1.Class1.this[string].get': cannot explicitly call operator or accessor
        Console.WriteLine(foo.GetType().GetProperty("MyProperty").GetGetMethod().Invoke(foo, new object[]{"Hello"}));   // Works
        Console.WriteLine(foo["Hello"]);            // Works

The usual way to access an indexer in C # is the last line, and this works. Intellisense does not show the property MyProperty, and trying to call it gives a compile-time error. But it looks like I can access it through reflection.

The documentation for using indexers in C # shows code that uses an attribute to specify the name of the indexer for other languages, so I assume that C # just doesn't support calling the indexer in this way.

+1

Source: https://habr.com/ru/post/1542947/