C
C#7mo ago
charlie

✅ 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
The Fog from Human Resources
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
charlie
charlieOP7mo ago
why would we need native code in the first place
The Fog from Human Resources
Why would we not
charlie
charlieOP7mo ago
because then crtain classes don't exist for different platforms
The Fog from Human Resources
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
leowest
leowest7mo ago
are u refering to something specific like WPF?
charlie
charlieOP7mo ago
why blame linux when you can just implement c calls or whatver and just make a pull request
leowest
leowest7mo ago
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
charlie
charlieOP7mo ago
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
The Fog from Human Resources
Isn't MAUI already compatible with Linux etc if GUI is the issue Pluh
charlie
charlieOP7mo ago
isn't there a wy that we can just allow non native cod in a sandbox?
leowest
leowest7mo ago
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
charlie
charlieOP7mo ago
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
leowest
leowest7mo ago
Plugs reads to me as the same of what LibraryImport and DllImport does
charlie
charlieOP7mo ago
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
leowest
leowest7mo ago
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
charlie
charlieOP7mo ago
so, from what i know, we re still working on dotnet 6 i think we are working onto dotnet 7
leowest
leowest7mo ago
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
charlie
charlieOP7mo ago
hmm, well we need a plug for the dll import from my testing with it
leowest
leowest7mo ago
but you should probably ask in #advanced tbh or even #allow-unsafe-blocks for things more indepth in terms of native code, interoperability etc
charlie
charlieOP7mo ago
ah, cheers isnt dotnet open source?
leowest
leowest7mo ago
it is you can also see the source of .net framework https://source.dot.net/ you can browse it there or in the github
charlie
charlieOP7mo ago
oh shit nice! is there a way to just download like the whole of the system class in one sweep?
leowest
leowest7mo ago
leowest
leowest7mo ago
but I would say no, specially in your case where version diverge but you can try
charlie
charlieOP7mo ago
oh nice. well i'm goimg to mark his with that checkmark
MODiX
MODiX7mo ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server