Can't get my .NET WPF Application to work with Backendless

The documentation for working with .NET with Backendless is not valid or is outdated, whatever it is, it does not work. The documentation tells us to implement Backendless.App.Init( appId, secretKet, version );, however there is no property called “App”. It is Backendless.InitApp and this method does not take in a third parameter of version. And it never works! It always shows an IOFileNotFoundException. And yes I have added the Backendless.dll reference to my project. Please do help with a solution.

Please use the documentation at: https://backendless.com/docs/dotnet/doc.html

Make sure to get the Backendless SDK for .NET from NuGet:

Let us know if you run into any problems.

Regards,
Mark

Hi Mark

I have problem with my WPF application in C# .Net . I cant seem to retrieve information from the database into my WPF application. I wanted to display information in a text block. Please help me.

Hi, @Onalerona_Gabanakgosi

Please, provide us with the simple code request that does not work for you? Or provide us with the steps which lead to the issue. Do you use UI-Builder?

Regards,
Marina

Hi @Marina.Rudenko

I followed the example on Backendless’s YouTube page but it was for a console application. When I try to incorporate the same steps into my WPF application, the app doesn’t successfully build. I dont know if its because of the async method, because I realized that in the youtube video ‘Console.Readline();’ is essential because of the async method but I dont know why in my WPF pplication it can’t seem to work. Please Help me @Marina.Rudenko I’m in a desperate position now

Your assistance will be highly appreciated.

@Onalerona_Gabanakgosi

Have you seen this documentation?

Client-side Setup - Backendless SDK for .NET API Documentation

What errors do you see? Any additional information you can give us will help us understand your problem more quickly and help you.

Regards

Hi @Marina.Rudenko

This is the error:

Severity Code Description Project File Line Suppression State
Error Could not copy obj\Debug\WpfApp1.exe to bin\Debug\WpfApp1.exe. Exceeded retry count of 10. Failed. The file is locked by: WpfApp1 (20188), WpfApp1 (19544) WpfApp1

I did follow the documentation and did as instructed.

@Onalerona_Gabanakgosi, I have just searched on your issue and found these solutions:

c# - Visual Studio "Could not copy" .... during build - Stack Overflow

Also, to make sure the issue is not related to Backendless, comment out the code which uses Backendless and try running the application.

Regards,
Marina

Hi @Marina.Rudenko

I created another project and didn’t include The Backendless code and it runs ok, but as soon as I include code for Backendless it runs once and doesnt retrieve information from the database and when I run the second time the error appears. So I think its because of an exception during the build process. I think the problem is with getting information from the database and displaying it into a Text Block. The issue is I’m using a WPF Application and not a console application, so I can’t seem to understand what I need to code to insert info from the database into my Text Block and displaying it. From inside the async method ‘private async void GetPeople()’ instead of Console.Writeline(“name” + person[“name”]); I used txtBlock = “” + person[“name”]; and in the Mainwindow constructor i coded: new MainWindow().GetPeople(); then Console.ReadLine() as I didnt know what to code in WPF to be able to retrieve the Information and Display it.

I hope you understand my query and your assistance will be Highly appreciated.

Hello, @Onalerona_Gabanakgosi.

Please provide an example of used code, we will investigate your issue.

Best regards, Nikita.

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Backendless.URL = “https://eu-api.backendless.com”;
BackendlessAPI.Backendless.InitApp(“", "*”);

    }

    private void SubmitBtn_Click(object sender, RoutedEventArgs e)
    {
        new MainWindow().GetPeople();
        Console.ReadLine();

    }


     private async void GetPeople()
     {
         var people = await BackendlessAPI.Backendless.Data.Of("Person").FindAsync();

         foreach (var person in people)
         {
            txtBlockN.Text =""+ person["name"];
         }
     }

}

txBlockN is the name of TextBlock in the XAML File and private void SubmitBtn_Click(object sender, RoutedEventArgs e) is a click event of a button

Hi @Nikita_Fedorishchev

To simplify my query, I need to know how to Display information from my Backendless database into my WPF aplication.

I was unable to reproduce your error. To display information you can use the following:

var people = await Backendless.Data.Of( "Person" ).FindAsync();
      
foreach(var person in people )
  foreach( KeyValuePair<String, Object> kvp in person )
    txtBlockN.Text +="\n" + kvp.Value;

Also you don’t need create new instance of MainWindow:

private void SumbitBtn_Click(Object sender, RoutedEventArgs e )
{
  GetPeople();
}

Hi @Nikita_Fedorishchev

I used F11 to step into the code to see where it breaks. It throws an exception by: var people = await Backendless.Data.Of( “Person” ).FindAsync();

What error are you getting?

System.NullReferenceException: ‘Object reference not set to an instance of an object.’

Hi @Nikita_Fedorishchev

Here is all my code:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
try
{
Backendless.URL = “https://eu-api.backendless.com”;
BackendlessAPI.Backendless.InitApp(“1383E4DA-C18B-D6CF-FF38-556A8374B000”, “531BA538-FE58-4421-A441-4924492F07D3”);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

    }

    private void SubmitBtn_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            GetPeople();
            Console.ReadLine();
            
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

    }


     private async void GetPeople()
     {
        try
        {
            var people = await Backendless.Data.Of("Person").FindAsync();
            foreach (var person in people)
            {
                foreach (KeyValuePair<String, Object> kvp in person)
                {
                    try
                    {
                        txtBlockN.Text += "\n" + kvp.Value;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }

            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
}

@Onalerona_Gabanakgosi, your application is on a US cluster, but you are using a URL for the EU.
Remove the line:
Backendless.URL = “https://eu-api.backendless.com”;

Hi @Nikita_Fedorishchev

Thanks For your assistance. The program just started displaying, but the programs is displaying the date, objectID and names in the column ‘name’ and once its done it closes my window and reopens it. Is it because of these lines of code: ```
foreach (KeyValuePair<String, Object> kvp in person)
{
try
{
txtBlockN.Text += “\n” + kvp.Value;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

}


Sorry for being such a nuisance its just that I'm under pressure to get this application working.
I highly appreciate your assistance.

Hi @Marina.Rudenko

Thank you very much for your assistance. I got it to work, you’re a life saver :slightly_smiling_face: