Bug Report T1225402
Visible to All Users

Implement ISerializable - Code provider does not respect the naming convention defined for parameters

created a year ago

Steps to reproduce:

  1. Naming convention for parameters is _PascalCase
  2. Start with the code:
Visual Basic
Imports System.ComponentModel Public Class Class3 Implements INotifyPropertyChanged Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged Protected Sub NotifyPropertyChanged(_PropertyName As String) RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(_PropertyName)) End Sub Private m_Prop1 As String Private m_Prop2 As GenericEventArgs(Of GenericResultFlags) Public Property Prop1 As String Get Return m_Prop1 End Get Set(_Value As String) If m_Prop1 Is _Value Then Return End If m_Prop1 = _Value NotifyPropertyChanged(NameOf(Prop1)) End Set End Property Public Property Prop2 As GenericEventArgs Get Return m_Prop2 End Get Set(_Value As GenericEventArgs) If m_Prop2 = _Value Then Return End If m_Prop2 = _Value NotifyPropertyChanged(NameOf(Prop2)) End Set End Property Public Sub New(ByVal _Prop1 As String, ByVal _Prop2 As GenericEventArgs) m_Prop1 = _Prop1 m_Prop2 = _Prop2 End Sub End Class
  1. Execute the Implement ISerializable code provider

Expected results:

Visual Basic
Protected Sub New(_Info As SerializationInfo, _Context As StreamingContext) If _Info Is Nothing Then Throw New ArgumentNullException(NameOf(_Info), $"{NameOf(_Info)} is null.") End If m_Prop1 = _Info.GetString(NameOf(m_Prop1)) m_Prop2 = CType(_Info.GetValue(NameOf(m_Prop2), GetType(GenericEventArgs)), GenericEventArgs) End Sub Protected Overridable Sub GetObjectData(_Info As SerializationInfo, _Context As StreamingContext) Implements ISerializable.GetObjectData If _Info Is Nothing Then Throw New ArgumentNullException(NameOf(_Info), $"{NameOf(_Info)} is null.") End If _Info.AddValue(NameOf(m_Prop1), m_Prop1) _Info.AddValue(NameOf(m_Prop2), m_Prop2) End Sub

Current results:

Visual Basic
Protected Sub New(info As SerializationInfo, context As StreamingContext) If info Is Nothing Then Throw New ArgumentNullException(NameOf(info), $"{NameOf(info)} is null.") End If m_Prop1 = info.GetString(NameOf(m_Prop1)) m_Prop2 = CType(info.GetValue(NameOf(m_Prop2), GetType(GenericEventArgs)), GenericEventArgs) End Sub Protected Overridable Sub GetObjectData(info As SerializationInfo, context As StreamingContext) Implements ISerializable.GetObjectData If info Is Nothing Then Throw New ArgumentNullException(NameOf(info), $"{NameOf(info)} is null.") End If info.AddValue(NameOf(m_Prop1), m_Prop1) info.AddValue(NameOf(m_Prop2), m_Prop2) End Sub
Comments (1)
DR DR
Duke Rogers 1 a year ago

    I dont know if this helps but I just noticed something. I am the middle of making a custom exception. To Repro, make a new class that inherits from Exception and has 4 private members. haha. I chose Generate All (constructors) from the action context menu , the resulting constructors dont respect my rules. I delete the serialization constructor and then I chose Generate Constructor from the action context menu and i pick my 4 members. haha. When I do this, my rules are respected. I dont know if one is VS and the other CR or what. Below is the resulting code:

    Visual Basic
    Public Class ConversionException Inherits Exception Private m_ExpectedType As Type Private m_InitialType As Type Private m_Message As String Private m_Value As Object Public Sub New() End Sub Public Sub New(message As String) MyBase.New(message) End Sub Public Sub New(message As String, innerException As Exception) MyBase.New(message, innerException) End Sub Public Sub New(_ExpectedType As Type, _InitialType As Type, _Message As String, _Value As Object) ExpectedType = _ExpectedType InitialType = _InitialType Message1 = _Message Value = _Value End Sub End Class

    This is what I expected to get

    Visual Basic
    Public Class ConversionException Inherits Exception Private m_ExpectedType As Type Private m_InitialType As Type Private m_Message As String Private m_Value As Object Public Sub New() End Sub Public Sub New(_Message As String) MyBase.New(_Message) End Sub Public Sub New(_Message As String, _InnerException As Exception) MyBase.New(_Message, _InnerException) End Sub Public Sub New(_ExpectedType As Type, _InitialType As Type, _Message As String, _Value As Object) ExpectedType = _ExpectedType InitialType = _InitialType Message1 = _Message Value = _Value End Sub End Class

    I hope it helps

    Answers approved by DevExpress Support

    created a year ago

    We have addressed the issue described in this ticket and will include a fix in our next maintenance update. Should you need to apply our fix prior to official release, you can request a hotfix here.

    Important Notes:

    • Hotfixes may be unavailable for Early Access/Beta builds or updates set for release within a week.
    • .NET only: in the NuGet Package Manager, use your personal NuGet feed and check the "Include prerelease" option to view the hotfix package in the "Updates" tab.

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.