I've got a really weird error going on here with our Azure App Service deployment related to RazorLight.
I've been running 2.0-alpha3 for several days now in Azure App Services without issue. Then all of a sudden this evening (without anything changing on our end) our app starts getting 500 errors from anything that invokes RazorLight (sending emails).
Source array was not long enough. Check srcIndex and length, and the array's lower bounds.
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)\r\n
at System.Collections.Immutable.ImmutableExtensions.TryCopyTo[T](IEnumerable`1 sequence, T[] array, Int32 arrayIndex)\r\n
at System.Collections.Immutable.ImmutableExtensions.ToArray[T](IEnumerable`1 sequence, Int32 count)\r\n
at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)\r\n
at Microsoft.CodeAnalysis.ImmutableArrayExtensions.AsImmutableOrEmpty[T](IEnumerable`1 items)\r\n
at Microsoft.CodeAnalysis.Compilation.ValidateReferences[T](IEnumerable`1 references)\r\n
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.Create(String assemblyName, CSharpCompilationOptions options, IEnumerable`1 syntaxTrees, IEnumerable`1 references, CSharpCompilation previousSubmission, Type returnType, Type hostObjectType, Boolean isSubmission)\r\n
at RazorLight.Compilation.RoslynCompilationService.CreateCompilation(String compilationContent, String assemblyName)\r\n
at RazorLight.Compilation.RoslynCompilationService.CompileAndEmit(GeneratedRazorTemplate razorTemplate)\r\n
at RazorLight.TemplateFactoryProvider.CreateFactory(GeneratedRazorTemplate razorTemplate)\r\n
at RazorLight.TemplateFactoryProvider.<CreateFactoryAsync>d__4.MoveNext()\r\n
--- End of stack trace from previous location where exception was thrown ---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at RazorLight.RazorLightEngine.<CompileTemplateAsync>d__10.MoveNext()\r\n
--- End of stack trace from previous location where exception was thrown ---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at RazorLight.RazorLightEngine.<CompileRenderAsync>d__9.MoveNext()\r\n
--- End of stack trace from previous location where exception was thrown ---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at Bit.Core.Services.RazorMailService.<SendMasterPasswordHintEmailAsync>d__9.MoveNext()\r\n
--- End of stack trace from previous location where exception was thrown ---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at Bit.Core.Services.UserService.<SendMasterPasswordHintAsync>d__26.MoveNext()\r\n
--- End of stack trace from previous location where exception was thrown ---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at Bit.Api.Controllers.AccountsController.<PostPasswordHint>d__8.MoveNext()\r\n
--- End of stack trace from previous location where exception was thrown ---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()\r\n
--- End of stack trace from previous location where exception was thrown ---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__10.MoveNext()\r\n
--- End of stack trace from previous location where exception was thrown ---\r\n
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)\r\n
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__14.MoveNext()\r\n
--- End of stack trace from previous location where exception was thrown ---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextExceptionFilterAsync>d__23.MoveNext()",
I restart the server and even re-deployed the code, but the error remains every time something uses RazorLight. I don't really understand what has changed all of a sudden to cause this issue.
Locally I can execute the same RazorLight code without issue. See source here: https://github.com/bitwarden/core/blob/master/src/Core/Services/Implementations/RazorMailService.cs
Any ideas what is going on here?
That sounds really really weird, because I did not reupload anything to nuget, nor made any changes to the code at all
@toddams Even if you did, we are locked at <PackageReference Include="RazorLight" Version="2.0.0-alpha3" />. Plus, we didn't even change anything here so no new bits have been picked up. This same code has been running without issue on the server for 2-3 days without issue. Then all of a sudden these 500s that I could not get rid of for several hours last night.
And guess what, this morning I wake up and the errors have magically stopped and everything works fine again with RazorLight.
Sound like a magic :)
@toddams Even though things eventually resolved themselves, are you not concerned that this may be some issues in the library? Stack traces definitely appear to be pointing at RazorLight.
Well, if we look at stack trace - it goes deeper than RazorLight and falls into Microsoft.CodeAnalysis, which uses some array extensions, that makes me think that it's not a RazorLight issue. I'm pretty concerned about this issue, as I use RazorLight personally in my projects and at work (that's basically why it's developed in a first place) but I did not face with such an issue so far. Let's reopen this and wait if somebody else has the same problem
This just started happening again tonight. It coincided with a deployment (publish) to the web app service on Azure. We'll see if it self-corrects itself again or not.
More info:
The server continued throwing the errors mentioned in the original stack trace above, however, after about 10 minutes or so of the application running it then completely crashed with the following errors:
Value cannot be null.\r\nParameter name: values
at System.String.Join(String separator, IEnumerable`1 values)\r\n
at Microsoft.Extensions.RazorViews.BaseView.EndWriteAttribute()\r\n
at Microsoft.AspNetCore.Hosting.Views.ErrorPage.<ExecuteAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at Microsoft.Extensions.RazorViews.BaseView.<ExecuteAsync>d__29.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame`1.<ProcessRequestsAsync>d__2.MoveNext()
and then
Cannot access a disposed object.\r\nObject name: 'FrameResponseStream'.
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameResponseStream.ValidateState(CancellationToken cancellationToken)\r\n
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameResponseStream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)\r\n
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameResponseStream.Write(Byte[] buffer, Int32 offset, Int32 count)\r\n
at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)\r\n
at System.IO.StreamWriter.Write(String value)\r\n
at Microsoft.Extensions.RazorViews.BaseView.WriteLiteralTo(TextWriter writer, String value)\r\n
at Microsoft.AspNetCore.Hosting.Views.ErrorPage.<ExecuteAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at Microsoft.Extensions.RazorViews.BaseView.<ExecuteAsync>d__29.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame`1.<ProcessRequestsAsync>d__2.MoveNext()
This caused me to have to restart the server. After restarting from the crash there are now no more errors occurring.
I am see this as well. Could this be a race condition somewhere with multiple threads needing to use a template which has not been compiled yet? If I queue up a bunch of jobs for the same template and they all run together, it seems to run into this issue and it doesn't get resolved. If I then restart the service and only queue one job for a specific template, then it seems to be fine. I can then queue up multiple jobs to run at the same time for the same template and everything runs fine.
Looks like I'm going to have great time debugging it) Thank you for the report
This seems to happen pretty consistently now when deploying our API to azure app services.
I reproduced the bug, will keep you updated
Issue is fixed, preparing for release
I've got same issue with following stacktrace:
Unhandled Exception: System.AggregateException: One or more errors occurred. (One or more errors occurred. (Source array was not long enough. Check the source index, length, and the array's lower bounds.
Parameter name: sourceArray)) (One or more errors occurred. (Source array was not long enough. Check the source index, length, and the array's lower bounds.
Parameter name: sourceArray)) (One or more errors occurred. (Source array was not long enough. Check the source index, length, and the array's lower bounds.
Parameter name: sourceArray)) (One or more errors occurred. (Source array was not long enough. Check the source index, length, and the array's lower bounds.
Parameter name: sourceArray)) (One or more errors occurred. (Source array was not long enough. Check the source index, length, and the array's lower bounds.
Parameter name: sourceArray)) ---> System.AggregateException: One or more errors occurred. (Source array was not long enough. Check the source index, length, and the array's lower bounds.
Parameter name: sourceArray) ---> System.ArgumentException: Source array was not long enough. Check the source index, length, and the array's lower bounds.
Parameter name: sourceArray
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Collections.Generic.List`1.CopyTo(T[] array, Int32 arrayIndex)
at System.Collections.Immutable.ImmutableExtensions.TryCopyTo[T](IEnumerable`1 sequence, T[] array, Int32 arrayIndex)
at System.Collections.Immutable.ImmutableExtensions.ToArray[T](IEnumerable`1 sequence, Int32 count)
at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
at Microsoft.CodeAnalysis.ImmutableArrayExtensions.AsImmutableOrEmpty[T](IEnumerable`1 items)
at Microsoft.CodeAnalysis.Compilation.ValidateReferences[T](IEnumerable`1 references)
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.Create(String assemblyName, CSharpCompilationOptions options, IEnumerable`1 syntaxTrees, IEnumerable`1 references, CSharpCompilation previousSubmission, Type returnType, Type
hostObjectType, Boolean isSubmission)
at RazorLight.Compilation.RoslynCompilationService.CreateCompilation(String compilationContent, String assemblyName)
at RazorLight.Compilation.RoslynCompilationService.CompileAndEmit(IGeneratedRazorTemplate razorTemplate)
at RazorLight.Compilation.RoslynCompilationService.CompileAsync(IGeneratedRazorTemplate razorTemplate)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.Compilation.TemplateFactoryProvider.<CompileAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.Compilation.TemplateFactoryProvider.<CreateFactoryAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.RazorLightEngine.<CompileTemplateAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.RazorLightEngine.<CompileRenderAsync>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at YamlTests.Razor.<ProcessTemplate>d__2.MoveNext() in C:\Users\Rizzen\RiderProjects\YamlTests\YamlTests\Razor.cs:line 20
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at YamlTests.Program.<>c__DisplayClass0_0.<Main>g__ProcessAndAdd|0(String templ) in C:\Users\Rizzen\RiderProjects\YamlTests\YamlTests\Program.cs:line 40
at System.Threading.Tasks.Parallel.<>c__DisplayClass33_0`2.<ForEachWorker>b__0(Int32 i)
at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
at System.Threading.Tasks.TaskReplicator.Replica`1.ExecuteAction(Boolean& yieldedBeforeCompletion)
at System.Threading.Tasks.TaskReplicator.Replica.Execute()
--- End of inner exception stack trace ---
at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally
)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Threading.Tasks.Parallel.ThrowSingleCancellationExceptionOrOtherException(ICollection exceptions, CancellationToken cancelToken, Exception otherException)
at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally
)
at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IList`1 list, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWi
thEverything, Func`1 localInit, Action`1 localFinally)
at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`
5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, Action`1 body)
at YamlTests.Program.Main(String[] args) in C:\Users\Rizzen\RiderProjects\YamlTests\YamlTests\Program.cs:line 44
It reproduces in about one of three runs
Must be fixed in beta1
I'm using latest prerelease 2.0.0-beta1.
I see Parallel.ForEach in a stack trace, it's your code that causes this exception
Ok, i'll consider it.
Also have the same problem in 2.0.0-beta1
It occurs in 2 cron jobs running at the same time, using 2 templates based on the same Layout
Maybe is it a race condition with the common layout which is compiled twice at the same time?
As a workaround, I use a Lock section when I call CompileRenderAsync. But then, I cannot await it and must get the result synchronously.
On 2.0.0-beta1 and still experiencing this issue. Typically works fine, but every so often everything begins failing (without any code changes).
Stack trace here:
2018-02-13 14:02:38.000 +00:00 [Error] One or more errors occurred. (Source array was not long enough. Check the source index, length, and the array's lower bounds.
Parameter name: sourceArray)
System.AggregateException: One or more errors occurred. (Source array was not long enough. Check the source index, length, and the array's lower bounds.
Parameter name: sourceArray) ---> System.ArgumentException: Source array was not long enough. Check the source index, length, and the array's lower bounds.
Parameter name: sourceArray
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Collections.Generic.List`1.CopyTo(T[] array, Int32 arrayIndex)
at System.Collections.Immutable.ImmutableExtensions.TryCopyTo[T](IEnumerable`1 sequence, T[] array, Int32 arrayIndex)
at System.Collections.Immutable.ImmutableExtensions.ToArray[T](IEnumerable`1 sequence, Int32 count)
at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
at Microsoft.CodeAnalysis.ImmutableArrayExtensions.AsImmutableOrEmpty[T](IEnumerable`1 items)
at Microsoft.CodeAnalysis.Compilation.ValidateReferences[T](IEnumerable`1 references)
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.Create(String assemblyName, CSharpCompilationOptions options, IEnumerable`1 syntaxTrees, IEnumerable`1 references, CSharpCompilation previousSubmission, Type returnType, Type hostObjectType, Boolean isSubmission)
at RazorLight.Compilation.RoslynCompilationService.CreateCompilation(String compilationContent, String assemblyName)
at RazorLight.Compilation.RoslynCompilationService.CompileAndEmit(IGeneratedRazorTemplate razorTemplate)
at RazorLight.Compilation.RoslynCompilationService.CompileAsync(IGeneratedRazorTemplate razorTemplate)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.Compilation.TemplateFactoryProvider.<CompileAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.Compilation.TemplateFactoryProvider.<CreateFactoryAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.RazorLightEngine.<CompileTemplateAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.RazorLightEngine.<CompileRenderAsync>d__11.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at X.Y.Z.GenerateSubject() in C:\a\b\c\d\e\f\g\h.g\NotificationGenerator.cs:line 338
at X.Y.Z.SendNotification() in C:\a\b\c\d\e\f\g\h.g\NotificationGenerator.cs:line 285
at A.B.C.D.Send(DocumentType DocTypeID, Int32 TransactionID, Template Template) in C:\a\b\c\d\e\f\g\h.g\Controllers\NotificationController.cs:line 44
---> (Inner Exception #0) System.ArgumentException: Source array was not long enough. Check the source index, length, and the array's lower bounds.
Parameter name: sourceArray
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Collections.Generic.List`1.CopyTo(T[] array, Int32 arrayIndex)
at System.Collections.Immutable.ImmutableExtensions.TryCopyTo[T](IEnumerable`1 sequence, T[] array, Int32 arrayIndex)
at System.Collections.Immutable.ImmutableExtensions.ToArray[T](IEnumerable`1 sequence, Int32 count)
at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
at Microsoft.CodeAnalysis.ImmutableArrayExtensions.AsImmutableOrEmpty[T](IEnumerable`1 items)
at Microsoft.CodeAnalysis.Compilation.ValidateReferences[T](IEnumerable`1 references)
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.Create(String assemblyName, CSharpCompilationOptions options, IEnumerable`1 syntaxTrees, IEnumerable`1 references, CSharpCompilation previousSubmission, Type returnType, Type hostObjectType, Boolean isSubmission)
at RazorLight.Compilation.RoslynCompilationService.CreateCompilation(String compilationContent, String assemblyName)
at RazorLight.Compilation.RoslynCompilationService.CompileAndEmit(IGeneratedRazorTemplate razorTemplate)
at RazorLight.Compilation.RoslynCompilationService.CompileAsync(IGeneratedRazorTemplate razorTemplate)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.Compilation.TemplateFactoryProvider.<CompileAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.Compilation.TemplateFactoryProvider.<CreateFactoryAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.RazorLightEngine.<CompileTemplateAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.RazorLightEngine.<CompileRenderAsync>d__11.MoveNext()<---
There should be 1 compilation at a time, otherwise this exception occurs
@toddams
Issue is fixed, preparing for release
Was this fix ever released? I'm still seeing alpha3 from September as latest. Still dealing with this issue.
Nevermind, it just seems you didn't tag it here on GitHub. I see beta1 on Nuget.
Receiving this error on 2.0.0-beta1. The error happens quite rarely, but the only way to resolve it is by restarting the entire site - once the error happens, all subsequent requests will experience the same error until the site is restarted. Seems to be happening less often than in previous versions but it is still happening. The way to reproduce is by visiting the site.
System.ArgumentException: Source array was not long enough. Check the source index, length, and the array's lower bounds.
Parameter name: sourceArray
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Collections.Generic.List`1.CopyTo(T[] array, Int32 arrayIndex)
at System.Collections.Immutable.ImmutableExtensions.TryCopyTo[T](IEnumerable`1 sequence, T[] array, Int32 arrayIndex)
at System.Collections.Immutable.ImmutableExtensions.ToArray[T](IEnumerable`1 sequence, Int32 count)
at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
at Microsoft.CodeAnalysis.ImmutableArrayExtensions.AsImmutableOrEmpty[T](IEnumerable`1 items)
at Microsoft.CodeAnalysis.Compilation.ValidateReferences[T](IEnumerable`1 references)
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.Create(String assemblyName, CSharpCompilationOptions options, IEnumerable`1 syntaxTrees, IEnumerable`1 references, CSharpCompilation previousSubmission, Type returnType, Type hostObjectType, Boolean isSubmission)
at RazorLight.Compilation.RoslynCompilationService.CreateCompilation(String compilationContent, String assemblyName)
at RazorLight.Compilation.RoslynCompilationService.CompileAndEmit(IGeneratedRazorTemplate razorTemplate)
at RazorLight.Compilation.RoslynCompilationService.CompileAsync(IGeneratedRazorTemplate razorTemplate)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.Compilation.TemplateFactoryProvider.<CompileAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.Compilation.TemplateFactoryProvider.<CreateFactoryAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.RazorLightEngine.<CompileTemplateAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.RazorLightEngine.<CompileRenderAsync>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Website.Startup.<>c__DisplayClass11_0.<<Configure>b__0>d.MoveNext() in C:\Git\[REDACTED]\Startup.cs:line 236
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()
Seems like my "fix" did not fix everything, reopening for further investigation.
Have you found a fix for this issue yet?
I need a little help from everyone who encounters this exception.
Is it possible for your system to call RazorLight and pass templateKey that do not exists?
Like someone wants to compile a template, but file with "testKey" doesn't exist in the folder?
@toddams I am fairly confident there are no calls to undefined template keys in my code. https://github.com/bitwarden/core/blob/master/src/Core/Services/Implementations/RazorMailService.cs
You can reproduce it using this unit test project.
razorlight_issue.zip
For me, the problem is caused by a simultaneous compilation of the same resources. But this is probably less obvious when it is in an ASP.Net env. Where the engine is probably registered as a singleton.
As a workaround, you can lock the methods where you compile templates.
No longer experiencing the issue in my case
Fixed. Thanks everyone for your help, I do appreciate that
Hi @toddams
I'm still have this issue in version 2.0-beta1, how can I fix this, thank!
This is my stacktrace
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Collections.Generic.List`1.CopyTo(T[] array, Int32 arrayIndex)
at System.Collections.Immutable.ImmutableExtensions.TryCopyTo[T](IEnumerable`1 sequence, T[] array, Int32 arrayIndex)
at System.Collections.Immutable.ImmutableExtensions.ToArray[T](IEnumerable`1 sequence, Int32 count)
at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
at Microsoft.CodeAnalysis.ImmutableArrayExtensions.AsImmutableOrEmpty[T](IEnumerable`1 items)
at Microsoft.CodeAnalysis.Compilation.ValidateReferences[T](IEnumerable`1 references)
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.Create(String assemblyName, CSharpCompilationOptions options, IEnumerable`1 syntaxTrees, IEnumerable`1 references, CSharpCompilation previousSubmission, Type returnType, Type hostObjectType, Boolean isSubmission)
at RazorLight.Compilation.RoslynCompilationService.CreateCompilation(String compilationContent, String assemblyName)
at RazorLight.Compilation.RoslynCompilationService.CompileAndEmit(IGeneratedRazorTemplate razorTemplate)
at RazorLight.Compilation.RoslynCompilationService.CompileAsync(IGeneratedRazorTemplate razorTemplate)
--- End of stack trace from previous location where exception was thrown ---
at RazorLight.Compilation.TemplateFactoryProvider.CompileAsync(IGeneratedRazorTemplate razorTemplate)
at RazorLight.Compilation.TemplateFactoryProvider.CreateFactoryAsync(String templateKey)
at RazorLight.RazorLightEngine.CompileTemplateAsync(String key)
at RazorLight.RazorLightEngine.CompileRenderAsync(String key, Object model, Type modelType, ExpandoObject viewBag)
I'm also having this issue intermittently. From your note about one compilation should be done at a time; why bother having it async if you can only do one thing at a time? Isn't it likely that one would want to compile as much as they can at the same time using Task.WhenAll/etc. ?
Other than this bug, I find this library very handy. Thank you for making it available.
We are also seeing this issue, It does seem to be somehow related to Threading. Any idea if there is a fix for this any time soon. We really like this library.
Hi all, we are also having this issue "Source array was not long enough. Check the source index, length, and the array's lower bounds. Parameter name: sourceArray". We are using v2.0.0-beta1 executed on an Azure Functions. Any idea? Thanks a lot.
For anyone experiencing this issue, I was able to fix it after @toddams closed this issue on 8th June by cloning the latest commit of the master branch and compiling the RazorLight plugin myself in Visual Studio. This is because there hasn't been any release since the issue was fixed containing the fix. I then referenced my compiled RazorLight in my projects and I haven't had the issue since. I've attached a zip file of the RazorLight that I compiled which is working well for me, I will note that the version I've attached was compiled back in June and therefore is probably outdated now.
You just need to uninstall any version that you already have installed beforehand and reference the compiled version in your projects (Right click project -> Add -> Reference in Visual Studio 2017)
RazorLight.zip
Hello everyone: Is another maintainer able to publish a release of @toddams 's changes please?
Most helpful comment
Hello everyone: Is another maintainer able to publish a release of @toddams 's changes please?