question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

async Main doesn't work in Run mode

See original GitHub issue

I’ve tried to compile the following code:

using System;
using System.Threading.Tasks;
public static class Program {
    public static async Task Main() {
        Console.WriteLine("🌄");
    }
}

The compilation failed with an error:

Unbreakable.AssemblyGuardException: Type System.Runtime.CompilerServices.AsyncTaskMethodBuilder is not allowed.
   at Unbreakable.Internal.AssemblyValidator.EnsureAllowed(TypeReference type, String memberName)
   at Unbreakable.Internal.AssemblyValidator.ValidateMemberReference(MemberReference reference)
   at Unbreakable.Internal.AssemblyValidator.ValidateInstructionAndGetPolicy(Instruction instruction, MethodDefinition method)
   at Unbreakable.AssemblyGuard.ValidateAndRewriteMethod(MethodDefinition method, RuntimeGuardReferences guard, AssemblyValidator validator, AssemblyGuardSettings settings)
   at Unbreakable.AssemblyGuard.ValidateAndRewriteType(TypeDefinition type, RuntimeGuardReferences guard, AssemblyValidator validator, AssemblyGuardSettings settings)
   at Unbreakable.AssemblyGuard.ValidateAndRewriteType(TypeDefinition type, RuntimeGuardReferences guard, AssemblyValidator validator, AssemblyGuardSettings settings)
   at Unbreakable.AssemblyGuard.Rewrite(AssemblyDefinition assembly, AssemblyGuardSettings settings)
   at SharpLab.Server.Execution.Executor.Execute(Stream assemblyStream, Stream symbolStream, IWorkSession session)
   at SharpLab.Server.MirrorSharp.SlowUpdate.<ProcessAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MirrorSharp.Internal.Handlers.SlowUpdateHandler.<ExecuteAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at MirrorSharp.Internal.Connection.<ReceiveAndProcessInternalAsync>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MirrorSharp.Internal.Connection.<ReceiveAndProcessAsync>d__12.MoveNext()

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ashmindcommented, Nov 13, 2021

Hi @ForNeVeR, this is now resolved, as new Run mode does not have restrictions on async code.

0reactions
ashmindcommented, Nov 28, 2021

Yep, current Run mode does not use Unbreakable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - How can I use async/await at the top level?
I can't seem to wrap my head around why this does not work. Because main returns a promise; all async functions do. At...
Read more >
C# Async code doesn't work on Visual Studio Release ...
This code pings each ip address 4 times asynchronously, and the entire function is made to run on 5k IP addresses using task.Add...
Read more >
Because this call is not awaited, execution of the current ...
The call to the async method starts an asynchronous task. However, because no Await operator is applied, the program continues without waiting ...
Read more >
Async methods do not stop executing when exiting play ...
A program is running as long as it has at least one active thread. So outside the editor it should behave the same....
Read more >
C# Async code doesn't work on Visual Studio Release ...
Question C# Async code doesn't work on Visual Studio Release mode, works perfectly well on debug mode (with or without attaching the debugger)....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found