Base solution for your next web application
Open Closed

Maui Page Route Error & File Save Issue #12504


User avatar
0
stanley5389 created

Hi, I'm facing Issue Maui project Shows Route Issue but Project Running fine. My Project Was .Net Angular Seprated The Developer Menu Save Function not working.[Where ever I use File type same problem]

Power Tool Navigation Property I choose Dropdown or Typeahead Error. LookupTable Working Fine.

If you want I'll share my code.

Error: The type 'Pages' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

8 Answer(s)
  • User Avatar
    0
    stanley5389 created

    Hello?

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @stanley5389

    You need to add the [Area("App")] attribute to your controller to fix the file upload issue.

    Example:

    [Area("App")]
    [AbpMvcAuthorize(AppPermissions.Pages_Developers)]
    public class DevelopersController : ExcelImportControllerBase
    {
        // ...
    }
    

    Without this, the route will not match and you'll get a 404 error when uploading files.

    The error XL50414: The type 'Pages' was not found means that the type you're referring to in your XAML is not correctly defined or referenced. Specifically, this line:

    ComponentType="{x:Type local:Pages_Routes}"
    

    is causing the issue.

    To fix this:

    1. Make sure Pages.Routes is a valid class that is:

      • public
      • Not partial without implementation
      • Exists in the namespace CoreSync.Maui (if you're using clr-namespace:CoreSync.Maui).
    2. If Routes is in another namespace like CoreSync.Maui.Pages, update your XAML accordingly:

    xmlns:pages="clr-namespace:CoreSync.Maui.Pages"
    ...
    ComponentType="{x:Type pages:Routes}"
    

    MainPage.xml

    <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:local="clr-namespace:CoreSync.Maui"
                 xmlns:pages="clr-namespace:CoreSync.Maui.Pages"
                 x:Class="CoreSync.Maui.MainPage"
                 BackgroundColor="{DynamicResource PageBackgroundColor}">
    
        <BlazorWebView x:Name="BlazorWebView">
            <BlazorWebView.RootComponents>
                <RootComponent Selector="#app" ComponentType="{x:Type pages:Routes}" />
            </BlazorWebView.RootComponents>
        </BlazorWebView>
    
    </ContentPage>
    

    The file upload issue you mentioned is not a problem in the latest version. If any errors are encountered after a detailed review, we will create an issue. Thank you for your feedback. If the issue persists, please feel free to contact us.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    stanley5389 created

    Thanks for the update. Works. If I add [Area("App")] Angular project throws permission error this method GetFileAllowedTypes()

    If I remove [Area("App")] this working fine

    using Abp.AspNetCore.Mvc.Authorization; using Abp.BackgroundJobs; using Abp.IO.Extensions; using Abp.UI; using Abp.Web.Models; using CoreSync.Authorization; using CoreSync.DataImporting.Excel; using CoreSync.Property; using CoreSync.Storage; using CoreSync.Storage.FileValidator; using CoreSync.Web.Controllers; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System; using System.IO; using System.Linq; using System.Threading.Tasks;

    namespace CoreSync.Web.Controllers; [Area("App")] [AbpMvcAuthorize(AppPermissions.Pages_Addresses)] [Authorize] public class AddressesController : ExcelImportControllerBase { private readonly ITempFileCacheManager _tempFileCacheManager;

    private const long MaxFileLength = 5242880; //5MB
    private const string MaxFileLengthUserFriendlyValue = "5MB"; //5MB
    private readonly string[] AllowedFileTypes = { "jpeg", "jpg", "png", "pdf" };
    
    protected readonly IBinaryObjectManager _binaryObjectManager;
    protected readonly IBackgroundJobManager _backgroundJobManager;
    
    public override string ImportExcelPermission => AppPermissions.Pages_Addresses_Create;
    
    private readonly IFileValidatorManager _fileValidatorManager;
    
    public AddressesController(ITempFileCacheManager tempFileCacheManager, IBinaryObjectManager binaryObjectManager, IBackgroundJobManager backgroundJobManager, IFileValidatorManager fileValidatorManager) : base(binaryObjectManager, backgroundJobManager, fileValidatorManager)
    {
        _tempFileCacheManager = tempFileCacheManager;
        _fileValidatorManager = fileValidatorManager;
    }
    
    public FileUploadCacheOutput UploadFile()
    {
        try
        {
            //Check input
            if (Request.Form.Files.Count == 0)
            {
                throw new UserFriendlyException(L("NoFileFoundError"));
            }
    
            var file = Request.Form.Files.First();
            if (file.Length > MaxFileLength)
            {
                throw new UserFriendlyException(L("Warn_File_SizeLimit", MaxFileLengthUserFriendlyValue));
            }
    
            var fileType = Path.GetExtension(file.FileName).Substring(1);
            if (AllowedFileTypes != null && AllowedFileTypes.Length > 0 && !AllowedFileTypes.Contains(fileType))
            {
                throw new UserFriendlyException(L("FileNotInAllowedFileTypes", AllowedFileTypes));
            }
    
            var validationResult = _fileValidatorManager.ValidateAll(new FileValidateInput(file));
    
            byte[] fileBytes;
            using (var stream = file.OpenReadStream())
            {
                fileBytes = stream.GetAllBytes();
            }
    
            var fileToken = Guid.NewGuid().ToString("N");
            _tempFileCacheManager.SetFile(fileToken, new TempFileInfo(file.FileName, fileType, fileBytes));
    
            return new FileUploadCacheOutput(fileToken);
        }
        catch (UserFriendlyException ex)
        {
            return new FileUploadCacheOutput(new ErrorInfo(ex.Message));
        }
    }
    
    public string[] GetFileAllowedTypes()
    {
        return AllowedFileTypes;
    }
    
    public override async Task EnqueueExcelImportJobAsync(ImportFromExcelJobArgs args)
    {
        await BackgroundJobManager.EnqueueAsync&lt;ImportAddressesToExcelJob, ImportFromExcelJobArgs&gt;(args);
    }
    

    }

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    stanley5389 created

    Hello, Can you give an Update ASAP. Thanks.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @stanley5389

    You need to edit the endpoint on the Angular side. Here, when sending a request, add the "/app" area name on prefix after the serviceBaseUrl.

    I will open a fix issue for this situation, so there will be no need to fix them manually in the next version.

    Thank You.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    stanley5389 created

    Where to add exactly? If I add appsettings crash. If I modify below crash.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @stanley5389

    As shown in the screenshot below, removing the "app/" part in the UploadFile method inside ProxyDevelopersControllerService on the MAUI side will resolve your file upload issue. In fact, no changes will be needed in the DevelopersController on the backend. This will also make the previous suggestion unnecessary.

    So the updated code will be like this.

    ProxyDevelopersControllerService.cs

    public class ProxyDevelopersControllerService : ProxyAppServiceBase
    {
    
        public async Task<FileUploadCacheOutput> UploadFile(Stream stream, string fileName)
        {
            return await ApiClient.PostMultipartAsync<FileUploadCacheOutput>(
                "Developers/" + nameof(UploadFile),
                stream,
                fileName
            );
        }
    }
    

    DevelopersController.cs

    [Authorize]
    public class DevelopersController : ExcelImportControllerBase
    {
        //...
    }
    
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    stanley5389 created

    Perfect. Works. Thanks.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)