- INDEX VB TO NET
- KNOWLEDGE BASE
- EWIS-WARNINGS
- WARNING #1063
WARNING #1063
Arrays in structure %1 may need to be initialized before they can be used.
Description
In Visual Basic .NET, fixed-size arrays in structures are not supported. Fixed-size arrays that are members of structures defined in COM interfaces will need to be initialized before they can be used.
Recommendations
Structs do not have constructors but you could add a method, for examplewhere you initialize your array with a known size:
private struct Structure2 { public int Size; public int[] Numbers; public void Initialize() { Numbers = new int[10]; } }
and if you need to resize the array you can use Array.Resize.
If you are going to be doing COM Interop or PInvoke you should read about passing arrays in microsoft docs.
If you have structs with fixed sized arrays that you pass to unmanaged code, there is good chance that you will need to add some attributes like:
[StructLayout(LayoutKind.Sequential)] private struct Structure2 { public short Size; [MarshalAs(UnmanagedType.ByValArray, SizeConst=20)] public short[] Numbers; }
Sample VB6
Private Type Structure2 Size As Integer Numbers() As String End Type Private Type Structure1 name As String str2 As Structure2 End Type
Target VB.NET
Private Structure Structure2 Dim Size As Integer Dim Numbers() As String End Structure Private Structure Structure1 Dim name As String 'UPGRADE_WARNING: (1063) Arrays in structure str2 may need to be initialized before they can be used. Dim str2 As Structure2 End Structure
Target C#
[Serializable] private struct Structure2 { public short Size; public string[] Numbers; } [Serializable] private struct Structure1 { public string name; //UPGRADE_WARNING: (1063) Arrays in structure str2 may need to be initialized before they can be used. public Structure2 str2; public static Structure1 CreateInstance() { Structure1 result = new Structure1(); result.name = String.Empty; return result; } }