Hi . The error dialog still showing after editing code like you suggested.
<TelerikSwitch Value="@item.IsActive" OnLabel=" " OffLabel=" " Size="@ThemeConstants.Switch.Size.Small" OnChange="@(async () => await ToggleStatus(item))"/> </span> private async Task ToggleStatus(ChassisTypeDto item) { try { throw new UserFriendlyException("Test exception"); } catch (UserFriendlyException ex) { Logger.LogError(ex, "Handled UserFriendlyException"); await Notify.Error(string.IsNullOrEmpty(ex.Message) ? L["Messages:Error"] : ex.Message); } catch (Exception e) { Logger.LogError(e, "Error change status container type with id id :{SelectedChassisTypeId}", SelectedChassisTypeId); await Notify.Error(string.IsNullOrEmpty(e.Message) ? L["Messages:Error"] : e.Message); } finally { LoaderVisible = false; } }
Okay, it seems it's all about timing and you need to disable ABP's exception handling system on the UI side. To do that, you can add the following line to both your Blazor.Client
and Blazor
projects' module classes:
public override void ConfigureServices(ServiceConfigurationContext context)
{
//other configs...
context.Services.Replace(ServiceDescriptor.Transient(typeof(IUserExceptionInformer), typeof(NullUserExceptionInformer)));
}
This will replace the UserExceptionInformer
service (https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/ExceptionHandling/UserExceptionInformer.cs), which shows a message dialog by default. If you want you can create your own UserExceptionInformer implementation and then show Notify popup on the bottom-right for each exception.
After the replacement, it should work seamlessly:
Hi, actually, you should have a shared library for your localization files and the related configuration. So, for example, if you move your localization configurations and the related Localization/Resources/Test/*.json
to *.Application.Contracts
it should work.
In summary, you should have a shared library to make these configurations (because normally, Blazor.Client is a Blazor WASM application at its core), and then you can inject the IStringLocalizer<TestResource>
and use it in your blazor application:
1-)
2-) Update the related *.csproj
:
<ItemGroup>
<EmbeddedResource Include="Localization\Resources\Test\*.json" />
<Content Remove="Localization\Resources\Test\*.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="9.0.0" />
</ItemGroup>
<PropertyGroup>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
</PropertyGroup>
3-) Then, use it in your page:
But when I send this dto to create method of service, I get an error of this type: System.InvalidOperationException, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
Hi Murat, API is using the default .NET model binder, and something in your custom attribute is causing a validation metadata exception or reflection issue before the controller is even entered.
There are some checks that you can do:
PspResource
is in a shared project. (It typically should be in *.Domain.Shared
project)[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter,
AllowMultiple = false)]
public class PspRequiredAttribute : RequiredAttribute
{
public PspRequiredAttribute()
{
//ErrorMessageResourceName = nameof(PspResource.RequiredAttribute_ValidationError);
//ErrorMessageResourceType = typeof(PspResource);
}
}
When your API (the backend part) tries to reflect over the DTO, it's trying to fetch the error message string via the
ErrorMessageResourceType
during model binding, and probably this where you get error.
After you have tried these two suggestions, please let me know about the situation. If it's not related to reflection problem, then please share your PspResource
class and give more details (such as where the resource class is defined, where you created the attribute, and any other context)
Regards.
Hi, thanks for the detailed explanation!
I've followed your suggestion and updated the
OnChange
handler to use anasync
lambda as shown:However, I'm still seeing the default error dialog (from ABP) even though the exception is caught and I’m manually showing a toast notification.
And can i ask are there any supported way to disable this dialog globally or override the error handling mechanism or correctly to handle this?
Thanks again for your support!
<TelerikSwitch Value="@item.IsActive" OnLabel=" " OffLabel=" " Size="@ThemeConstants.Switch.Size.Small" OnChange="@(async () => await ToggleStatus(item))" /> private async Task ToggleStatus(ContainerTypeDto item) { try { var messageKey = item.IsActive ? "Delete:ConfirmInactiveMessage" : "Delete:ConfirmActiveMessage"; var message = L[messageKey, L["ContainerType"]]; if (await Dialogs.ConfirmAsync(message, L["Dialog:ConfirmAction"])) { LoaderVisible = true; SelectedContainerTypeId = item.Id.ToString(); await ContainerTypeService.ChangeStatusAsync(Guid.Parse(SelectedContainerTypeId)); var result = await ContainerTypeService.GetListAsync(new ContainerTypeRequestDto()); ContainerTypes = result.Items.ToList(); await Notify.Success(L["Messages:Success"]); } } catch (Exception e) { Logger.LogError(e, "Error changing container type status for ID: {SelectedContainerTypeId}", SelectedContainerTypeId); await Notify.Error(string.IsNullOrEmpty(e.Message) ? L["Messages:Error"] : e.Message); } finally { LoaderVisible = false; } } public async Task ChangeStatusAsync(Guid containerTypeId) { var containerType = await repository.GetAsync(containerTypeId); var hasInUse = await containerRepository .AnyAsync(d => d.ContainerTypeId == containerTypeId && !d.IsDeleted && d.Asset != null && d.Asset.IsActive); if (hasInUse) { throw new BusinessException(TmsSolutionDomainErrorCodes.ContainerTypeIsInUse); } containerType.IsActive = !containerType.IsActive; await repository.UpdateAsync(containerType); }
Hi, you should catch UserFriendlyException
, because ABP shows dialog for this exception type. Can you try like in my suggested code?
Is the next patch release date obvious?
We haven't decided on the date, but it will probably be next week.
Hi,
It works now. Thank you.
There are some enconding characters (%20) at the end of the latest-version.json file url.
Is it possible that the latest version information cannot be obtained because of this when performing an ABP update?
Yes, it might be. I'll check that, thanks for pointing that out 👍
Hi, when using the abp update
command, normally, the command checks the latest stable version from this file and then updates your project.
So, it's really weird to see that. Can you try to update by specifying the version and see if it works for you:
abp update --version 9.1.1
Hi, it's impossible for us to fix the problem with the shared logs. Actually, we are directly using Hangfire's own dashboard UI and you can check their documentation to understand the reason: https://docs.hangfire.io/en/latest/configuration/using-dashboard.html
Please refer to the related documentation, and if you still can't fix your problem, then we can assist you.
Thanks for sharing the test via email. We got your mail and we will evaluate it.