Skip to content

[PORT] fix index access bug caused by Access Modifiers of C# class #1918

Closed
@tomlm

Description

@tomlm

Port this change from botbuilder-dotnet/master branch:
microsoft/botbuilder-dotnet#3554

Close: #3555

Bug description: Assume there is a static class PublicA, and it contains a private class A, the structure shown as below:

public static class PublicA
    {
        public static object GetList()
        {
            return new List<A> { new A("hi") };
        }

        private class A
        {
            public A(string name)
            {
                this.Name = name;
            }
            public string Name { get; set; }
        }
    }

We call the static method in another class (which has no access to class A), and use dynamic as an intermediate variable. Code as below:

var list = PublicA.GetList();
dynamic dy = list;
var result = dy[0];

When running through the code, the error occurs with the message: Cannot apply indexing with [] to an expression of type 'object'

So, the root cause of the issue is that when we cast a list value (with a specific object Generics, and the caller has no access to this class) to dynamic, some features of List would be lost.

Changed projects

  • AdaptiveExpressions
  • AdaptiveExpressions.Tests

[LG,R9]

Metadata

Metadata

Assignees

No one assigned

    Labels

    R9Release 9 - May 15th, 2020

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions