-1

in below code

public partial class UC_Home : UserControl
{
     static byte[] Data_From_Class_library { get; set; }
    string resultedStr { get; set; }


    public UC_Home()
    {
        InitializeComponent();


    }


    public UC_Home(byte[] _data_From_Main_Form)
        :this()
    {
        Data_From_Class_library = _data_From_Main_Form;

    }


    private void UC_Home_Load(object sender, EventArgs e)
    {
   
        if(Data_From_Class_library != null)
        {
            resultedStr = BitConverter.ToString(Data_From_Class_library);
        }

    }
}

as you can see i get some information and convert them to a string

in debug mode if i put a breakpoint before converting bytes to string and continue the debug with the F11 key, when i cross over the below code :

  (  ==> breakpoint is here )

            resultedStr = BitConverter.ToString(Data_From_Class_library);

the values convert succesfully (refer to the below picture) enter image description here

but if i put a breakpoint after the below code :

            resultedStr = BitConverter.ToString(Data_From_Class_library);
   
(  ==> breakpoint is here )

         
   

when i hit the breakpoint the converted results are zero (refer to below picture)

enter image description here

this behavior shows that program working differently in running mode and debugging mode why is that? and how can i solve it?

  • Ok, what is resultedStr ? Did you initialize it before ? I think at some point, you intialized resultedStr at some point we cannot see right here. Could you post the snippet where the initialization of resultedStr is located ? This would be helpful. – Animalz Aug 23 '23 at 09:19
  • Are you running a debug build or are you trying to debug a release build? – PMF Aug 23 '23 at 09:25
  • @Animalz i edited the post and added the location of ( resultedStr ) – shayan ghezelbash Aug 23 '23 at 12:37
  • @PMF I'm not quite sure what you mean but i think debug build – shayan ghezelbash Aug 23 '23 at 12:42
  • 3
    The first breakpoint is hit **before** `resultedStr` is assigned, which means that the value it has at that point is from a **previous** assignment. – Lasse V. Karlsen Aug 23 '23 at 13:03

0 Answers0