Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using PublishSingleFile and IncludeNativeLibrariesForSelfExtract on macOS causes a "Class PlaceholderObject is implemented in both" warning #29658

Open
KTSnowy opened this issue Dec 23, 2022 · 5 comments
Assignees
Labels
Area-NetSDK untriaged Request triage from a team member

Comments

@KTSnowy
Copy link

KTSnowy commented Dec 23, 2022

Describe the bug

We're using a native C library for some performance critical parts of our application. This library gets called from our C# code using PInvoke. Recently we've been experimenting with single file publish which would allow us to package the native library with the application, but we're getting the following warning every time the application starts with dotnet run:

objc[4948]: Class PlaceholderObject is implemented in both
/<project-dir>/bin/Debug/net7.0/osx-x64/<project-name> (0x104e20400) 
and /<project-dir>/bin/Debug/net7.0/osx-x64/libSystem.Native.dylib (0x1061ad6a0). 
One of the two will be used. Which one is undefined.

To Reproduce

As far as I've tested it seems that adding these two csproj options on macOS is what is causing the warnings:

<PublishSingleFile>true</PublishSingleFile>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>

Exceptions (if any)

Further technical details

  • Include the output of dotnet --info
.NET SDK:
 Version:   7.0.100
 Commit:    e12b7af219

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  12.6
 OS Platform: Darwin
 RID:         osx.12-x64
 Base Path:   /usr/local/share/dotnet/sdk/7.0.100/

Host:
  Version:      7.0.0
  Architecture: x64
  Commit:       d099f075e4

.NET SDKs installed:
  5.0.302 [/usr/local/share/dotnet/sdk]
  6.0.402 [/usr/local/share/dotnet/sdk]
  7.0.100-rc.2.22477.23 [/usr/local/share/dotnet/sdk]
  7.0.100 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.10 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.0-rc.2.22476.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.10 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0-rc.2.22472.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version
Visual Studio Code
Version: 1.74.1
Commit: 1ad8d514439d5077d2b0b7ee64d2ce82a9308e5a
Date: 2022-12-14T10:33:40.793Z (1 wk ago)
Electron: 19.1.8
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Darwin x64 21.6.0
Sandboxed: No
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-NetSDK untriaged Request triage from a team member labels Dec 23, 2022
@vitek-karas
Copy link
Member

Where does the error come from? What do you use to build the native code (as the error seems to be from the native side of things).

@vitek-karas
Copy link
Member

Actually - looking at the failure some more... I guess this is at runtime right?

When you dotnet publish the output goes to something like /bin/Debug/net7.0/osx-x64/publish. The content of the bin/Debug/net7.0/osx-x64 directory is probably a semi-random collection of files needed to produce the final output. With single-file there should be no libSystem.Native.dylib file next to the executable (since its content is included in the executable).

@KTSnowy
Copy link
Author

KTSnowy commented Jan 5, 2023

Actually - looking at the failure some more... I guess this is at runtime right?

This is when executing dotnet run inside a project with those two csproj options. Running dotnet publish and then running the executable doesn't display this error.

What do you use to build the native code (as the error seems to be from the native side of things).

The native PInvoke code we use in our project is built with Clang (on macOS) and is imported from a class library into the executable application. But it doesn't seem that the error is coming from the C code side of it.

With PublishSingleFile dotnet run will display it as part of its output before running the application. Without PublishSingleFile or when not using dotnet run it won't display it.

@Herz3h
Copy link

Herz3h commented May 14, 2024

Same issue here with dotnet sdk 8.0, when I do dotnet publish executable works fine. If I do dotnet run it display same error:

objc[36476]: Class PlaceholderObject is implemented in both /my-project/WordGenerator/bin/Debug/net7.0/osx.13-arm64/WordGenerator (0x1027e1408) and /my-project/WordGenerator/bin/Debug/net7.0/osx.13-arm64/libSystem.Native.dylib (0x103fc8660). One of the two will be used. Which one is undefined.

@jakubmisek
Copy link

The same;

building console app using dotnet 7.0, osx-arm64:
dotnet build /p:PublishSingleFile=true /p:DebugType=portable /p:DebugSymbols=false /p:PublishReferencesDocumentationFiles=false

running the compiled executable produces the notice:
objc[57322]: Class PlaceholderObject is implemented in both /Users/jakub/Projects/peachpie-samples/console-application/bin/Debug/net7.0/osx-arm64/console-application (0x102c19408) and /Users/jakub/Projects/peachpie-samples/console-application/bin/Debug/net7.0/osx-arm64/libSystem.Native.dylib (0x1040f8660). One of the two will be used. Which one is undefined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-NetSDK untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

5 participants