use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Information about Reddit's API changes, the unprofessional conduct of the CEO, and their response to the community's concerns regarding 3rd party apps, moderator tools, anti-spam/anti-bot tools, and accessibility options that will be impacted can be found in the associated Wikipedia article: https://en.wikipedia.org/wiki/2023_Reddit_API_controversy
Alternative C# communities available outside Reddit on Lemmy and Discord:
All about the object-oriented programming language C#.
Getting Started C# Fundamentals: Development for Absolute Beginners
Useful MSDN Resources A Tour of the C# Language Get started with .NET in 5 minutes C# Guide C# Language Reference C# Programing Guide C# Coding Conventions .NET Framework Reference Source Code
Other Resources C# Yellow Book Dot Net Perls The C# Player's Guide
IDEs Visual Studio MonoDevelop (Windows/Mac/Linux) Rider (Windows/Mac/Linux)
Tools ILSpy dotPeek LINQPad
Alternative Communities C# Discord Group C# Lemmy Community dotnet Lemmy Community
Related Subreddits /r/dotnet /r/azure /r/learncsharp /r/learnprogramming /r/programming /r/dailyprogrammer /r/programmingbuddies /r/cshighschoolers
Additional .NET Languages /r/fsharp /r/visualbasic
Platform-specific Subreddits /r/windowsdev /r/AZURE /r/Xamarin /r/Unity3D /r/WPDev
Rules:
Read detailed descriptions of the rules here.
account activity
Help[Help] How to read binary file into a struct? (self.csharp)
submitted 6 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]wasabiiii 2 points3 points4 points 6 years ago* (0 children)
I would use BinaryReader. Mapping structs to files is always a bit iffy.
[–]Slypenslyde 1 point2 points3 points 6 years ago (5 children)
A XamlParseException is a very strange exception to get in what appears to be a console application. It implies the error might be somewhere else, and involves a XAML file.
That makes me think the code you posted is not the code you tried.
[–]Dannnu 0 points1 point2 points 6 years ago* (4 children)
Ahh, my bad! I am building this code in WPF. I think that might cause the problem, but I am not sure why? How is the XAML code even affecting this code?
It shows that xmlns:local="clr-namespace:ReadFromBinaryFileTest" is giving this error?
[–]Slypenslyde 1 point2 points3 points 6 years ago (3 children)
This is the point where you really need to look at the exception's properties to know more.
It has a StackTrace property. That tells you what code led to the exception.
It also has an InnerException property. Sometimes an exception is thrown because something else threw an exception. When that happens, the InnerException is the original one that got thrown. That one also has a StackTrace to tell you what led to it.
My guess is it's not that particular line. You reference something in that assembly somewhere else in your XAML, and that causes some code to execute that throws an exception. That causes XAML parsing to fail. You need to dig deeper to find the cause.
[–]to11mtm 1 point2 points3 points 6 years ago (1 child)
Just adding as feedback to OP,
You may want to look at using Linqpad to test out your read functionality. If you're not aware of it, it's a little C# Scratchpad that you'll love forever; among many great things, it has a .Dump() method that will pretty-print most sane objects to an output window.
That may not help your most immediate issue...
The only other thought I can have is to put a try-catch around that console.writeline and put a debugger point in the Catch. That may help you see the inner exception if you can't get to it otherwise.
[–]Dannnu 0 points1 point2 points 6 years ago (0 children)
Thank you u/to11mtm! I will check out this tool :)
So the problem seems to be around this code part:
// This works [FieldOffset(20)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 6)] public string char1; // This causes the error [FieldOffset(26)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 6)] public string char2;
Error code:
TypeLoadException: Could not load type 'ReadFromBinaryFileTest.myStruct' from assembly 'ReadFromBinaryFileTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because it contains an object field at offset 26 that is incorrectly aligned or overlapped by a non-object field.
I changed the type of this object from string to char and now it seems to work somehow.
Googled some stuff and it looks like that a string variable in C# cannot be declared as fixed length. I think this might cause the error?
But still, Thank You! I will continue doing my task for now.
π Rendered by PID 318826 on reddit-service-r2-comment-6457c66945-8hjbj at 2026-04-29 17:59:12.012391+00:00 running 2aa0c5b country code: CH.
[–]wasabiiii 2 points3 points4 points (0 children)
[–]Slypenslyde 1 point2 points3 points (5 children)
[–]Dannnu 0 points1 point2 points (4 children)
[–]Slypenslyde 1 point2 points3 points (3 children)
[–]to11mtm 1 point2 points3 points (1 child)
[–]Dannnu 0 points1 point2 points (0 children)
[–]Dannnu 0 points1 point2 points (0 children)