Closed rotanov closed 8 months ago
It is surprising to me that we managed to get that far into the execution; on a client-app/SDK architecture mismatch I would have expected something more like a crash when we call into hostfxr
. I guess maybe macOS transparently virtualizes the shared-library load?
@rainersigwald I'm not sure I understand, by "that far into execution" do you imply that all other dependencies loaded by the app (before the Microsoft.Build.dll) are also have wrong architecture? Or are you talking only about that far into loading Microsoft.Build.dll
?
Yeah sorry, that was me talking to other folks with knowledge of the details of how MSBuildLocator is implemented, but I didn't say that. . . .
MSBuildLocator has two main phases:
Your crash is showing a failure in step 2.
Step 1 is implemented by calling a native library, hostfxr.dll
/hostfxr.dylib
. My surprise is that that apparently works in this situation, even though I would have expected the dylib to be ARM64 and then fail to load in an x64 process.
To set expectations here, I think we should have a better error experience--but I don't expect to get this combination of x64-app + ARM64-SDK to Just Work.
Oh, I see.
I also don't expect x64 app + arm64 sdk to just work, but there's must be a x64 sdk on the machine installed, I'm not sure, by vs2022 installer, or by dotnet workload install macos
, but otherwise x64 application shouldn't have successfully build and then run.
The only SDKs that were listed by MSBuildLocator are:
MS Build path: "/usr/local/share/dotnet/sdk/7.0.309"
MS Build path: "/usr/local/share/dotnet/sdk/6.0.415"
both are apparently same as machine architecture.
As per dotnet --info
:
...
Other architectures found:
x64 [/usr/local/share/dotnet/x64]
registered at [/etc/dotnet/install_location_x64]
They are actually not present by the path specified.
But, as mentioned above x64 SDK must be somewhere on the machine.
Here's what I found, may be it'll be of some use:
-> sudo find /usr -name libhostfxr.dylib | xargs file
/usr/local/share/dotnet/host/fxr/7.0.12/libhostfxr.dylib: Mach-O 64-bit dynamically linked shared library arm64
/usr/local/share/dotnet/host/fxr/6.0.23/libhostfxr.dylib: Mach-O 64-bit dynamically linked shared library arm64
-> sudo find /Applications/Visual\ Studio.app/ -name libhostfxr.dylib | tr \\n \\0 | xargs -0 file
/Applications/Visual Studio.app//Contents/MacOS/Visual Studio Update.app/Contents/MonoBundle/libhostfxr.dylib: Mach-O 64-bit dynamically linked shared library arm64
/Applications/Visual Studio.app//Contents/dotnet/host/fxr/7.0.3/libhostfxr.dylib: Mach-O 64-bit dynamically linked shared library arm64
/Applications/Visual Studio.app//Contents/SharedSupport/VSMonitor.app/Contents/MonoBundle/libhostfxr.dylib: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit dynamically linked shared library x86_64] [arm64:Mach-O 64-bit dynamically linked shared library arm64]
/Applications/Visual Studio.app//Contents/SharedSupport/VSMonitor.app/Contents/MonoBundle/libhostfxr.dylib (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64
/Applications/Visual Studio.app//Contents/SharedSupport/VSMonitor.app/Contents/MonoBundle/libhostfxr.dylib (for architecture arm64): Mach-O 64-bit dynamically linked shared library arm64
/Applications/Visual Studio.app//Contents/MonoBundle/MSBuild/Current/bin/SdkResolvers/Microsoft.DotNet.MSBuildSdkResolver/libhostfxr.dylib: Mach-O 64-bit dynamically linked shared library x86_64
/Applications/Visual Studio.app//Contents/MonoBundle/libhostfxr.dylib: Mach-O 64-bit dynamically linked shared library arm64
/Applications/Visual Studio.app//Contents/MonoBundle/MSBuildBuilder/net8.0/osx-x64/libhostfxr.dylib: Mach-O 64-bit dynamically linked shared library x86_64
/Applications/Visual Studio.app//Contents/MonoBundle/MSBuildBuilder/net8.0/osx-arm64/libhostfxr.dylib: Mach-O 64-bit dynamically linked shared library arm64
/Applications/Visual Studio.app//Contents/MonoBundle/MSBuildBuilder/net7.0/osx-x64/libhostfxr.dylib: Mach-O 64-bit dynamically linked shared library x86_64
/Applications/Visual Studio.app//Contents/MonoBundle/MSBuildBuilder/net7.0/osx-arm64/libhostfxr.dylib: Mach-O 64-bit dynamically linked shared library arm64
/Applications/Visual Studio.app//Contents/MonoBundle/AddIns/WebEditors/LanguageServerHost/libhostfxr.dylib: Mach-O 64-bit dynamically linked shared library arm64
/Applications/Visual Studio.app//Contents/MonoBundle/AddIns/MonoDevelop.AzureFunctions/azure-functions-cli/v4/libhostfxr.dylib: Mach-O 64-bit dynamically linked shared library arm64
/Applications/Visual Studio.app//Contents/MonoBundle/AddIns/MonoDevelop.AzureFunctions/azure-functions-cli/v3/libhostfxr.dylib: Mach-O 64-bit dynamically linked shared library x86_64
Also maybe somehow related to this? https://github.com/dotnet/sdk/issues/26052
I mean, if x64 SDK is actually present at the path defined in /etc/dotnet/install_location_x64
, will MSBuildLocator list it?
Hi @rotanov,
Could you tell me the values of the next env variables on the machine where the issue exists? DOTNET_ROOT DOTNET_HOST_PATH DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR
Thank you!
@YuliiaKovalova they're all empty.
@rotanov, as I workaround, we can advice you to set DOTNET_HOST_PATH environment variable that points to the proper dotnet.exe.
Hi @rotanov,
Please let us know if you still need for help for resolving this issue.
@YuliiaKovalova No, thank you. I decided to use -getProperty:<propertyName>
cli feature of msbuild instead.
@rotanov thank you for the quick update. Feel free to reopen the issue if it becomes relevant to you!
On macOS when running an osx-x64 app on M1/M2 (osx-arm64) machine which tries to load
Microsoft.Build.dll
using MSBuildLocator after executingMicrosoft.Build.Locator.MSBuildLocator.RegisterDefaults();
it crashes with exceptionBadImageFormatException
.Probably because it locates osx-arm64 SDK instead of osx-x64.
Repro
dotnet build -c Debug example.csproj
on Mac machine with M1/M2 CPU./bin/Debug/net7.0-macos/osx-x64/example.app/Contents/MacOS/example ../../../../../example.csproj
example.csproj:
main.cs:
Environment
macOS Sonoma, XCode 15, freshly installed Visual Studio 2022
dotnet --info
: