SteveTheMadLad
Serialize HashSet into a binary file
Yes, as far as I know, then of course it can point to other locations for the actual contents.
“How would one deserialize it” is barking up the wrong tree imo, because as far as I know e.g. a json serializer will create one for you and just add stuff to it, it’s not like it will look at the internals (which aren’t in a json to begin with), and anyway getting rid of the chance someone would be able to craft a malicious serialized binary to interfere with object creation was exactly why BinaryFormatter was removed.
218 replies
What are they trying to say here?
Eh, it's not much of an explanation.
If you've done any WinForms development, you know that for each form you have two files: one that has "Designer" in its name that specifies what controls are on that form and where they're located along with any other properties you set through the designer.
Then there's the so-called code-behind, which is where you handle events raised by the controls.
WPF instead separates the layout of a form, which you design with a XAML file, from the implementation (the behavior, as that tutorial calls it). So theoretically you could have one guy design the form, and a different guy write its implementation, which would be doable but impractical in WinForms. As an approximation, you can think of how HTML defines what's in the page, and CSS defines what it looks like.
I suggest you don't get hung up on that ".NET instances", it doesn't mean a whole lot. There must be tutorials on YT that are better put together than those on that website.
Already the first paragraph of that section says:
One of the longstanding problems that all of us face with GUI design can be solved by using XAML. It can be used to design UI elements in Windows Forms applications.If by Windows Forms they mean what we call WinForms, then that's patently false, because XAML is for WPF. If they mean a generic "windows application with forms", then that's correct. If you lack historical context, WinForms came out first, and WPF after a few years.
10 replies
Serialize HashSet into a binary file
Like, I'm not sure whether this applies to you, but if you paste the following prompt into ChatGPT, it does come up with a few suggestions:
if i have a .net memory dump containing a hashset among other things, is there a way I can build a hashset that is perfectly identical?Whether it's hallucinating or not, is up to you to figure out I'm afraid :KEKW:
218 replies
Serialize HashSet into a binary file
Yeah but do you know exactly how it's serialized? Like, if it's a set of strings but for some reason they're encoded in UTF-16, they're taking up 2x the length of a string, just as an example.
Another question would be: why do you need to do this? If you can say. I'm asking purely because someone more experienced might be able to suggest a different approach altogether.
218 replies
Serialize HashSet into a binary file
Oh okay, then if you know exactly the format you can produce your own binary file laid out identically, and then if you just care about whether they're different and don't need to do anything more sophisticated, a simple byte-by-byte comparison will do it (and even maybe optimize for the case where the respective lengths are different).
Hell, given the two byte arrays you could even pass them to a SHA-family hash function and compare hashes for minimum effort. Would be interesting to benchmark vs writing your own for loop, actually.
218 replies
Serialize HashSet into a binary file
But just to reiterate, if you don't have control over the binary file you already have or don't know how it's laid out, there isn't much you can do. Reverse engineering a binary format takes skill, luck, a lot of time and patience and dedication.
218 replies
Serialize HashSet into a binary file
I would certainly hope it isn't, otherwise a few heads would end up on a pike!
Here's a link to the docs in case they help:
https://learn.microsoft.com/en-us/dotnet/standard/io/how-to-read-and-write-to-a-newly-created-data-file
218 replies
Serialize HashSet into a binary file
For the security aspect, you might find this GH issue enlightening: https://github.com/dotnet/runtime/issues/98245
As for the problem at hand, if the
HashSet
contains primitive objects, you could think of using BinaryWriter
this way:
That's very barebones but gets you most of the way there, the result is a binary file that you can then read with BinaryReader
(or just simply read the thing into a byte[]
and compare byte-by-byte).
Reading your latest messages as I was typing this up, it appears you already have a binary file, but then it depends on how that file was written, and if it's a proper binary format with more than just the hashset entries, you're well and truly screwed if you don't know the specs.
Lastly, I did a cast to int
because that's the default underlying type for enums if you leave it unspecified, but it could be any of the integer types.
EDIT to add: do note that you can do a binary serialization even if it's something other than primitive types, it just takes a bit more design when deciding how to lay stuff out.218 replies
Which Architecture to Choose?
Sounds like a case of premature optimization to me, unless there’s hard data showing the architecture we all pretty much unanimously suggested, albeit with slight variations on the same theme, can’t possibly cut it.
52 replies
Issues loading DLL
It may be that the DLL is compiled for x64, or has dependencies of its own that can't be found and loaded (possibly because they're located somewhere Windows doesn't look). I haven't used it in ages, but I think you can still find a tool called Dependency Walker, it would tell you what other DLLs a given DLL depends on. Give it your DLL and see what it says.
I don't know much about native win32 programming, but while you do specify the full path to the main DLL, if it has dependencies, the OS is going to look for them according to some default logic. There are WinAPI functions such as SetDllDirectory and AddDllDirectory that you can use to control where the system looks for libraries, and even LoadLibraryEx which accepts flags to further control this.
Frankly, this is the sort of task where I think ChatGPT or some other LLM can help you out reasonably well.
18 replies
Docker-compose volume storing image
Not sure I'll be able to follow up if you answer, but just to get the obvious things out of the way so that it may help others:
- if you
docker exec -it apitest.api ls /unfiltered_images
can you see the actual files?
- if you docker exec -it apitest.api touch /unfiltered_images/chicken.png
, can you then see the file?
EDIT to add: the indentation in the compose file seems to be a little off for the volume, yaml can get a little weird, I'm guessing it should give you an error but it's probably worth it to fix it and try again, unless it's just a copy-paste gone wrong.
EDIT on top of the edit: if your app is running as user app
, you could add -u app
before -it
in those docker exec
commands, otherwise you're likely to execute them as root, I think.7 replies
Which Architecture to Choose?
Another opinion. What volume of incoming calls are you expecting? Just because you can, it doesn't mean you should necessarily decouple the consumer into its own external process right away.
If I didn't already have reasons to believe the system will get absolutely hammered by requests, I'd personally go for a BackgroundService.
As for polling the database, you can get rid of any problem with empty reads (and by that I mean querying and coming up empty handed because there's nothing to do) or ridiculously short polling intervals by using Redis or any of its forks as a message broker with its pub/sub pattern.
Check out:
- https://stackexchange.github.io/StackExchange.Redis/Basics#using-redis-pubsub
- https://redis.io/docs/latest/develop/interact/pubsub/
- https://stackexchange.github.io/StackExchange.Redis/PubSubOrder
Doing things this way, you know exactly when you have something to do and avoid bothering the db. It's also a matter of how fast you need the results and how long the processing takes. If the processing itself doesn't take very long and messages don't have to be processed the second they come in, a tiny SELECT every few seconds is probably not going to kill anyone.
I say, keep it simple unless you already know the traffic will be crazy, or if the processing has to carry on no matter what even if the main app goes down. If it does become crazy, it's then fairly trivial to move the BackgroundService class and make it its own app (without changing anything, because you're using Redis anyway: as long as the machine where you put the consumer can access the same Redis instance, you're golden. Things do change if you already know you're gonna need multiple consumers).
Do note that, if you really want to use Kafka, you can still go for an in-process consumer, and move it out-of-process should you need to.
52 replies
Microsoft Authentication in an iframe
This is just an idea, but assuming you have control over both apps, have you considered passing what you need via postMessage in JavaScript?
https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
be sure to read about the security implications, of course, even if it’s an internal app.
2 replies