Bug 59988 - System.MissingMemberException when accessing the list contents in a class property referenced by type "Object"
Summary: System.MissingMemberException when accessing the list contents in a class pro...
Status: NEW
Alias: None
Product: Runtime
Classification: Mono
Component: General (show other bugs)
Version: 5.0
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-10-05 15:16 UTC by cvr.dheeraj
Modified: 2017-10-05 15:16 UTC (History)
2 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description cvr.dheeraj 2017-10-05 15:16:08 UTC
Mono Version: Mono JIT compiler version 5.0.0 (Stable 5.0.0.100/9667aa6 Wed Jul 12 17:00:30 UTC 2017)
OS Version: Arch Linux
.NET Framework version: 4.6.1

I am attempting to run a large VB.NET project using Mono under Linux. I have come across a late binding issue and I have written a sample program to replicate the issue. Here is the code.

Module Main

    Sub Main()
        'Create instances
        Dim SmallContainer As New SmallContainerAttrib
        SmallContainer.Weight = 300

        Dim LargeContainer As New LargeContainerAttrib
        LargeContainer.Weight = 500

        'Container Items
        Dim ContainerItem1 As New ContainerItem
        ContainerItem1.Weight = 10
        Dim ContainerItem2 As New ContainerItem
        ContainerItem2.Weight = 20

        SmallContainer.Contents.Add(ContainerItem1)
        SmallContainer.Contents.Add(ContainerItem2)
        LargeContainer.Contents.Add(ContainerItem1)
        LargeContainer.Contents.Add(ContainerItem2)

        Dim MyContainer1 As New Container
        MyContainer1.Attributes = SmallContainer
        MyContainer1.Name = "Container1"

        Dim MyContainer2 As New Container
        MyContainer2.Attributes = LargeContainer
        MyContainer2.Name = "Container2"


        'Print Full container weights
        PrintContainerWeight(MyContainer1)
        PrintContainerWeight(MyContainer2)

        'Print weight of container item
        PrintContainerContentWeight(MyContainer1, 0)
        PrintContainerContentWeight(MyContainer1, 1)

        Console.ReadLine()
    End Sub

    Public Sub PrintContainerWeight(ByVal Container As Container)
        Console.WriteLine(String.Format("Weight Of {0} is {1}", Container.Name, Container.Attributes.Weight))
    End Sub

    Public Sub PrintContainerContentWeight(ByVal Container As Container, ByVal ItemIndex As Integer)
        Console.WriteLine(String.Format("Container Item Weight in {0} at position {1} is {2}", Container.Name, ItemIndex, Container.Attributes.Contents(ItemIndex).Weight))
    End Sub

    Public Class Container
        Public Property Attributes As Object
        Public Property Name As String
        Public Property IsActive As Boolean
    End Class

    Public Class SmallContainerAttrib
        Public Property Weight As Double
        Public Property SmallContainerVal1 As Integer
        Public Property SmallContainerVal2 As Integer
        Public Property SmallContainerVal3 As Integer
        Public Property Contents As New List(Of ContainerItem)
    End Class


    Public Class LargeContainerAttrib
        Public Property Weight As Double
        Public Property LargeContainerVal1 As Integer
        Public Property LargeContainerVal2 As Integer
        Public Property LargeContainerVal3 As Integer
        Public Property Contents As New List(Of ContainerItem)
    End Class

    Public Class ContainerItem
        Public Property Weight As Double
        Public Property Height As Double
        Public Property Width As Double
        Public Property Depth As Double
    End Class

End Module

The above code compiles perfectly fine on Windows and runs without any issues. However, on Mono in Linux, it crashes with the following exception on the following line
"Container.Attributes.Contents(ItemIndex).Weight"

Weight Of Container1 is 300
Weight Of Container2 is 500

Unhandled Exception:
System.MissingMemberException: Attempted to access a missing member.
  at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet (System.Object o, System.Type objType, System.String name, System.Object[] args, System.String[] paramnames, System.Boolean[] CopyBack) [0x000bb] in <e9c31d27c6b546a896655e6383f70df2>:0 
  at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet (System.Object Instance, System.Type Type, System.String MemberName, System.Object[] Arguments, System.String[] ArgumentNames, System.Type[] TypeArguments, System.Boolean[] CopyBack) [0x00001] in <e9c31d27c6b546a896655e6383f70df2>:0 
  at MonoTest.Main.PrintContainerContentWeight (MonoTest.Main+Container Container, System.Int32 ItemIndex) [0x00018] in <17a26c3182c14d4aa7ff125a3c8a6bd3>:0 
  at MonoTest.Main.Main () [0x000d7] in <17a26c3182c14d4aa7ff125a3c8a6bd3>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.MissingMemberException: Attempted to access a missing member.
  at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet (System.Object o, System.Type objType, System.String name, System.Object[] args, System.String[] paramnames, System.Boolean[] CopyBack) [0x000bb] in <e9c31d27c6b546a896655e6383f70df2>:0 
  at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet (System.Object Instance, System.Type Type, System.String MemberName, System.Object[] Arguments, System.String[] ArgumentNames, System.Type[] TypeArguments, System.Boolean[] CopyBack) [0x00001] in <e9c31d27c6b546a896655e6383f70df2>:0 
  at MonoTest.Main.PrintContainerContentWeight (MonoTest.Main+Container Container, System.Int32 ItemIndex) [0x00018] in <17a26c3182c14d4aa7ff125a3c8a6bd3>:0 
  at MonoTest.Main.Main () [0x000d7] in <17a26c3182c14d4aa7ff125a3c8a6bd3>:0 


The logic behind declaring the Attribute property in the Container class as "Object" is to assign it a class instance of LargeContainerAttrib or SmallContainerAttrib. Although this might not be the best approach, I feel this should still work on mono provided it works fine on with .net compiler.

Do let me know if you need additional information to debug this issue.

Note You need to log in before you can comment on or make changes to this bug.