0

I created a view who have two entry and a button with a command to consume a rest api in my physical device but i got this exception while debugging:

[System.out] [OkHttp] sendRequest<< [apitrace] apitrace: warning: caught signal 11 [apitrace] call flush from exceptionCallback [libc] Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x7ffaf31ff0 in tid 15432 (companyname.add), pid 15432 (companyname.add)

this is the view:


    <ContentPage.Content>
        <StackLayout>
            <Entry Text="{Binding Machine_Qr}"></Entry>
            <Entry Text="{Binding Machine_Name}"></Entry>
            <Button Text="add the machine" Command="{Binding Ajout}"></Button>
        </StackLayout>
    </ContentPage.Content>

this is the View Model:

 public class AjoutMachineVM : BaseViewModel
    {
        public string machine_Name;
        public string machine_Qr;
        IMachineService _rest = DependencyService.Get<IMachineService>();



        public AjoutMachineVM()
        { 
            SaveMachine();
        }

        public async Task SaveMachine()
        {
            try
            {
                var machine = new Machine
                {
                    Machine_Name = machine_Name,
                    Machine_Qr = machine_Qr

                };

                await _rest.AddMachine(machine);

                await Shell.Current.GoToAsync("..");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public string Machine_Qr
        {
            get => Machine_Qr;
            set
            {
                machine_Qr = value;
                NotifyPropertyChanged(nameof(Machine_Qr));
            }
        }
        public string Machine_Name
        {
            get => Machine_Name;
            set
            {
                machine_Name = value;
                NotifyPropertyChanged(nameof(Machine_Name));
            }
        }
        public ICommand Ajout { get; }

    }

and this is the service :

public class MachineService : IMachineService
    {
        public  string Base_url = "http://192.168.1.112:45455/api/";

       public async Task AddMachine(Machine machine)
        {
            string url = Base_url + "machine/creation";

            HttpClient client = new HttpClient();

            var response = await client.PostAsync(url,
                           new StringContent(JsonConvert.SerializeObject(machine), Encoding.UTF8, "application/json"));

        }
    }

the exception comes after exectuting this line in the MachineService class :

 var response = await client.PostAsync(url,
                               new StringContent(JsonConvert.SerializeObject(machine), Encoding.UTF8, "application/json"));
Gazdallah Amira
  • 188
  • 3
  • 16

0 Answers0