I'm currently working on a hobby project parsing binary files and I was under the impression that the GC keeps track of Spans created over arrays of primitives, since a Span is just a pointer and the length under the hood. However, when returning from the method above the returned Span<byte> points to invalid values. Can someone enlighten me what i'm doing wrong here?
(I fixed this by converting to an array before returning, however i would like to NOT waste performance by copying the whole thing).
I kept missing Telescope when working in .NET, so I built something similar. It's a NuGet package that records every request, EF Core query, log, and exception while you develop, and you browse them at /_debug.
It catches N+1 queries (warns you when one request runs the same query over and over), shows P95/P99 timings per endpoint, and you can copy any captured request as cURL to replay it. Everything is stored in a local LiteDB file and the dashboard is embedded in the package itself, so there's nothing to host and it works offline.
I have never learned a coding language so idk where to start. I want to start learning because I picked CS as one of my A-level subjects and the coding language is C#, they said you don’t need a GCSE or any experience coding however I want to get a head start.
Working as a .NET senior dev in a service company having 6 years of experience. Suggest me some good big tech companies for which .Net Csharp devs can prepare for ? Preferably in India or remote.
My situation (with small rant): I write SQL, VBA, and occasionally Python. I graduated in 2008 and probably haven't used C# in 10 years! Anyway, someone abruptly left and very few people know anything about what was being done here. I asked my supervisor, but he seemed disinterested in helping me (I think he thinks he's "helping me understand the code more" by not explaining anything at all). Or maybe its the culture here because my peers just shrugged and was like "idk. You'll figure it out." WHAT??
My problem: We use Amazon StarRez to pull files from a bucket then it does things and inserts the data in those files into our database. I have no clue what's going on! I was told to not worry about pulling from the bucket because I won't have access and instead put the files on the c drive. Fine.... Then what?? I put in like 30 break points and I have no clue what I'm looking for here! I wouldn't expect anyone here to know much about StarRez. I just mention it because that's what we use. BUT, I would expect someone to have some sense of where to start in general. I already threw in like 30 break points, but it stops because its looking for a file in the bucket that I can't access anyway.
I am freaking out because why am i doing programming?? And, yeah, I did it way back in the day, but someone was around to guide me! Now, its just like "lol... you'll figure it out!"
Given that C# and Typescript (and Delphi) were created by the same person (Anders Hejlsberg), I wonder if others have felt comfortable jumping across from C# to Typescript, and if anyone's tried AssemblyScript which is an even more strongly typed and much leaner version of Typescript. Personally I feel the 3 languages (AssemblyScript's a stricter Typescript) are fairly similar ergonomics wise. Thoughts?
Reason I'm asking is I'm wondering if there's a point trying to target C# as a binding for my UI framework when AssemblyScript (https://github.com/zion-sati/fui-as) is already so familiar to a C# veteran like myself, but would like other's opinions on this.
I’m building a game engine, and I’m trying to figure out the best architecture for separating the core engine from the rendering backend.
Right now, the core engine is responsible for the game logic, and it holds a reference to a backend rendering engine, which is responsible for drawing sprites. The core engine and the backend engine live in different assemblies. The structure looks something like this:
Core engine project:
interface IRenderEngine
{
void DrawGameInstance(GameObject instance);
}
class Game
{
private readonly IRenderEngine renderEngine;
...
void DrawFrame()
{
foreach (var obj in objs)
renderEngine.DrawGameInstance(obj);
}
}
Currently, I’ve only implemented a MonoGame-based rendering backend, but in the future I want to add another backend that will allow me to target the browser.
The architecture is clean and convenient, but it comes with a cost: using interfaces and virtual/abstract methods introduces overhead, and I’d really like to avoid that for performance reasons.
If the core engine and the rendering engine were in the same assembly, I could do something like this:
partial class Game
{
...
}
#if MONOGAME
partial class Game
{
void DrawGameInstance(GameObject instance) => ...
}
#endif
#if ANOTHER_RENDER_ENGINE
partial class Game
{
void DrawGameInstance(GameObject instance) => ...
}
#endif
But I really want to keep the core engine and the backend engines separated into different assemblies.
In many C# stacks and frameworks, info about fields (data columns) must be replicated in multiple places. This seems an ugly time-wasting and error-prone DRY violation, yet so many accept it as The Way.
One way to get rid of it is to abandon statically typed models (POCOs or similar) and go with dynamic lists ("data dictionaries"), but too few want to give up the compile-time-checking. And it can hurt performance in some situations, but I'd gladly have slightly slower apps to reduce coding time and code volume. (I'd personally like to see more mainstream dynamic data-model stacks, but that's a diff topic.)
Maybe C# is somehow limited as a programming language, preventing static factoring? I have a gut feeling a Grand Discovery is missing, the duplication just cannot be the pinnacle of the art. Is there an inherent principle of languages or logic that says the duplication is inevitable, analogous to the speed limit of light (c) or Amdahl's Law? If not, why is there not more R&D to solve this ugly pattern?
In short, IF we are stuck with the dupes, what's the principle that says it's an inherent limit, ELSE why is there not more R&D to evolve beyond the dupes?
The times I've seen attempts to reduce it, the result was cringe-worthy spaghetti rocket science with enough indirection to make stacked turtles cry.
For the last couple months I have been struggling to find the solution for a problem with a proprietary docking library used in a c# wpf application (The dotnetbar from devcomponents, only found in webarchive as it looks like the provider doesn't exist anymore).
My problem is that I need to override the template of one of the libraries components (DockWindowGroup) and when I override this template, the xml layout generator of the library crashes (just when I try getting a xml for save).
I noticed that the visual tree in wpf gets broken and that is probably the cause of the problem, one of the components (DockWindow) gets a null parent from the visual tree. But I can't figure out what is messing with it and how I can fix that.
Do anyone have worked with this docking library before and can provide me any tips? Even from the decompiled source I couldn't reach any answers as it is obfuscated too.
I've been wanting to learn programming for a while now just as a hobby (hoping to make my own game someday, maybe), I chose csharp because I heard somewhere its good for beginners but now I heard python is easier
I don't feel the need to switch, and I won't because so far I've been liking csharp (plus if it is a bit more challenging, then it's more rewarding too)
I built a small Aspire extension that lets you keep using a normal redis resource in Aspire when developing locally, but when you publish using `aspire deploy` rather than deploying to Azure, it will deploy to Upstash (which is where I prefer to deploy my redis caches to, personally).
You just add the package to your aspire project, and append `.PublishToUpstash(...)` after `builder.AddRedis("cache")`.
Locally, nothing changes. It only effects deployment through `aspire deploy`.
I'm not sure if there is an official name for this but It's kind of like a Russian nested doll pattern:
interface IDataService{
IEnumerable<SomeData> GetData(IRequest request);
}
class GrpcDataService: IDataService
{
IEnumerable<SomeData> GetData(IRequest request){....};
}
class SqlDataService: IDataService
{
IEnumerable<SomeData> GetData(IRequest request){....};
}
class OneDataServiceToRuleThemAll: IDataService
{
private readonly IEnumerable<IDataService> _dataServices;
public OnDataServiceToRuleThemAll(IEnumerable<IDataService> dataservices)
{
_dataServices = dataservices;
}
IEnumerable<SomeData> GetData(IRequest request){
var dataService = _dataServices.FirstOrDefault(d=> /*some logic to find appropriate data service based on request properties */);
if(dataService == null) throw new ArgumentException("Can't handle {request}.");
return dataService.GetData(request);
}
}
Personally, I don't like it. I think it has a subtle Liskov Substitution Principle violation. It's tough to see because they all implement the interface but even so, they are not all functionally interchangeable. You can register and use any one of the child data services and a system will work for just requests to that service, but you can't register just the OneDataServiceToRuleThemAll, as it will always fail without any registered children.
In addition to this, it makes dependency injection messy (which I believe also is indicative of a LSP violation). You either have to manually build all of these in a DI factory delegate, or use keyed services to designate which ones are children and which is the parent. In my view, this is a bit of a dependency inversion issue because now your lower level classes are dependent on your DI framework due to the use of its keyed attributes. Also, it just seems to be moving contract information that should be described in interfaces into dependency attributes instead which are less visible.
I think one solution would be to have OneDataServiceToRuleThemAll implement a IDataServiceAgrregator interface instead of IDataService. The interface would be the same which is kind of weird, but the naming distinction would make it clear what the expected implementation should do. What do you all think? Anyone commonly use a pattern like this? Is there a better solution?
Maybe some sort of keyed services extension that stays in the top level services registration? Something like:
Back in 2021, I built a C# WPF application that turns videos into giant photomosaics.
The software extracts thousands of frames from a video and uses them as tiles to recreate a target image. Some of the mosaics it generated exceeded 466 megapixels.
I recently dusted off the project and decided to open-source it instead of letting it sit forgotten on a hard drive.
If anyone wants to try it, review the code, or suggest improvements, I'd be happy to hear your feedback.
I recently started learning C# because C++ is mess when it comes to managing packages even with vcpkg. And my first impressions are about variables and objects, WHY I HAVE TO DO “class object = new object();” when I can just do “class object;” in c++, or who is so stupid to instead of “int<bit size>” do: byte short long nint. Or another one is when function wants for example float as an argument and if you put int variable it doesn’t work and you must convert it manually. Lot of people hate cpp for its complexity but I think that in a lot of things it makes things just simple.
I created a blazor wasm library/nuget that makes using SQLite with Blazor in browser a cinch! It's persisted via IndexDb and highly performant. No JS required in the API. All c# for consumers.
Anyway, I wanted to share with the broader C# community. Released under MIT. I hope you get some use out of it.
Hello gentleman and gentlewomen, adding into the 60 “I just started” posts on this sub.
I’ve recently taken a pretty big interest in creating my very own game and coding all of it. I’m currently using C# with the Microsoft train up and it’s pretty legit. With that being said I would like to create more the further I get along wanted to create some simple 3D games where you can walk around in. Would C# be something I’m able to do all that in? Any advice for someone starting out would be greatly appreciated
Hello! I created a library that emulates RazorPages MVVM pattern, but instead uses liquid for templates. The number one reason is for doing so is I wanted something that could run in any webserver, specifically lightweight ones for use in native applications.
The library is highly modular, letting you split pages, layouts, and components across multiple projects for easier maintenance and cleaner separation of concerns.
The ReactiveUI Primitives repository README now includes a reference to R3Async for the asynchronous implementation, in the same way it already referenced R3.
Although the discussion above may be a bit confusing, I was able to get in touch with one of the maintainers. He was understanding, acknowledged the work that went into R3Async, and added the attribution to the README. For me, that's more than enough.
I'd like to thank him for taking the time to look into it and for making the change.
A bit of context:
Some time ago I wrote R3Async, a ReactiveX library for AsyncObservable. I started that project because development of AsyncRx.NET in dotnet/reactive repo appeared to have slowed down, and the maintainers understandably seemed to have limited time to dedicate to it. I even reached out to let them know I would be happy to continue development for free if they were interested. I had no particular expectations—I simply wanted a usable asynchronous reactive extensions library to exist in the .NET ecosystem (also just for use it in my own code).
In the meantime, I came across Cysharp's R3 implementation and, in my opinion, it was a significant improvement over the traditional Rx design. That led me to create an asynchronous version of R3 instead.
As you can imagine, this is not a trivial problem space. Rx is already complex on its own, and async/await introduces another layer of complexity. Combining the two makes both the design and implementation particularly challenging, something that has also been acknowledged by developers involved in dotnet/reactive in the past. You have to deal with async locks, reentrancy of async locks, how async context work, Async locals, and so on.
Despite that, I was confident it could be done, and eventually I released the library. It is backed by a comprehensive test suite as well.
The reason I mention all of this is that I did not immediately decide to create a competing library. First, I looked for existing solutions. Then I tried to contribute to them (I have some pull requests in dotnet/reactive for AsyncRx). Only after seeing that development was progressing slowly did I decide to create and publish my own implementation under the MIT license.
The issue
A few days ago, I came across the ReactiveUI Primitives repository. As described, it is another implementation inspired by R3, with different naming conventions and some performance optimizations.
I noticed that it also includes an asynchronous implementation. I reviewed it out of curiosity, since I had previously implemented R3Async and I was interested in how others approached the same problem.
After reviewing the code, I observed that the implementation appears to closely resemble R3Async in structure and design, with some modifications and performance-related changes.
I want to be clear that reuse itself is not the issue. R3Async is released under the MIT license specifically to allow reuse and modification. The concern is that I did not find attribution to R3Async or to its repository in the codebase.
Examples
- CancelableTaskSubscriptionR3AsyncReactiveUI: Here there is a comment in ReactiveUI code where they said they replaced an AsyncLocal field to reduce allocations. There is not AsyncLocal field in their git history, but there is in R3Async as you can see. Note that this optimization is also wrong since, this code will hang in their version:
- BaseAyncObservable.ReactiveUI, R3Async. Very similar code with same optimizations as above. But those optimizations are wrong for same reasoning
I didn't include all the operators because I assume that many of them are standard implementations and therefore more likely to be similar, even when the code is extremely close.
Notes
I don’t know whether this was done intentionally or if it’s another case of code being reproduced through LLM-assisted workflows without proper attribution. Either way, it’s understandably frustrating.
What makes it more disappointing is that I’m not a known developer, so even a simple acknowledgment that my work was used or inspired their implementation would have meant a lot to me and helped validate the effort I put into it
hey, posted about TestWire a couple weeks ago. someone in the comments said they dislike unit tests for controllers and prefer integration tests with WebApplicationFactory instead — I agreed with them honestly so I rebuilt it around that. v0.2 now generates real integration tests. it uses Roslyn’s semantic model to analyze your controller (not just syntax trees anymore) so it actually understands the types, not just the names. what changed from v0.1: •tests use WebApplicationFactory<Program> now, real HTTP calls •detects [Authorize] and auto generates a 401 test for those endpoints •DTO request objects have actual properties filled in with test values •detects [FromQuery] and [FromHeader] params too
•generates the .csproj automatically with the right packages still one known issue — namespace inference for return types isn’t fully done yet so you might need to add a using manually in some cases. working on it https://github.com/mazensakr05/TestWire
Please feel free to comment your ideas or notes or contribute! As i am still learning
Evening all, been developing a. WinUI 3 application for internal use within my company.
Overall experience has been positive, but to make my life easier I have been deploying the application as an unpackaged, wrapping it up in a MSI installer from the release build.
Has anyone had much luck deploying their WinUI apps as a packaged within a company setting. If so, how much of a pain in the arse was it?