Run dotnet-sos, dotnet-dump, dotnet-gcdump for a self-contained .NET Core application on Linux - .net-core

I have an Ubuntu 18.04 x64 Linux server running a bunch of .NET Core applications. All of them are published as self-contained applications and .NET Core versions vary between 2.1, 3.1 and 5.0. I don't have .NET Core runtime (let alone SDK) installed on the machine and do not want to install it.
I want to run tools such as dotnet-sos, dotnet-dump and dotnet-gcdump for a .NET Core 3.1 self-contained application. The linked pages provide direct download links for them, e.g. https://aka.ms/dotnet-sos/linux-x64. However, when I run the downloaded dotnet-sos tool it fails with
A fatal error occurred. The required library libhostfxr.so could not be found.
If this is a self-contained application, that library should exist in [/var/tmp/.net/MY_USERNAME/dotnet-sos/mrdxw5vu.czm/].
If this is a framework-dependent application, install the runtime in the global location [/usr/share/dotnet] or use the DOTNET_ROOT environment variable to specify the runtime location or register the runtime location in [/etc/dotnet/install_location].
The .NET Core runtime can be found at:
- https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=ubuntu.18.04-x64
This happens even if the current working directory is my .NET application directory, which contains
libhostfxr.so. The error implies that running the tool for a self-contained application should be possible, but the file indeed does not exist in /var/tmp/.net/MY_USERNAME/dotnet-sos/mrdxw5vu.czm/. If I manually copy that file to the above directory it then fails with
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '3.1.0' was not found.
- No frameworks were found.
You can resolve the problem by installing the specified framework and/or SDK.
The specified framework can be found at:
- https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=3.1.0&arch=x64&rid=ubuntu.18.04-x64
How do I run such tools without installing the .NET runtime machine-wide? I can easily download the binaries from https://dotnet.microsoft.com/download/dotnet/thank-you/runtime-3.1.14-linux-x64-binaries but where do I put them for the tool to find them?

Turns out the .NET SDK can be extracted to any directory and then used to install and run dotnet-dump and dotnet-gcdump like this:
curl -fsSL https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.sh | bash -s -- --no-path --install-dir ~/dotnet-sdk --channel 5.0
~/dotnet-sdk/dotnet tool install --tool-path ~/dotnet-sdk/tools dotnet-dump
DOTNET_ROOT=~/dotnet-sdk ~/dotnet-sdk/tools/dotnet-dump collect -p PID_TO_DUMP
(I did not manage to get SOS working in LLDB, however. "Installing" it works just as above, but it fails to load in LLDB.)

Related

Setting DOTNET_ROOT to directory of libhostfxr.so is insufficient

If want to run dotnet-trace on Linux, against an application that ships with its own .NET Core runtime. When I run it, however, I get:
A fatal error occurred. The required library libhostfxr.so could not be found.
If this is a self-contained application, that library should exist in [/home/user/.net/dotnet-trace/RMBGJOBRwpkX5Kvpq_FShF5s1UmJMO8=/].
If this is a framework-dependent application, install the runtime in the global location [/usr/share/dotnet] or use the DOTNET_ROOT environment variable to specify the runtime location or register the runtime location in [/etc/dotnet/install_location].
I located the libhostfxr.so library at /home/user/app/libhostfxr.so, then executed DOTNET_ROOT=/home/user/app/ dotnet-trace, but got the same error.
How do I go from the path of this library to the correct setting for DOTNET_ROOT?
According to strace, it is looking for the file /home/user/app/host/fxr which does not exist.
I ended up installing the .NET version that matched the application I was trying to debug using the install script. (I found this by using strings libhostfxr.so; perhaps there's a better way.)
A little confusingly, the runtime version 3.1.28 is not the same as the corresponding SDK version 3.1.422, which I installed with:
$ wget -O - https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --version 3.1.422
It can also be downloaded from versionsof.net which is not an official site, but it links to the files hosted by Microsoft.
This process installed /home/user/.dotnet/host/fxr/3.1.28/libhostfxr.so and I could then run DOTNET_ROOT=/home/user/.dotnet/ dotnet-trace.

Can I publish targeting linux-armv6 runtime in .NET Core 7?

According to this issue and this runtime list for .NET Core v7.0, linux-armv6 is supported. However, when I try to target it with dotnet publish -r linux-armv6 I get the following error:
C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(135,5): error NETSDK1084: There is no application host available for the specified RuntimeIdentifier 'linux-armv6'.
What am I doing wrong?
armv6 in dotnet is only community supported. You can build it by yourself. If you want, I've build it from 7.0.0 source and put it in docker image for building my project. (I use linux-armv6/self contained)
https://hub.docker.com/r/taphome/dotnet7armv6
From my experience, dotnet is working pretty well on armv6. Problem is if you have some Nugets with native libraries which probably doesn't have armv6 version of native dependencies. I switched my app.libraries from mono/netstandard20 to net7 on armv6.

dotnet build stopped working after VS 2022 upgrade

I upgraded Visual Studio Community to the final release, and it stopped working. Specifically, I could generate a new project, but when I try to load it, it gave me an error
Critical Project 'SdkTest' load failed| [MSB4236] The SDK 'Microsoft.NET.Sdk.Web' specified could not be found. ...\SdkTest.csproj
Even though build and run worked fine
I ran "repair" on VS2022, and it seems to be working now from Visual Studio. However, dotnet --info doesn't show any SDKs; only runtime; and dotnet build or dotnet new give an error:
C:\Code>dotnet new console -o myapp
Could not execute because the application was not found or a compatible .NET SDK is not installed.
Possible reasons for this include:
* You intended to execute a .NET program:
The application 'new' does not exist.
* You intended to execute a .NET SDK command:
It was not possible to find any installed .NET SDKs.
Install a .NET SDK from:
https://aka.ms/dotnet-download
I even reinstalled .NET 6 and I see it in the list of applications (along with older SDKs). I checked the path, and I see everything that I expect to see:
C:\Program Files (x86)\dotnet\
C:\Program Files\dotnet\
C:\Users\me\.dotnet\tools
I am running Windows 11.
It's known bug in VS2022 installation.
Problem is that dotnet you access is located inside Program Files(x86)/dotnet, but all sdk's are located in Program Files/dotnet. You simply need to edit PATH environment variable so Program Files/dotnet goes before Program Files(x86)/dotnet. If you don't see Program Files(x86)/dotnet in user environment variable (which is likely to happen) then edit system environment variable (located below)
Example with screenshots: https://stackoverflow.com/a/44272417/10339675

Self-contained deployment .NET Core app in Ubuntu

I wrote a test project using .NET Core and assembled the self-contained deployment for Ubuntu 16.04 as described here (see Self-contained deployment without third-party dependencies).
But when I run the app I get the following error:
An assembly specified in the application dependencies manifest (Test.deps.json) was not found:
package: 'runtime.linux-x64.Microsoft.NETCore.App', version: '2.0.0-preview2-25407-01'
path: 'runtimes/linux-x64/lib/netcoreapp2.0/Microsoft.CSharp.dll'
I am using .NET Core 2.0 Preview 2, VS2017 Preview.
I will be grateful for any help!
This is an old question, but I just ran across this when I was trying to run a .Net Core application on Linux and wanted to share the solution. If you are getting the error above, you are likely trying to execute the wrong binary. For those following along from scratch, follow these steps:
On Windows, open a command prompt in the directory of the project you want to run on Linux.
Build the project for Linux using dotnet publish -r linux-x64
I chose to target linux-x64, but you can target a specific runtime if you'd like. Runtime identifiers can be found here.
Copy the published files to the Linux workstation. Because the above command omitted the configuration flag -c, the configuration defaulted to debug. The published files will be in Debug\netcoreapp2.0\linux-x64\publish
Note: there will be binaries in Debug\netcoreapp2.0\linux-x64\ too. These are not the binaries you want to copy to your Linux workstation. If you run these binaries, you will get the error described in the OP. Copy all the files in the publish directory instead. Ignore whatever files might be in linux-x64.
On the Linux workstation, give execute permission to the binary file. My project was named ConsoleUI, so I used chmod 764 ConsoleUI
Execute the binary using ./ConsoleUI
Keep in mind that you will need to at least have the .Net Core runtime installed on your Linux workstation.

Running Mono 3.2.0 with .NET MVC 4

I am trying to get Mono 3.0 setup to run MVC4 sites under .NET 4 and .NET 4.5. I've been working through various errors, what can I do to get it up and running?
Server Configuration
CentOS 5
Apache 2.2.3
3.2.0 (tarball Sun Jul 28 00:57:40 UTC 2013); ASP.NET Version: 4.0.30319.17020
2013)
Latest XSP from git, as of the time of this post
Apache/Mono Config
MonoServerPath "/usr/local/bin/mod-mono-server4"
/usr/local/bin/mod-mono-server4 contents:
#!/bin/sh
exec /usr/local/bin/mono $MONO_OPTIONS "/usr/local/lib/mono/4.5/mod-mono-server4.exe" "$#"
Update
The crux of the problem is that Mono doesn't ship with MVC4 which the site requires. It still has the MVC3 dlls, yet it has the Razor 2 dlls but not the Razor 1 dlls which MVC3 wants to sue.
Everything you need is now available within the Mono framework or on NuGet. I've created downloadable template for MVC4 for .Net 4.0 and .Net 4.5 and some notes on resolving the issues:
http://www.cafe-encounter.net/p1510/asp-net-mvc4-net-framework-version-4-5-c-razor-template-for-mono-on-mac-and-linux
The steps from the blog post are:
git clone
github.com/chrisfcarroll/AspNetTemplatesForMono/Mvc4CSharpRazorFx45Intranet
NB This github repo includes all the required dlls in case you don’t
have NuGet working, so it’s an oversized download.
Open the solution in Xamarin Studio. It almost works out-of-the-box.
The one thing you have to do is choose one of these 2 steps to make
it work:
Either delete Microsoft.Web.Infrastructure.dll from the bin\ directory and from the project
Or, from the command line:
sudo mkdir /Library/Frameworks/Mono.framework/Versions/3.2.5/etc/mono/registry
sudo chmod g+rwx /Library/Frameworks/Mono.framework/Versions/3.2.5/etc/mono/registry
(replacing 3.2.5 with your mono version, which you get at the command line with mono --version);
The Microsoft.Web.Infrastructure.dll is required on .Net on Windows, so deleting it is not the simpler approach if you want cross-platform deployability
Success
If you want to run MVC4 on Mono, you need to use some Microsoft dlls which are not provided by Mono at this time.
A word of caution - Taking a cursory look at the Mono source, there appears to be methods and classes in the MC4 source that do not exist in the 3.2.0 build. There may be features that are broken. The site I am running is for all intents and purposes an MVC3 site built against the latest dlls.
Microsoft DLLs to copy
System.Web.Abstractions - 4.0
System.Web.Helpers - 2.0
System.Web.Mvc - 4.0
Once you copy over the dlls, if you're still having problems you may have to do some detective work if the above fix doesn't work. If you get an error message saying that Mono can't find the DLL, it's usually one of three reasons:
Troubleshooting
Is doesn't have the dll - You can try using the Microsoft version of the DLL
It's looking for an older version of the DLL when the correct one is installed in the GAC or in your project folder - An assembly in your project is likely referencing that version somewhere. You can use a binding re-direct to force the specific version you have be used instead
It stil can't find the dll - Add the assembly in the compilation/assemblies section of your web.config
You're getting a 'can't find view searched...' message - if any of the views in that particular views folder have compile errors, then you'll receive this message.

Resources