dotnet / dotnet/sdk

10.0.200 AOT publish creates corrupted dll when output path is a directory above the project being published

Open
#53,400 0 comments 0 reactions 0 assignees View on GitHub
Area-NativeAOT untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Describe the bug
Publishing a C# project using AOT will create a corrupt dll when the output directory specified in the publish command is a level above the project being built.
**Note that this is a regression from 10.0.1xx.**

### To Reproduce
* Create a basic C# project with a method that is exported using UnManagedCallersOnly attribute
* Publish the C# project using the following command:
`dotnet publish "C:\path\to\csharp_project\ManagedAotLib.csproj" -c Release -r win-x64 -o "C:\path\to"`
* Create a basic C++ project that loads the above dll using LoadLibrary and tries to call into the above method using GetProcAddress
* When run, the C++ project will successfully load the dll but will not be able to find the function using GetProcAddress, returning nullptr and 127 as its last error

(see https://gist.github.com/koyote/ee80f7f64eb753af3abd4b718b760f7d for the example code)

**Note that this bug is specific to the output path specified in the publish command!**
It has to be one level above the project that is to be published (I did not test if multiple levels above have the same issue).
It has to be an absolute path! Relative paths do not trigger the bug as far as I can see.

### Further technical details
details of dotnet --info


.NET SDK:
Version: 10.0.200
Commit: 40cd698e5c
Workload version: 10.0.200-manifests.b7278506
MSBuild version: 18.3.0-release-26119-122+40cd698e5

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

.NET workloads installed:
[wasm-tools]
Installation Source: VS 18.4.11605.240
Manifest Version: 10.0.104/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.workload.mono.toolchain.current\10.0.104\WorkloadManifest.json
Install Type: Msi

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.4
Architecture: x64
Commit: 80d3e14f5e

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

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.24 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.24 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.4 [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]

Environment variables:
Not set

global.json file:
Not found

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.