Share via

Cloud Shell: Error Executing Code in Training Module - Unable to Proceed Due to [CS1002;1026;1529]

rain purple 300 Reputation points
2026-05-22T07:17:29.4433333+00:00

Hello, support team:

  1. Source: when finish the training module "Discover Azure message queues",I face an exercise issue with Cloudshell(Powershell). training module: https://learn.microsoft.com/en-us/training/modules/discover-azure-message-queue/ exercise link:https://microsoftlearning.github.io/mslearn-azure-developer/instructions/azure-events-messages/03-service-bus-send-receive.html
  2. Step Where the Issue Occurred: "Create a .NET console app to send and receive messages"-->"Add the starter code for the project"-->code Program.cs-->then copy the code from next step: "Replace any existing contents ****"-->input "dotnet run" in Powershell directly
  3. Attempts to Fix the Issue find the position, but don't know how to fix. the exercise don't show what issue will face when copy code to replace the content directly

Checking Error Records

I take a picture with these codes and error feedback. it shows that the

 [Program.cs.jpeg](/api/attachments/eb40c355-44ba-4645-9562-e4966b8d1e5b?platform=QnA)

[error information.jpeg](/api/attachments/982c4414-0f3e-454d-8e46-624ac06ea3fc?platform=QnA)
  1. Row 3rd, 19th symbol faces error
  2. Row 4th ,1st symbol faces error
  3. Row 5th ,1st symbol faces error
  4. Row 26th (last one),29th symbol faces error. 5.Alternative Solutions Is there any other solution to send message through Cloud shell? How to check the file in Azure portal service bus resource? I can't find it when it shows that already saved. Can I use Export template to save this file through Cloud shell?

Thanks a lot!

good weekend!

user from Azure portal

Azure Service Bus
Azure Service Bus

An Azure service that provides cloud messaging as a service and hybrid integration.

0 comments No comments

Answer accepted by question author

Pravallika KV 17,025 Reputation points Microsoft External Staff Moderator
2026-05-22T10:05:22.97+00:00

Hi @rain purple ,

It sounds like you’ve successfully generated a .NET console app in Cloud Shell but you’re hitting C# compile errors (CS1002, CS1026, CS1529) right after pasting in the sample code. Those error codes usually pop up when the compiler finds unexpected characters (like “smart quotes”, stray markdown symbols or missing semicolons) or when the code uses C# features not supported by your SDK version.

Here's a checklist to help you zero in on the issue:

  1. Verify your .NET SDK version
    • Run dotnet --version in Cloud Shell.
    • The sample code uses top-level statements and async Main which require .NET 6 or later.
    • If you’re on an older SDK, recreate the console app with:
      
           dotnet new console --framework net6.0 --name ServiceBusQuickStart
      
      
      or update your Cloud Shell to use a newer SDK.
  2. Clean up any invalid characters
    • Open Program.cs in your editor (e.g. code Program.cs or vi Program.cs).
    • Replace any curly quotes (“ ”) with straight quotes (") and remove any bullet numbers or markdown prefixes that snuck in.
    • Make sure each statement ends with a semicolon where required.
  3. Grab the raw sample code directly from the repo
  4. Build and run
    
       dotnet build
    
       dotnet run
    
    
    If everything is formatted correctly and you have the package installed (dotnet add package Azure.Messaging.ServiceBus), it should compile and send/receive messages.

Alternative ways to send a Service Bus message without writing a full C# app:

  • Azure CLI (with the Service Bus extension):
    
      az servicebus queue send \
    
        --resource-group MyRG \
    
        --namespace-name MyNamespace \
    
        --queue-name MyQueue \
    
        --body "Hello from Cloud Shell!"
    
    
  • REST API via curl or PowerShell’s Invoke-WebRequest.
  • Azure Portal’s built-in Service Bus Explorer blade (under your Service Bus namespace).

Inspecting files in Cloud Shell’s storage from the Azure portal:

  • In the Azure portal, locate the “Storage account” named cs<yourID>store (in the resource group ShellResources).
  • Click on “File shares” → clouddrive → Browse to see your Program.cs.
  • You can also mount that file share locally via Storage Explorer or AzCopy.

Unfortunately, you can’t export a C# source file as an ARM template (ARM templates export Azure resources, not code files). If you want persistent backups, just git-init your folder and push to GitHub or clone it to your local machine.

References:

Hope this helps!


If the resolution was helpful, kindly take a moment to click on User's imageand click on Yes for was this answer helpful. And, if you have any further query do let us know.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

Answer accepted by question author

AI answer

2026-05-22T07:17:49.7466667+00:00

The CS1002, CS1026, and CS1529 errors in Program.cs indicate that the C# code copied into the file is syntactically incomplete or was pasted incorrectly. These errors are compiler syntax errors in the .NET console app code, not Cloud Shell or Azure Service Bus issues.

To proceed with the training module scenario (send/receive messages with Azure Service Bus), use these approaches:

  1. Ensure the Program.cs content exactly matches the training code
    • Delete all existing content in Program.cs.
    • Carefully re-copy the entire code block from the "Replace any existing contents" step in the module, making sure:
      • All using statements at the top are included.
      • The namespace, class Program, and static async Task Main definitions are complete.
      • All opening { braces have matching closing } braces.
    • Save the file and run dotnet run again.
  2. Use Cloud Shell correctly for .NET code
    • In Cloud Shell (PowerShell), create and run the .NET console app as described in the module:
      • dotnet new console -n <project-name>
      • cd <project-name>
      • Replace Program.cs with the full sample code.
      • dotnet run to execute.
    • If Cloud Shell reports sign-in or authorization errors when the app calls Service Bus, sign in interactively in Cloud Shell with:
      • az login --use-device-code
    • For passwordless Service Bus samples, if errors like 'Send' claim(s) are required or 'Receive' claim(s) are required appear, ensure the signed-in account has the appropriate role on the Service Bus namespace as described in the Service Bus TypeScript troubleshooting section (the same principle applies: correct Azure role assignment is required).
  3. Alternative way to complete the exercise
    • If Cloud Shell is problematic (for example, MSI or sign-in issues), use the guidance from the training support article:
      • Start Cloud Shell from the module page and run az login if you see "Failed to connect to MSI".
      • If Cloud Shell won’t start or behaves inconsistently, try a different browser or an InPrivate/incognito window, as suggested in the training troubleshooting table.
    • The exercise itself is designed around a .NET console app; there is no supported alternative in the module to “send messages directly from Cloud Shell without code” for this scenario.
  4. About “files in the Service Bus resource” and Export template
    • Azure Service Bus queues and topics store messages, not code files. Program.cs and other project files live in the Cloud Shell storage (Azure Files share attached to Cloud Shell), not inside the Service Bus resource.
    • The Export template feature in the Azure portal exports the ARM template for the Service Bus resource configuration (namespaces, queues, etc.), not the application code or Program.cs.
    • To view or edit Program.cs, use the editor in Cloud Shell (for example, code Program.cs in Bash or PowerShell Cloud Shell) rather than looking in the Service Bus resource in the portal.

Following these steps should resolve the syntax errors and allow the console app to run and send/receive messages as required by the "Discover Azure message queues" module.


References:

AI-generated content may be incorrect. Read our transparency notes for more information.

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.