microsoft / microsoft/aspire

`aspire run` fails for Azure Functions due to CS8802

Open
#13,205 2 comments 0 reactions 0 assignees View on GitHub
area-cli
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

Trying to run an Azure Function in Aspire fails during build with `Error CS8802: Only one compilation unit can have top-level statements.`

### Expected Behavior

The app builds and runs.

### Steps To Reproduce

Basic CLI instructions

1. Run `func new`
- Use the up/down arrow keys to select a worker runtime:**dotnet-isolated**
- Use the up/down arrow keys to select a language:**c#-isolated**
- Use the up/down arrow keys to select a template:Function name: **[HttpTrigger]**
2. Run `code .` and edit csproj to target `net10`
3. Upgrade to latest packages
- Microsoft.Azure.Functions.Worker 2.50.0 -> 2.**51.0**
- Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore 2.0.2 -> 2.**1.0**
- Microsoft.Azure.Functions.Worker.Sdk 2.0.6 -> 2.0.**7**
4. Run `aspire init`
- Choose project
- Add Service Defaults to all
- Choose 13.0.0
6. Run `aspire run`

### Exceptions (if any)

```
PS C:\source\aspire10> aspire run
Determining projects to restore...
Restored C:\source\aspire10\aspire10.csproj (in 448 ms).
2 of 3 projects are up-to-date for restore.
aspire10.ServiceDefaults -> C:\source\aspire10\aspire10.ServiceDefaults\bin\Debug\net10.0\aspire10.ServiceDefaults.dll
C:\source\aspire10\Program.cs(6,1): error CS8802: Only one compilation unit can have top-level statements. [[C:\source\aspire10\aspire10.csproj]]
C:\source\aspire10\aspire10.ServiceDefaults\obj\Debug\net10.0\.NETCoreApp,Version=v10.0.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [[
C:\source\aspire10\aspire10.csproj]]
C:\source\aspire10\aspire10.ServiceDefaults\obj\Debug\net10.0\aspire10.ServiceDefaults.AssemblyInfo.cs(13,12): error CS0579: Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute [[
C:\source\aspire10\aspire10.csproj]]
C:\source\aspire10\aspire10.ServiceDefaults\obj\Debug\net10.0\aspire10.ServiceDefaults.AssemblyInfo.cs(14,12): error CS0579: Duplicate 'System.Reflection.AssemblyConfigurationAttribute' attribute [[
C:\source\aspire10\aspire10.csproj]]
C:\source\aspire10\aspire10.ServiceDefaults\obj\Debug\net10.0\aspire10.ServiceDefaults.AssemblyInfo.cs(15,12): error CS0579: Duplicate 'System.Reflection.AssemblyFileVersionAttribute' attribute [[
C:\source\aspire10\aspire10.csproj]]
C:\source\aspire10\aspire10.ServiceDefaults\obj\Debug\net10.0\aspire10.ServiceDefaults.AssemblyInfo.cs(16,12): error CS0579: Duplicate 'System.Reflection.AssemblyInformationalVersionAttribute' attribute [[
C:\source\aspire10\aspire10.csproj]]
C:\source\aspire10\aspire10.ServiceDefaults\obj\Debug\net10.0\aspire10.ServiceDefaults.AssemblyInfo.cs(17,12): error CS0579: Duplicate 'System.Reflection.AssemblyProductAttribute' attribute [[
C:\source\aspire10\aspire10.csproj]]
C:\source\aspire10\aspire10.ServiceDefaults\obj\Debug\net10.0\aspire10.ServiceDefaults.AssemblyInfo.cs(18,12): error CS0579: Duplicate 'System.Reflection.AssemblyTitleAttribute' attribute [[
C:\source\aspire10\aspire10.csproj]]
C:\source\aspire10\aspire10.ServiceDefaults\obj\Debug\net10.0\aspire10.ServiceDefaults.AssemblyInfo.cs(19,12): error CS0579: Duplicate 'System.Reflection.AssemblyVersionAttribute' attribute [[
C:\source\aspire10\aspire10.csproj]]
C:\source\aspire10\obj\Debug\net10.0\.NETCoreApp,Version=v10.0.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [[
C:\source\aspire10\aspire10.csproj]]
C:\source\aspire10\obj\Debug\net10.0\aspire10.AssemblyInfo.cs(13,12): error CS0579: Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute [[C:\source\aspire10\aspire10.csproj]]
C:\source\aspire10\obj\Debug\net10.0\aspire10.AssemblyInfo.cs(14,12): error CS0579: Duplicate 'System.Reflection.AssemblyConfigurationAttribute' attribute [[C:\source\aspire10\aspire10.csproj]]
C:\source\aspire10\obj\Debug\net10.0\aspire10.AssemblyInfo.cs(15,12): error CS0579: Duplicate 'System.Reflection.AssemblyFileVersionAttribute' attribute [[C:\source\aspire10\aspire10.csproj]]
C:\source\aspire10\obj\Debug\net10.0\aspire10.AssemblyInfo.cs(16,12): error CS0579: Duplicate 'System.Reflection.AssemblyInformationalVersionAttribute' attribute [[C:\source\aspire10\aspire10.csproj]]
C:\source\aspire10\obj\Debug\net10.0\aspire10.AssemblyInfo.cs(17,12): error CS0579: Duplicate 'System.Reflection.AssemblyProductAttribute' attribute [[C:\source\aspire10\aspire10.csproj]]
C:\source\aspire10\obj\Debug\net10.0\aspire10.AssemblyInfo.cs(18,12): error CS0579: Duplicate 'System.Reflection.AssemblyTitleAttribute' attribute [[C:\source\aspire10\aspire10.csproj]]
C:\source\aspire10\obj\Debug\net10.0\aspire10.AssemblyInfo.cs(19,12): error CS0579: Duplicate 'System.Reflection.AssemblyVersionAttribute' attribute [[C:\source\aspire10\aspire10.csproj]]
C:\source\aspire10\aspire10.AppHost\obj\Debug\net10.0\aspire10.AppHost.GlobalUsings.g.cs(2,14): error CS0246: The type or namespace name 'Aspire' could not be found (are you missing a using directive or an assembly
reference?) [[C:\source\aspire10\aspire10.csproj]]
C:\source\aspire10\aspire10.AppHost\obj\Debug\net10.0\aspire10.AppHost.GlobalUsings.g.cs(3,14): error CS0246: The type or namespace name 'Aspire' could not be found (are you missing a using directive or an assembly
reference?) [[C:\source\aspire10\aspire10.csproj]]
C:\source\aspire10\aspire10.AppHost\obj\Debug\net10.0\Aspire\references\aspire10.ProjectMetadata.g.cs(12,33): error CS0400: The type or namespace name 'Aspire' could not be found in the global namespace (are you missing
an assembly reference?) [[C:\source\aspire10\aspire10.csproj]]

Build FAILED.
```

### .NET Version info

```
.NET SDK:
Version: 10.0.100
Commit: b0f34d51fc
Workload version: 10.0.100-manifests.4c0ca8ba
MSBuild version: 18.0.2+b0f34d51f

Runtime Environment:
OS Name: Windows
OS Version: 10.0.26200
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.100\

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
Version: 10.0.0
Architecture: x64
Commit: b0f34d51fc

.NET SDKs installed:
10.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 10.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
```

### Anything else?

Azure Functions:

```
Azure Functions Core Tools
Core Tools Version: 4.5.0+e74aae22c9630777c9f58354f290a6e214218546 (64-bit)
Function Runtime Version: 4.1044.400.25520
```

Windows:
Version 25H2 (OS Build 26200.7171)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.