Bug Report T533783
Visible to All Users

Refactorings - The "Introduce using statement" refactoring works incorrectly when initializing a variable via a property

created 8 years ago (modified 8 years ago)

Hello,

I want to do a refactoring on aConnection using a using statement, but i don't have the choice, to do this.
Here is the code and please see the attachments: CR is Classic CodeRush, CRR is CodeRush for Roslyn

C#
/// <summary> /// lesen eines Datensatzes aus der lokalen Datenbank /// </summary> /// <returns>Dataset mit der geforderten ID</returns> public DsPcWrkAufP1 ReadFromLocal(decimal idWerkauftrag) { var aDataSet = new DsPcWrkAufP1(); var aConnection = PCCommon.Instance.ConnectionMySql; var aCommand = aConnection.CreateCommand(); aCommand.CommandText = String.Format(SQL.selectAuftrag, idWerkauftrag); try { aConnection.Open(); using (var aReader = aCommand.ExecuteReader()) { aDataSet.PCWRKAUFP1.Load(aReader); } } catch (Exception ex) { var st = new StackTrace(); var sf = st.GetFrame(0); var MethodName = sf.GetMethod().Name; var ClassName = sf.GetMethod().DeclaringType.Name; var aMessage = String.Format("{0} ({1}) -> {2}", MethodName, ClassName, ex.Message); LogMe.Instance.LogIt(aMessage); try { var eMail = new MailMessage(); var mailSender = new MailAddress(string.Format("{0}@paulundco.de", PCCommon.Instance.Kostenstelle), string.Format("Kostenstelle {0}", PCCommon.Instance.Kostenstelle)); eMail.From = mailSender; eMail.To.Add(PCCommon.Instance.ErrorMailReceiver); eMail.Subject = string.Format("{0} -> Hostname: {1}", Resources.ErrorMailSubject.Trim(), System.Net.Dns.GetHostName()); eMail.Body = aMessage; var mailClient = new SmtpClient(PCCommon.Instance.MailServer); mailClient.Send(eMail); } catch { } } finally { aConnection.Close(); } return aDataSet;

Thank you
Hans-Peter

Show previous comments (4)
DevExpress Support Team 8 years ago

    Hans-Peter, I have noticed that this ticket is marked as "Private" and thus it is invisible to others. If you do not mind, I would like to make it public so that other customers can view it and track our progress with this issue. If you want me to remove private information from this ticket prior to publishing it, please let me know.

    H H
    Hans-Peter Sannert 8 years ago

      you can remove the private flag

      DevExpress Support Team 8 years ago

        Thank you for your cooperation.

        Answers approved by DevExpress Support

        created 8 years ago (modified 8 years ago)

        We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

        Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

          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.