Warum löst ein Array in einem Couchbase -Dokument eine Ausnahme aus, wenn die Anzahl der Array auf 8 erreicht?C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Warum löst ein Array in einem Couchbase -Dokument eine Ausnahme aus, wenn die Anzahl der Array auf 8 erreicht?

Post by Anonymous »

Ich verwende Couchbase, um Benutzerdaten zu speichern.

Code: Select all


< /code>
Gerätedaten sehen so aus: < /p>
    {
"ClientVersion": "#",
"CreatedAt": "2025-02-20T01:43:09.195092+03:00",
"CreatedBy": null,
"DeletedAt": null,
"DeviceId": "#",
"Id": "c3d1e0e8-d817-4d63-b66b-9112a3676fd8",
"Ip": "#",
"IsMainDevice": true,
"LastOtpVerificationDate": "2025-02-20T01:43:09.195092+03:00",
"Model": "#",
"OperatingSystem": "#",
"OriginalDeviceId": "BA5393F0-D283-4422-A21C-CE4BB8FC95E5",
"Platform": "#",
"SystemVersion": "#",
"UpdatedAt": null,
"UpdatedBy": null,
"Version": "#"
},
{
"ClientVersion": "#",
"CreatedAt": "2025-02-20T01:43:09.195092+03:00",
"CreatedBy": null,
"DeletedAt": null,
"DeviceId": "#",
"Id": "c3d1e0e8-d817-4d63-b66b-9112a3676fd8",
"Ip": "#",
"IsMainDevice": true,
"LastOtpVerificationDate": "2025-02-20T01:43:09.195092+03:00",
"Model": "#",
"OperatingSystem": "#",
"OriginalDeviceId": "BA5393F0-D283-4422-A21C-CE4BB8FC95E5",
"Platform": "#",
"SystemVersion": "#",
"UpdatedAt": null,
"UpdatedBy": null,
"Version": "#"
}, ...
]
}
< /code>
Wie Sie sehen können, wird ein Gerätearray die Geräteinformationen des Benutzers gespeichert. Ich füge ein neues Gerät hinzu, wenn ein neues Gerät erkannt wird. Ich bekomme jedoch eine Ausnahme, wenn die Gerätezahl auf 8 wie folgt erreicht wird: < /p>
 Ausnahme des Typs 'Couchbase.core.Exceptions.invalidargumentException' wurde geworfen. Couchbase.core.retry.retryOrchestrator.retryasync (Bucketbase
Bucket, Ioperation Operation, CancellationTokenpair Tokenpair bei
Couchbase.keyvalue.Couchbasecollection.mutateinasync(string id,
ienumable1 specs, MutateInOptions options)    at Business.Services.UserPasswordService.VerifyOtpForRecoveryAsync(String partnerCode, OtpForPasswordRecoveryRequestDto dto) in /app/Business/Services/UserPasswordService.cs:line 186    at WebAPI.Controllers.V1.PasswordController.VerifyOtpForRecoveryAsync(OtpForPasswordRecoveryRequestDto dto) in /app/WebAPI/Controllers/V1/PasswordController.cs:line 38    at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)    at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask< /code> 1 actionResultvalUeTask) at
microsoft.aspnetcore.mvc.infrastructure.ControllerActionInvoker.g__Awaited|10_ 0ControllerActionInvoker
Invoker, Task LastTask, State Next, Scope Scope Scope, Object, Object, Objekt, boolean
is completed) teure scope, Objekt, boolean
ist completed) teure scope, Objekt, boolean
is completed) teure scope, Objection, boolean
ist completed). />microsoft.aspnetcore.mvc.infrastructure.controlleractionInvoker.rethrow(ActionExecutedContextSealed
context) bei
microsoft.aspnetcore.mvc.infrastructure.controllerVoker. is completed) at
microsoft.aspnetcore.mvc.infrastructure.controllerActionInvoker.g__Awaited & namwitelig. />Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|20_0(ResourceInvoker
invoker, Task lastTask, State next, Scope scope, Object state, Boolean
isCompleted)    at
microsoft.aspnetcore.mvc.infrastructure.resourceInvoker.g__Awaited|17_0(ResourceInvoker
Invoker, Aufgabe, identifizierbarer Bereich) bei
microsoft.aspnetcore.mvc.infrastructure.resourceInvoker.g__Awaited|17_0(ResourcEnvoker
Aufgabe, Task -Task, idisposabler Scope) unter
microSoft.aspnetcore.routing.endpointpointdointpotze.g__aWaWaWaTly.  RequestTask, IloGger Logger) at
Microsoft.aspnetcore.localization.RequestLocalizationMiddleware.invoke(httpContext
context) bei
infra.aspnetcore.middlewares.reBasedAthorization context) />/app/infra.aspnetcore/middlewares/rolebasedAuthorizationMiddleware.cs:line
59 at
infra.aspnetcore.middlewares.RequestLoggermiddleware.invokeasync(httpcontext) Conctextex) in
Conctexe) in
Conctexe) in
contexten) in
contexten) in
contexten) in
contexten) in
contexten) in
in
contexte) in
in
contexten) />/app/infra.aspnetcore/middlewares/RequestLoggermiddleware.cs:line 37

unter webapi.middlewares.sessionContextMiddleware.invoke (httpcontext
Context) in Context in In in Context in In In In In In In In In Context). /App/webapi/middlewares/sesessioncontextmiddleware.cs:line
38 at
infra.aspnetcore.middlewares.Requestinitializermiddleware.invokeasync(httpcontext
contexte) in
/app/infra.aspnetcore/middlewares/requestinitializermiddleware.cs:line
30 at
microsoft.aspnetcore.diagnostics />Infra.AspNetCore.Middlewares.ExceptionHandlerMiddleware.InvokeAsync(HttpContext
context) in
/app/Infra.AspNetCore/Middlewares/ExceptionHandlerMiddleware.cs:line
43

I somehow luckily bemerkte dieses seltsame Verhalten in Test-/Staging-/Produktionsumgebungen. Aber ich bekomme das nicht in der lokalen Umgebung beim Debuggen. < /P>
Hier ist mein Code: < /p>
MutateInSpecBuilder modifyProperties(MutateInSpecBuilder specs)
{
return _deviceService.CreateOrUpdateWithNoCommit(specs, user).Data;
}

var userCollection = await _collectionFactory.GetCollectionAsync(CollectionNames.Users);
await userCollection.MutateInAsync(user.Id, specs => modifyProperties(specs));

public ServiceResult CreateOrUpdateWithNoCommit(MutateInSpecBuilder specs, User user)
{
MutateInSpecBuilder modifyProperties(MutateInSpecBuilder spec)
{
var now = DateTimeOffset.Now;

var registeredDevice = user.Devices.SingleOrDefault(s => s.OriginalDeviceId == originalDeviceId);
if (registeredDevice.IsNull())
{
for (int i = 0; i < user.Devices.Count; i++)
{
spec.Replace($"{nameof(User.Devices)}.[{i}].{nameof(UserDevice.IsMainDevice)}", false);
spec.Replace($"{nameof(User.Devices)}.[{i}].{nameof(UserDevice.DeletedAt)}", now);
user.Devices[i].IsMainDevice = false;
user.Devices[i].DeletedAt = now;
}

var device = new UserDevice
{
Platform = platform,
DeviceId = deviceId,
OriginalDeviceId = originalDeviceId,
SystemVersion = systemVersion,
Model = deviceModel,
OperatingSystem = operationSystem,
ClientVersion = clientVersion,
Version = version,
Ip = ip,
...
};

spec.ArrayAppend(nameof(User.Devices), device);
user.Devices.Append(device);
return spec;
}
}
}
Hat jemand mit diesem seltsamen Problem konfrontiert?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post