Open Closed

System.InvalidOperationException: Cannot retrieve property 'Name' because localization failed. #2460


User avatar
0
mostafa_ibrahem22@hotmail.com created
  • ABP Framework version: v5 commercial
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes

hi,

I want to test my api by sending all parameters with null value to check DataAnnotationsLocalization

[06:04:47 INF] Request starting HTTP/2 POST https://localhost:44358/api/main-core/country application/json 198
[06:04:47 INF] CORS policy execution failed.
[06:04:47 INF] Request origin https://localhost:44358 does not have permission to access the resource.
[06:04:47 DBG] PermissionStore.GetCacheItemAsync: pn:U,pk:15b4826b-9071-fdae-7b4a-3a017f5c2255,n:MainCore.Countries
[06:04:47 DBG] Found in the cache: pn:U,pk:15b4826b-9071-fdae-7b4a-3a017f5c2255,n:MainCore.Countries
[06:04:47 DBG] PermissionStore.GetCacheItemAsync: pn:R,pk:admin,n:MainCore.Countries
[06:04:47 DBG] Found in the cache: pn:R,pk:admin,n:MainCore.Countries
[06:04:47 DBG] PermissionStore.GetCacheItemAsync: pn:C,pk:Naama_Swagger,n:MainCore.Countries
[06:04:47 DBG] Found in the cache: pn:C,pk:Naama_Swagger,n:MainCore.Countries
[06:04:47 DBG] PermissionStore.GetCacheItemAsync: pn:U,pk:15b4826b-9071-fdae-7b4a-3a017f5c2255,n:MainCore.Countries.Create
[06:04:47 DBG] Found in the cache: pn:U,pk:15b4826b-9071-fdae-7b4a-3a017f5c2255,n:MainCore.Countries.Create
[06:04:47 DBG] PermissionStore.GetCacheItemAsync: pn:R,pk:admin,n:MainCore.Countries.Create
[06:04:47 DBG] Found in the cache: pn:R,pk:admin,n:MainCore.Countries.Create
[06:04:47 DBG] PermissionStore.GetCacheItemAsync: pn:C,pk:Naama_Swagger,n:MainCore.Countries.Create
[06:04:47 DBG] Found in the cache: pn:C,pk:Naama_Swagger,n:MainCore.Countries.Create
[06:04:47 INF] Executing endpoint 'Naama.MainCore.Lookups.Countries.CountryController.CreateAsync (Naama.MainCore.HttpApi)'
[06:04:47 INF] Route matched with {area = "mainCore", action = "Create", controller = "Country", page = ""}. Executing controller action with signature System.Threading.Tasks.Task`1[Naama.MainCore.Lookups.Countries.CountryDto] CreateAsync(Naama.MainCore.Lookups.Countries.CreateUpdateCountryDto) on controller Naama.MainCore.Lookups.Countries.CountryController (Naama.MainCore.HttpApi).
[06:04:47 INF] Entity Framework Core 6.0.0 initialized 'LanguageManagementDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:6.0.0' with options: QuerySplittingBehavior=SplitQuery 
[06:04:47 INF] Executed DbCommand (2ms) [Parameters=[@__ef_filter__p_0='?' (DbType = Boolean), @__KrJwKRUZe_0='?' (Size = 128), @__FacERZtJZ_1='?' (Size = 10)], CommandType='Text', CommandTimeout='30']
SELECT [a].[Id], [a].[CreationTime], [a].[CreatorId], [a].[CultureName], [a].[LastModificationTime], [a].[LastModifierId], [a].[Name], [a].[ResourceName], [a].[TenantId], [a].[Value]
FROM [AbpLanguageTexts] AS [a]
WHERE ((@__ef_filter__p_0 = CAST(1 AS bit)) OR [a].[TenantId] IS NULL) AND (([a].[ResourceName] = @__KrJwKRUZe_0) AND ([a].[CultureName] = @__FacERZtJZ_1))
[06:04:47 DBG] Added 0 entity changes to the current audit log
[06:04:47 ERR] ---------- RemoteServiceErrorInfo ----------
{
  "code": null,
  "message": "An internal error occurred during your request!",
  "details": null,
  "data": {},
  "validationErrors": null
}
[06:04:47 ERR] Cannot retrieve property 'Name' because localization failed.  Type 'Naama.MainCore.Localization.MainCoreResource' is not public or does not contain a public static string property with the name 'ArabicName'.
System.InvalidOperationException: Cannot retrieve property 'Name' because localization failed.  Type 'Naama.MainCore.Localization.MainCoreResource' is not public or does not contain a public static string property with the name 'ArabicName'.
   at System.ComponentModel.DataAnnotations.LocalizableString.<>c__DisplayClass12_1.<GetLocalizableValue>b__2()
   at System.ComponentModel.DataAnnotations.LocalizableString.GetLocalizableValue()
   at Microsoft.AspNetCore.Mvc.DataAnnotations.DataAnnotationsMetadataProvider.CreateDisplayMetadata(DisplayMetadataProviderContext context)
   at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultCompositeMetadataDetailsProvider.CreateDisplayMetadata(DisplayMetadataProviderContext context)
   at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata.get_DisplayMetadata()
   at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata.get_Order()
   at System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count)
   at System.Linq.OrderedEnumerable`1.ToList()
   at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata.get_Properties()
   at Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.get_BoundProperties()
   at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata.CalculateHasValidators(HashSet`1 visited, ModelMetadata metadata)
   at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata.get_HasValidators()
   at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.VisitImplementation(ModelMetadata& metadata, String& key, Object model)
   at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.Visit(ModelMetadata metadata, String key, Object model)
   at Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.Validate(ModelMetadata metadata, String key, Object model, Boolean alwaysValidateAtTopLevel, Object container)
   at Microsoft.AspNetCore.Mvc.ModelBinding.ObjectModelValidator.Validate(ActionContext actionContext, ValidationStateDictionary validationState, String prefix, Object model, ModelMetadata metadata, Object container)
   at Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder.EnforceBindRequiredAndValidate(ObjectModelValidator baseObjectValidator, ActionContext actionContext, ParameterDescriptor parameter, ModelMetadata metadata, ModelBindingContext modelBindingContext, ModelBindingResult modelBindingResult, Object container)
   at Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder.BindModelAsync(ActionContext actionContext, IModelBinder modelBinder, IValueProvider valueProvider, ParameterDescriptor parameter, ModelMetadata metadata, Object value, Object container)
   at Microsoft.AspNetCore.Mvc.Controllers.ControllerBinderDelegateProvider.<>c__DisplayClass0_0.<<CreateBinderDelegate>g__Bind|0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
[06:04:47 INF] Executing ObjectResult, writing value of type 'Volo.Abp.Http.RemoteServiceErrorResponse'.
[06:04:47 INF] Executed action Naama.MainCore.Lookups.Countries.CountryController.CreateAsync (Naama.MainCore.HttpApi) in 10.3301ms
[06:04:47 INF] Executed endpoint 'Naama.MainCore.Lookups.Countries.CountryController.CreateAsync (Naama.MainCore.HttpApi)'
[06:04:47 DBG] Added 0 entity changes to the current audit log
[06:04:47 INF] Entity Framework Core 6.0.0 initialized 'AbpAuditLoggingDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:6.0.0' with options: QuerySplittingBehavior=SplitQuery 
[06:04:47 INF] Executed DbCommand (4ms) [Parameters=[@p0='?' (DbType = Guid), @p1='?' (Size = 96), @p2='?' (Size = 512), @p3='?' (Size = 64), @p4='?' (Size = 64), @p5='?' (Size = 128), @p6='?' (Size = 256), @p7='?' (Size = 40), @p8='?' (Size = 64), @p9='?' (Size = 4000), @p10='?' (DbType = Int32), @p11='?' (DbType = DateTime2), @p12='?' (Size = 4000), @p13='?' (Size = 16), @p14='?' (DbType = Int32), @p15='?' (DbType = Guid), @p16='?' (DbType = Guid), @p17='?' (DbType = Guid), @p18='?' (Size = 4000), @p19='?' (Size = 256), @p20='?' (DbType = Guid), @p21='?' (Size = 256)], CommandType='Text', CommandTimeout='30']
SET NOCOUNT ON;
INSERT INTO [AbpAuditLogs] ([Id], [ApplicationName], [BrowserInfo], [ClientId], [ClientIpAddress], [ClientName], [Comments], [ConcurrencyStamp], [CorrelationId], [Exceptions], [ExecutionDuration], [ExecutionTime], [ExtraProperties], [HttpMethod], [HttpStatusCode], [ImpersonatorTenantId], [ImpersonatorUserId], [TenantId], [TenantName], [Url], [UserId], [UserName])
VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11, @p12, @p13, @p14, @p15, @p16, @p17, @p18, @p19, @p20, @p21);
[06:04:47 DBG] Added 0 entity changes to the current audit log
[06:04:47 DBG] Added 0 entity changes to the current audit log
[06:04:47 INF] Request finished HTTP/2 POST https://localhost:44358/api/main-core/country application/json 198 - 500 - application/json;+charset=utf-8 31.7985ms

8 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I will check and fix this.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    This problem doesn't seem to be related to ABP, you need to create a resource file.

    Please try to remove the resourceType and custom the DataAnnotationLocalizerProvider func.

    https://github.com/abpframework/abp/blob/29366d4ae0814f1c5a985708ae74d2e0d6897322/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs#L124

    https://stackoverflow.com/questions/37833661/asp-net-core-displayattribute-localization?answertab=votes#tab-top

  • User Avatar
    0
    mostafa_ibrahem22@hotmail.com created

    hi, sorry, I don't understand, why to add ".resx", the ABP use *.json as resources files. kindly please give me exact instructions to follow with abp example.

  • User Avatar
    0
    mostafa_ibrahem22@hotmail.com created

    Kindly any update

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    sorry, I don't understand, why to add ".resx",

    This is the Microsoft design.

    the ABP use *.json as resources files. kindly please give me exact instructions to follow with abp example.

    Please try to remove the resourceType from the displayattribute, ABP will find the resource automatically. See https://github.com/abpframework/abp/blob/29366d4ae0814f1c5a985708ae74d2e0d6897322/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs#L124

  • User Avatar
    0
    mostafa_ibrahem22@hotmail.com created

    I remove resourceType, but stile not working, I use the module template and include the module projects into the application project,

    Main Core module

    application project includes all modules

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you create a simple project via CLI to reproduce the problem and share it with me? liming.ma@volosoft.com

  • User Avatar
    0
    mostafa_ibrahem22@hotmail.com created

    hi maliming Thanks for your support

Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11