✅ native code in .net
got a question about the native code in the dotnet universe.
why do we need it?
is there a way that we can remove the native code so that we can have better support on linux?
28 Replies
Doesn't .NET already notify you when certain functions and such are only available on a specific OS?
Afaik System.Drawing(.Common) has a warning telling you it's only available on Windows
There shouldn't be any big issues running C#/.NET on a Linux system, I do it all the time
why would we need native code in the first place
Why would we not
because then crtain classes don't exist
for different platforms
Native code depends on your OS features
If for example System.Drawing is only available on Windows it might be, because the system libraries support it
In that case you should blame Linux and not dotnet
In most cases dotnet runs on any OS perfectly fine
are u refering to something specific like WPF?
why blame linux when you can just implement c calls or whatver and just make a pull request
or some framework that is windows only?
because if u are then the answer is that is not that simple
using WPF as an example its so tied coupled with DirectX that you would need to completely rewrite it, in order to make it xplatform compatible
so i'm learning the Cosmos framework https://github.com/CosmosOS/Cosmos . and i'm reading the discord and wondering why we have to make methods directly in C# that do the same thing as native code but can be packaged for other systems where the native code doesnt exist
GitHub
GitHub - CosmosOS/Cosmos: Cosmos is an operating system "constructi...
Cosmos is an operating system "construction kit". Build your own OS using managed languages such as C#, VB.NET, and more! - CosmosOS/Cosmos
Isn't MAUI already compatible with Linux etc if GUI is the issue
Pluh
isn't there a wy that we can just allow non native cod in a sandbox?
can u provide some examples? because there are a lot of things that in order to access it you have to access the native code of the specific OS, as c# can't directly access it.
by either wrapping around a library or something
there is also the standardization problem between all distros
so, plugs replace native code by writing them in C#.
currently most of the community has to work around System.Void and it's related classes because it's a sort of "native" class.
being able to work with something that would allow us to use them somewhere else would be nice like Cosmos. because i think we spend more time writing asm like code using X# or actual ASM code to get around this which brings up the point of even doing it in C# in the first place
Plugs reads to me as the same of what LibraryImport and DllImport does
here is what i can find related to plugs https://github.com/CosmosOS/Cosmos/tree/master/source/Cosmos.System2_Plugs/System
GitHub
Cosmos/source/Cosmos.System2_Plugs/System at master · CosmosOS/Cosmos
Cosmos is an operating system "construction kit". Build your own OS using managed languages such as C#, VB.NET, and more! - CosmosOS/Cosmos
GitHub
Cosmos/source/Cosmos.Core_Plugs/Interop/Advapi32Impl.cs at master ·...
Cosmos is an operating system "construction kit". Build your own OS using managed languages such as C#, VB.NET, and more! - CosmosOS/Cosmos
P/Invoke source generation - .NET
Learn about compile-time source generation for platform invokes in .NET.
so, from what i know, we re still working on dotnet 6
i think we are working onto dotnet 7
well I dont know cosmos enough to tell details
I just looked portions of it related to what u asked
but DllImport exists since .net framework
LibraryImport is new
when it was introduced I am unware
yeah libraryimport apparently was .net 7
hmm, well we need a plug for the dll import from my testing with it
but you should probably ask in #advanced tbh or even #allow-unsafe-blocks for things more indepth in terms of native code, interoperability etc
ah, cheers
isnt dotnet open source?
it is
you can also see the source of .net framework
https://source.dot.net/
you can browse it there
or in the github
oh shit nice!
is there a way to just download like the whole of the system class in one sweep?
GitHub
runtime/src/coreclr/System.Private.CoreLib at main · dotnet/runtime
.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps. - dotnet/runtime
but I would say no, specially in your case where version diverge
but you can try
oh nice. well i'm goimg to mark his with that checkmark
Use the /close command to mark a forum thread as answered