Request body too large - servicestack

When I try to upload a 80mb file from postman to my local endpoint running in Visual Studio 2019 on IISExpress I get the following error:
The request filtering module is configured to deny a request that exceeds the request content length.
So I added this to applicationhost.config for the project:
<system.web>
<httpRuntime maxRequestLength="1050000" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824"/>
</requestFiltering>
</security>
This stop the error coming when I make the API request but now I just get a ServiceStack generated "snapshot" page telling me how long request took and the date but my actual endpoint is never hit.
Inside my logs I can see ServiceStack throwing this exception:
2020-07-20 01:57:56.0497||ERROR|ServiceStackHost|Request body too
large. Microsoft.AspNetCore.Server.IIS.BadHttpRequestException:
Request body too large. at
Microsoft.AspNetCore.Server.IIS.BadHttpRequestException.Throw(RequestRejectionReason
reason) at
Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.InitializeRequestIO()
at
Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.ReadAsync(Memory1 memory, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.IIS.Core.HttpRequestStream.ReadAsyncInternal(Memory1
buffer, CancellationToken cancellationToken) at
Microsoft.AspNetCore.WebUtilities.BufferedReadStream.EnsureBufferedAsync(Int32
minCount, CancellationToken cancellationToken) at
Microsoft.AspNetCore.WebUtilities.MultipartReaderStream.ReadAsync(Byte[]
buffer, Int32 offset, Int32 count, CancellationToken
cancellationToken) at
Microsoft.AspNetCore.WebUtilities.StreamHelperExtensions.DrainAsync(Stream
stream, ArrayPool1 bytePool, Nullable1 limit, CancellationToken
cancellationToken) at
Microsoft.AspNetCore.WebUtilities.MultipartReader.ReadNextSectionAsync(CancellationToken
cancellationToken) at
Microsoft.AspNetCore.Http.Features.FormFeature.InnerReadFormAsync(CancellationToken
cancellationToken) at
Microsoft.AspNetCore.Http.Features.FormFeature.ReadForm() at
Microsoft.AspNetCore.Http.DefaultHttpRequest.get_Form() at
ServiceStack.Host.NetCore.NetCoreRequest.get_FormData() in
C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\Host\NetCore\NetCoreRequest.cs:line
167 at
ServiceStack.HttpRequestExtensions.GetFlattenedRequestParams(IRequest
request) in
C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\HttpRequestExtensions.cs:line
555 at ServiceStack.Host.RestHandler.CreateRequestAsync(IRequest
httpReq, IRestPath restPath) in
C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\Host\RestHandler.cs:line
132 at ServiceStack.Host.RestHandler.ProcessRequestAsync(IRequest
req, IResponse httpRes, String operationName) in
C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\Host\RestHandler.cs:line
89|url: |action:
So the Body length still needs to be set somewhere but everywhere I look points back to the config I have already used.
Is there additional setting required or is this a ServiceStack issue?

I was missing this option in startup:
services.Configure<IISServerOptions>(options =>
{
options.MaxRequestBodySize = int.MaxValue;
});
services.Configure<KestrelServerOptions>(options =>
{
options.Limits.MaxRequestBodySize = int.MaxValue; // if don't set default value is: 30 MB
});

Related

Azure Managed Identity Token couldn't produce from local

This is a continuation of the ticket Restrict Access with Azure Managed Identity in .NET Core Web API where I configured a .NET Core Web API to secured with user-assigned Azurre Managed Identity. This Web API has been deployed as https://epd-api.azurewebsites.net.
Now I have a locally running/debugging .NET Core WebApp trying to access the managed identity token for above azue deployed Web API as below.
string userAssignedClientId = "<<managed-identity clientid>>";
var credential = new DefaultAzureCredential(new DefaultAzureCredentialOptions { ManagedIdentityClientId=userAssignedClientId });
var accessToken = await credential.GetTokenAsync(new TokenRequestContext(new[] { "https://epd-api.azurewebsites.net/.default" }));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Token);
It's breaking at line 'credential.GetTokenAsync()' with below exceptionn message.
AuthenticationFailedException: Azure CLI authentication failed due to
an unknown error. See the troubleshooting guide for more information.
https://aka.ms/azsdk/net/identity/azclicredential/troubleshoot ERROR:
The command failed with an unexpected error. Here is the traceback:
ERROR: Get Token request returned http error: 400 and server response:
{"error":"invalid_resource","error_description":"AADSTS500011: The
resource principal named https://epd-api.azurewebsites.net was not
found in the tenant named DXC Production. This can happen if the
application has not been installed by the administrator of the tenant
or consented to by any user in the tenant. You might have sent your
authentication request to the wrong tenant.\r\nTrace ID:
b537e8c2-c1a8-44ff-a363-d162cd15e101\r\nCorrelation ID:
507df083-138c-4848-b446-40631732a181\r\nTimestamp: 2022-09-13
06:52:22Z","error_codes":[500011],"timestamp":"2022-09-13
06:52:22Z","trace_id":"b537e8c2-c1a8-44ff-a363-d162cd15e101","correlation_id":"507df083-138c-4848-b446-40631732a181","error_uri":"https://login.microsoftonline.com/error?code=500011"}
Traceback (most recent call last):
Once I deployed my Web APP in Azure, the error message is different as below.
Connection ID "15636497907840976997", Request ID
"80000866-0000-d900-b63f-84710c7967bb": An unhandled exception was
thrown by the application.
Exception: Azure.Identity.AuthenticationFailedException:
ManagedIdentityCredential authentication failed: Service request
failed. Status: 500 (Internal Server Error)
Content:
Headers: Date: Tue, 13 Sep 2022 07:39:11 GMT Server: Kestrel
Transfer-Encoding: chunked X-CORRELATION-ID: REDACTED Content-Type:
application/json; charset=utf-8
See the troubleshooting guide for more information.
https://aka.ms/azsdk/net/identity/managedidentitycredential/troubleshoot
---> Azure.RequestFailedException: Service request failed. Status: 500 (Internal Server Error)
Content:
Headers: Date: Tue, 13 Sep 2022 07:39:11 GMT Server: Kestrel
Transfer-Encoding: chunked X-CORRELATION-ID: REDACTED Content-Type:
application/json; charset=utf-8
at Azure.Identity.ManagedIdentitySource.HandleResponseAsync(Boolean
async, TokenRequestContext context, Response response,
CancellationToken cancellationToken) at
Azure.Identity.ManagedIdentitySource.AuthenticateAsync(Boolean async,
TokenRequestContext context, CancellationToken cancellationToken)
at Azure.Identity.ManagedIdentityClient.AuthenticateAsync(Boolean
async, TokenRequestContext context, CancellationToken
cancellationToken) at
Azure.Identity.ManagedIdentityCredential.GetTokenImplAsync(Boolean
async, TokenRequestContext requestContext, CancellationToken
cancellationToken) --- End of inner exception stack trace --- at
Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow(Exception
ex, String additionalMessage) at
Azure.Identity.ManagedIdentityCredential.GetTokenImplAsync(Boolean
async, TokenRequestContext requestContext, CancellationToken
cancellationToken) at
Azure.Identity.ManagedIdentityCredential.GetTokenAsync(TokenRequestContext
requestContext, CancellationToken cancellationToken) at
Azure.Identity.DefaultAzureCredential.GetTokenFromSourcesAsync(TokenCredential[]
sources, TokenRequestContext requestContext, Boolean async,
CancellationToken cancellationToken) at
Azure.Identity.DefaultAzureCredential.GetTokenImplAsync(Boolean async,
TokenRequestContext requestContext, CancellationToken
cancellationToken) at
Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow(Exception
ex, String additionalMessage) at
Azure.Identity.DefaultAzureCredential.GetTokenImplAsync(Boolean async,
TokenRequestContext requestContext, CancellationToken
cancellationToken) at
Azure.Identity.DefaultAzureCredential.GetTokenAsync(TokenRequestContext
requestContext, CancellationToken cancellationToken) at
ManagedIdentityWeb.Pages.IndexModel.OnGetAsync() in
C:\Users\jmathews4\Source\Repos\ManagedIdentityAPI\ManagedIdentityWeb\Pages\Index.cshtml.cs:line
36 at
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory.NonGenericTaskHandlerMethod.Execute(Object
receiver, Object[] arguments) at
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeHandlerMethodAsync()
at
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeNextPageFilterAsync()
at
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Rethrow(PageHandlerExecutedContext
context) at
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Next(State&
next, Scope& scope, Object& state, Boolean& isCompleted)
at
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeInnerFilterAsync()
at
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker
invoker, Task lastTask, State next, Scope scope, Object state, Boolean
isCompleted) at
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed
context) at
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State&
next, Scope& scope, Object& state, Boolean& isCompleted)
at
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker
invoker, Task lastTask, State next, Scope scope, Object state, Boolean
isCompleted) at
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker
invoker, Task task, IDisposable scope) at
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker
invoker, Task task, IDisposable scope) at
Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint
endpoint, Task requestTask, ILogger logger) at
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext
context) at
Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()
Any clue here for troubleshoot?
It's trying to use the AZ CLI there and its refresh token has expired. Run az login again in the command line and try again.

Acumatica and System Crash related to Push Notification Dispatch Errors

Does anyone understand this error or how to further troubleshoot? I see it on the system monitor screen, and the site crashes seconds after this error.
Level: Error
Source: PushNotifications
Event: Push notification queue dispatcher failed
Link to Screen: ~/Main?ScreenId=SM302010
Message: Push notification queue dispatcher failed TenantID:null, TransactionID:null
TenantID =
ContextScreenId = SM302010
SourceContext = PushNotifications
EventID = PushNotifications_DispatcherFailedEventId
Exception = System.Messaging.MessageQueueException (0x80004005): Operation was cancelled before it could be completed.
at System.Messaging.MessageEnumerator.MoveNext(TimeSpan timeout)
at PX.Data.PushNotifications.MsmqExtensions.MoveNextWithCancellation(MessageEnumerator queueObserver, CancellationToken cancellationToken, Nullable`1 timeout, Action`1 heartBeatDelegate)
at PX.PushNotifications.PrimaryQueue.MsmqPrimaryNotificationQueue.TryDropUnmatchedCommitFromBeginOfQueue(MessageEnumerator queueObserver, CancellationToken cancellationToken)
at PX.PushNotifications.PrimaryQueue.MsmqPrimaryNotificationQueue.TryGetNextTransactionId(CancellationToken cancellationToken, Message& message)
at PX.PushNotifications.PrimaryQueue.MsmqPrimaryNotificationQueue.ReadNextMessageTransaction(CancellationToken cancellationToken, EventsTransaction& messages)
at PX.PushNotifications.NotificationQueueDispatcher.ReadNextTransaction(CancellationToken cancellationToken, EventsTransaction& transaction)
at PX.PushNotifications.NotificationQueueDispatcher.Dispatch(CancellationToken cancellationToken)
This can error arise when site is restarted by IIS. I suppose your site crashes and this error was logged as the result of crash.

ServiceStack logging request body under load issue?

Switched on request logging of body and in development it works fine. Testing now under load and getting error in my log4net logs.
ERROR 17-10-2019 14:34:44 ServiceStack.ServiceStackHost [50] - ServiceBase<TRequest>::Service Exception System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'The stream with Id eacfc65d-dcfc-45dd-906b-ddbdb9dd025b and Tag is disposed.'.
at ServiceStack.Text.RecyclableMemoryStream.CheckDisposed() in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\RecyclableMemoryStream.cs:line 1393
at ServiceStack.Text.RecyclableMemoryStream.set_Position(Int64 value) in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\RecyclableMemoryStream.cs:line 1017
at ServiceStack.StreamExtensions.ReadToEnd(MemoryStream ms, Encoding encoding) in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\StreamExtensions.cs:line 363
at ServiceStack.StreamExtensions.ReadToEnd(Stream stream, Encoding encoding) in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\StreamExtensions.cs:line 442
at ServiceStack.Host.NetCore.NetCoreRequest.GetRawBody() in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\Host\NetCore\NetCoreRequest.cs:line 207
at RvRequestLogger.DbRequestLogger.CreateEntry(IRequest request, Object requestDto, Object response, TimeSpan requestDuration, Type requestType) in /opt/atlassian/pipelines/agent/build/RvRequestLogger/DbRequestLogger.cs:line 129
at RvRequestLogger.DbRequestLogger.Log(IRequest request, Object requestDto, Object response, TimeSpan elapsed) in /opt/atlassian/pipelines/agent/build/RvRequestLogger/DbRequestLogger.cs:line 47
at ServiceStack.HttpExtensions.EndHttpHandlerRequestAsync(IResponse httpRes, Boolean skipHeaders, Boolean skipClose, Func`2 afterHeaders) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\HttpExtensions.cs:line 121
at ServiceStack.HttpResponseExtensionsInternal.WriteToResponse(IResponse response, Object result, StreamSerializerDelegateAsync defaultAction, IRequest request, Byte[] bodyPrefix, Byte[] bodySuffix, CancellationToken token) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\HttpResponseExtensionsInternal.cs:line 364
at ServiceStack.Validation.ValidationFilters.RequestFilterAsync(IRequest req, IResponse res, Object requestDto, Boolean treatInfoAndWarningsAsErrors) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\Validation\ValidationFilters.cs:line 65
Now my DbRequestLogger line 129 is doing this, GetRawBody;
if (EnableRequestBodyTracking)
{
#if NETSTANDARD2_0
// https://forums.servicestack.net/t/unexpected-end-of-stream-when-uploading-to-aspnet-core/6478/6
if (!request.ContentType.MatchesContentType(MimeTypes.MultiPartFormData))
{
entry.RequestBody = request.GetRawBody();
}
#else
entry.RequestBody = request.GetRawBody();
#endif
}
This might be related to this post https://forums.servicestack.net/t/unexpected-end-of-stream-when-uploading-to-aspnet-core/6478/8
Any ideas? Seems the request has passed us by at this point.

Invalid Character reading xml file from Azure ServiceFabric Service

When I add Swagger (v2.5) on any Web Api service of my Azure ServiceFabric cluster, and the swagger documentation file contains accent marks (á, é, í...), I get this error:
Invalid character in the given encoding
I was passing the uri (path) of the xml file to swagger:
services.AddSwaggerGen(options =>
{
...
options.IncludeXmlComments(myxmlpath);
...
}
But according to this post I should pass a StreamReader to specify the encoding, so I swapped the code for this:
services.AddSwaggerGen(options =>
{
...
options.IncludeXmlComments(() => new XPathDocument(
new StreamReader(myxmlpath, Encoding.UTF8)));
...
}
In this way I managed to avoid the error, but in the swagger UI I see strange characters. For example, instead of áéíóú it shows:
����������
I don't understand why it works in my local cluster but it gives me encoding issues in my Azure cluster. I have not managed to reproduce the error in my local cluster.
Why the file parsing depends in any way on the node where the service is deployed (local or Azure)?
This is my entire stack trace before swapping the code:
Unhealthy event: SourceId='System.RA', Property='ReplicaOpenStatus', HealthState='Warning', ConsiderWarningAsError=false.
Replica had multiple failures during open on mynode01. API call: IStatelessServiceInstance.Open(); Error = System.Xml.XmlException (-2146232000)
Invalid character in the given encoding. Line 35, position 12.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
at System.Xml.XmlTextReaderImpl.InvalidCharRecovery(Int32& bytesCount, Int32& charsCount)
at System.Xml.XmlTextReaderImpl.GetChars(Int32 maxCharsCount)
at System.Xml.XmlTextReaderImpl.ReadData()
at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars)
at System.Xml.XmlTextReaderImpl.ParseText()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XPath.XPathDocument.LoadFromReader(XmlReader reader, XmlSpace space)
at System.Xml.XPath.XPathDocument..ctor(String uri, XmlSpace space)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions.<>c__DisplayClass31_0.b__0()
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions.CreateSwaggerProvider(IServiceProvider serviceProvider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.Internal.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass4_0.b__0(RequestDelegate next)
at Microsoft.AspNetCore.Builder.Internal.ApplicationBuilder.Build()
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
at Microsoft.AspNetCore.Hosting.Internal.WebHost.StartAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.Start()
at Microsoft.ServiceFabric.Services.Communication.AspNetCore.AspNetCoreCommunicationListener.OpenAsync(CancellationToken cancellationToken)
at Microsoft.ServiceFabric.Services.Runtime.StatelessServiceInstanceAdapter.OpenCommunicationListenersAsync(CancellationToken cancellationToken)
at Microsoft.ServiceFabric.Services.Runtime.StatelessServiceInstanceAdapter.System.Fabric.IStatelessServiceInstance.OpenAsync(IStatelessServicePartition partition, CancellationToken cancellationToken)
For more information see: http://aka.ms/sfhealth
I finally found the problem. It was not a problem in the Azure environment. I had a release step in VSTS Replace Tokens with the Files Encoding option in auto. I changed it to utf-8 and it works!

Visual Studio Team Services Build - Error 500 (was Visual Studio Online - VSO)

I don't know how to change or track the agent, or identify the reason of this error.
C:\a\1\s\RadMVCLab\Scripts\jquery.datatables\examples\examples_support\themes\smoothness\images\ui-bg_glass_95_fef1ec_1x400.png: Please contact your administrator. There was an error contacting the server.
Technical information (for administrator):
HTTP code 500: Internal Server Error
System.Exception: One or more errors occurred while performing a get operation for workspace ws_1_1;1c6d9554-2472-4494-8d67-d17901ca66b2
at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.TfvcGetOperation.Execute(String sourceVersion)
at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.TfvcHelper.SyncRepository(VersionControlServer server, Uri repositoryUrl, String workspaceName, String rootPath, WorkingFolder[] workingFolders, String sourceVersion, Boolean cleanRepository, String shelveset, String reshelveName, Boolean gatedRunCI, CancellationToken cancellationToken)
at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.TfvcHelper.Sync(ITaskEndpoint endpoint, String localPath, Dictionary2 serverPathMapping, String sourceVersion, Boolean cleanRepository, String workspaceName, String shelveset, String reshelveName, Boolean runCI, CancellationToken cancellationToken)
at Microsoft.TeamFoundation.DistributedTask.Plugin.Build.TfvcSourceProvider.<>c__DisplayClass3_0.<PrepareRepositoryAsync>b__0()
Microsoft.TeamFoundation.DistributedTask.Agent.Common.AgentExecutionTerminationException: Prepare repository failed with exception. ---> System.Exception: One or more errors occurred while performing a get operation for workspace ws_1_1;1c6d9554-2472-4494-8d67-d17901ca66b2
at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.TfvcGetOperation.Execute(String sourceVersion)
at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.TfvcHelper.SyncRepository(VersionControlServer server, Uri repositoryUrl, String workspaceName, String rootPath, WorkingFolder[] workingFolders, String sourceVersion, Boolean cleanRepository, String shelveset, String reshelveName, Boolean gatedRunCI, CancellationToken cancellationToken)
at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.TfvcHelper.Sync(ITaskEndpoint endpoint, String localPath, Dictionary2 serverPathMapping, String sourceVersion, Boolean cleanRepository, String workspaceName, String shelveset, String reshelveName, Boolean runCI, CancellationToken cancellationToken)
at Microsoft.TeamFoundation.DistributedTask.Plugin.Build.TfvcSourceProvider.<>c__DisplayClass3_0.b__0()
--- End of inner exception stack trace ---
at Microsoft.TeamFoundation.DistributedTask.Plugin.Build.TfvcSourceProvider.<>c__DisplayClass3_0.b__0()
at System.Threading.Tasks.Task.Execute()
Finishing Build

Resources