3221226107 (0xc000027b) API REST

Krzysztof 0 Reputation points
2023-01-13T13:49:02.3233333+00:00

Hello,

I am a novice programmer. Does anyone know how to solve the problem with 3221226107 (0xc000027b).

Well, after replacing the code in TodoListPage.xaml.cs

from

public partial class TodoListPage : ContentPage
{

    public TodoListPage()
    {

        InitializeComponent();
    }

}

on

public partial class TodoListPage : ContentPage
{
    ITodoService _todoService;

    public TodoListPage(ITodoService todoService)
    {

        InitializeComponent();
        _todoService = todoService;
    }

}

in AppShell.xaml, TodoListPage cannot be selected

    <ShellContent
        Title="Home"
        ContentTemplate="{DataTemplate local:TodoListPage}"
        Route="TodoListPage" />

What causes startup error generates error 3221226107 (0xc000027b)

I found a description of the solution for this error on the throne

[https://blog.infernored.com/net-maui-sounds-amazing-is-it/

But after adding further code in MauiProgram.cs

namespace R4;

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder
            .UseMauiApp<App>()
            .ConfigureFonts(fonts =>
            {
                fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
            });


        //// don't forget to register both the page _and_ the ViewModel
        builder.Services.AddTransient<Views.TodoItemPage>();
        builder.Services.AddTransient<Views.TodoListPage>();
        builder.Services.AddTransient<Services.IRestService, Services.RestService>();
        builder.Services.AddTransient<Services.ITodoService, Services.TodoService>();

        return builder.Build();



    }
}

error 3221226107 (0xc000027b) appears.

Can anyone help me?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,254 questions
Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,181 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,171 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
744 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 64,006 Reputation points Microsoft Vendor
    2023-01-17T06:34:05.73+00:00

    Hello,

    I still have a problem with loading the data. Can anyone tell me how to load data into the list?

    I test your API, your Json data have only one record. And your Json properties are different from your TodoItem.

    Firstly, please change your name of property in the TodoItem like following code.

     public class TodoItem    {
            public int userId { get; set; }
            public int id { get; set; }
            public string title { get; set; }
            public string body { get; set; } 
       }
    

    After that, you will get some errors about Error    CS1061    'TodoItem' does not contain a definition for 'ID', please change these properties from TodoItem.

    Then, open your public async Task<List<TodoItem>> RefreshDataAsync() method in RestService.cs. Based on your API, you just have only one record. You should change Items = JsonSerializer.Deserialize<List<TodoItem>>(content, _serializerOptions); to

     Items.Add(System.Text.Json.JsonSerializer.Deserialize<TodoItem>(content, _serializerOptions));
    

    In the end, please change the binding value from name to title in your TodoListPage

    <Label Text="{Binding title}"    VerticalTextAlignment="Center" />
    

    By the way, if you want to add other records in your API. Such as following Json.

    [
    {
      "userId": 1,  "id": 4,  "title": "this is title1",  "body": "test data"
    },
    {
      "userId": 2,  "id": 4,  "title": "this is title2",  "body": "test data"
    }
    ]
    

    You can use following code to deserialize JSON data in public async Task<List<TodoItem>> RefreshDataAsync() method of RestService.cs.

        //if you have several records in API, you could deserialize to List<TodoItem>
    
        Items=System.Text.Json.JsonSerializer.Deserialize<List<TodoItem>>(content, _serializerOptions);
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.