✅ This is a new set of errors to me
I've never seen this error before so I'm not sure how to go about solving it. I did google it though, and found this stack overflow https://stackoverflow.com/questions/47321869/how-do-i-convert-a-c-sharp-string-to-a-spanchar-spant, and tried their solution, but now I get
I also tried the next comment below it
and got the same error as the ReadOnlySpan<T> so then I tried the other part of that comment
and got these errors so I'm just not sure what to do
83 Replies
when I look at the
Write
method, it shows that it's looking for a Write(byte[] buffer, ...)
so that's a clue I'd imagineafter googling that
ohhhh
you're absolutely right. I didn't even notice I was using one or the other
I need to use stream writer to write to the file
FileStream requires u to write a buffer to the stream
StreamWriter works on top of the stream to facilitate that process allowing you to write strings
to it
FileStream requires u to write a buffer to the streamwould that be a list a bytes array of files to be used?
it can be a Span or a byte array yes
not byte array of files
but the information to/from the file
so for example
while you write out your example
You would encode that to bytes and then write teh resulting buffer
what I'm trying to achieve it a bit of automation with the checking for an update. I use the GitHub api for the repo's releases and some C# to download, extract, etc, but the person of the version.txt file is to hold the version of the release I just finished working on, so like when I create the new 1.0.0 release on the repo, I'll then change the version.txt file in my editor to say 1.0.2 and then I'll create another release. I'll manually download the 1.0.0 release onto my desktop and I'll run the executable from there. It'll query the github api and get the version number of the latest release on the repo. If the numbers don't match, then the program will present a screen sayign there is an update 🙂
would I do this like
you dont need StreamWriter in my example but you have the extra load of having ot turn your data into bytes to write it to the stream
if u use streamwriter
this is how it works
I like this. It's nice and simple
thank you ❤️
u see how much simpler it is to write to the file?
you can also change the encoding etc if need
in regards what you're doing
what kind of project are you working on?
I'm building a grade book
because there is or was a visual studio extension
it's an avalonia project and right now I'm working on the updater mechanism of the project
that when you build your project it automatically increases the version number to your manifest
Increment Version on Build - Visual Studio Marketplace
Extension for Visual Studio - Increment Version on every build according to configureable rules.
I remember trying to go that route before programmatically, but it was a headache so I just stuck with having a version file
I see
plus it makes for easy troubleshooting as well. If a user gets an issue with the latest update that causes the update to not work, then in the troubleshooting screen on the repo, there'll be information on how to locate the program, find the version.txt file, and how they can edit the file to change the version number back to a version that they know worked, send the error through the help button at the top of the screen, and I can work on fixing it and push a new update and send them an email back letting them know that they can update then
I see, I use squirrel for updates
I can set afterbuild actions on release that generates the deltas
all of that was over my head 😂
then u just need to add a few lines of code to your app and it will check for updates on startup
its super simple 😛
but yeah just saying squirrel is a cool tool for what you're doing
but you probably already have your solution made
After build is basically an event you can setup in your csproj
so that when you build your app in release mode or debug mode it does something after its done building
you have Pre and Post events so before u build and after you build
so basically squirel creates a MSI setup file on post build
that's pretty cool. I'm going to save the message link of that explanation and on my next project which is a desktop math game, I'll come back, and get your help on setting that up and stuff
no worries sorry that I ended up adding all this unrelated info hehe 😛
so basically just use StreamWriter for your version file u dont need FileStream for that
gotcha. I put your code in, and am fixing to test it. just a moment
ok so side question. I am on the newest version of Visual Studio. When I create a new avalonia desktop project now, it gives my project a Project.Desktop that is used to when you press the run button to build and run the application and it gives you just a Project file that you use to build your screens and such in. So like for me, I have a GradeBook.Desktop (target for the green run button) and a GradeBook folder where I build my screens and logic and stuff in. Why did that do that lol Your code works, but since I have to target the GradeBook.Desktop for the green play button so that the project builds and runs for testing, it puts the files that I create and such in the GradeBook.Desktop/bin/Debug/net7.0 folder instead of the GradeBook/bin/Debug/net7.0 folder and that's so annoying lol I'm just wondering why they changed it all. What was wrong with the version before
well I have never played with avalonia yet let me give it a look
I definitely appreciate it
its ok been meaning to try it to see how different it is from MAUI for mobile
which template u used to create your app so I use the same?
I tried to do a project in MAUI. I was going through some websites tutorial on it and we built a little math game with it. MAUI for desktop is pretty neat, but for some reason I prefer the much harder stuff like Avalonia
if we are talking about windows only
then I would use WPF instead
which of these u used for your project so I go the same route
oh reactiveui not sure I will be of much help o nthat but will see communitytoolkit is what im normally use to
I see so the other project is a library
and Desktop is the actual application
so whenever u run it will always deploy everything to desktop
it never runs from the library
if u notice on the folder
GradeBook.Desktop/bin/Debug/net7.0
I wanted to do CommunityToolKit but I couldn't figure it out, but I love how easy it is
I adore community tool kit
well with community toolkit
right. But this setup only makes sense when you're developing the same application across multiple platforms like Mobile, Web, Desktop, and there's one other. For just a desktop application, it should be stand alone, imo
all that would be just
also u should not make your field public
yea forgot that decorator
so the decorator creates all the above under the hood for u
and that's why I like it lol
anyway back to the topic
if u look in the folder
So now I've got two goals for my next project
1. Build it using CommunityToolkit instead of ReactiveUI
2. look at that squirrel thing
GradeBook.Desktop/bin/Debug/net7.0
u will also find a GradeBook.dll
that is your GradeBook folder as u say
what it does is it ships everything to the Desktop folder as the class library is referenced and needed by the Desktop wrapper
as you can see in the references of the Desktop
u will see something similar to your GradeBook
so basically, if I had the other platforms in here along with the desktop application, Each one of those platforms would be a library that the
.Desktop
wrapper calls to, or the platform dependent calls to
I get what you're sayingwell no
they would be like Desktop
you only have 1 library with all the views etc
so then when I publish, I need to publish to the GradeBook.Desktop/bin/Releases/windows folder
Desktop is just the wrapper delivering it to the desktop with the correct API for desktop ui etc
so if u had mobile, you would have another project targeting android for example
let me create one to see
but essentially everything goes into GradeBook
and only if u have something very platform specific u would handle it in the specific project
build in one place, and then call the platform that is needed to run and debug/build
i.e.: .Android
ok so then I feel like I've been doing my publishes wrong. When I go to publish a .exe, I use the publishing wizard. After the wizard, I edit the path for the files, and I always publish it to
Project/bin/Releases/net7.0/windows
for windows applications. Am I not supposed to do that anymore? LIke now I believe I would publish to GradeBook.Desktop/bin/Releases/net7.0/windows
instead?well publish is exactly for that purpose to build the app to distribute
what we were doing was debuging and running it for development
so when u want to publish yes that would be the correct route
right. I now have to build an exe so that I can test my updater so I'm confirming where I'm supposed to be publishing to lol
ok cool
u right click the platform u want to publish and do the wizard for it
right which is GradeBook.Desktop
yep
wait
I said all of that wrong
when u publish Desktop it will include GradeBook and all its dependencies to it
and since Desktop depends on GradeBook any time u publish Desktop it will save GradeBook or ask to save if anything is open and get all the new stuff in it
Desktop is nothing without GradeBook other than an empty DI shell
right. ok one second and I'll be able to explain
when I build my updater and gradebook projects to an exe using the publisher, I then do the following:
1. Right-click GradeBook project and select Add Existing Item
2. Navigate file explorer to find the
.exe
for the Updater project (this is the project that updates the gradebook project and then relaunched it once finished)
3. Select the Updater.Desktop.exe file and instead of clicking Add, I click the dropdown arrow on Add and select Add As Link
4. In VS, I right-click the added existing item, and change it's properties to Copy If Newer
I do the same thing with adding in the GradeBook.Desktop.exe file into the updater project.
The flow is:
1. user runs executable for gradebook program
2. gradebook queries the github api for the version number of the latest release
3. If the versions do not match, it displays that an update is available
4. The user selects to start update
The updater program downloads the zip folder for the windows os from the latest release on the repo. It then extracts those contents to a temporary folder. After extraction, it then iterates over all of the files and folders in that temp folder and it checks to see if that file/folder already exists in the gradebook. If it does, delete it from gradebook, move new files from temp to gradebook in its place. Once update is finished, alert the user we're done and relaunching the application.
so my question is, when I go to link the executables to each project respectively, do I need to link it into GradeBook or GradeBook.Desktop?
apologies. I know that's a lot to read. I couldn't think of a better way to explain itok im a bit confused by the first part hahaha
when I build my updater and gradebook projects to an exe using the publisher, I then do the following: Right-click GradeBook project and select Add Existing Item Navigate file explorer to find the .exe for the Updater project (this is the project that updates the gradebook project and then relaunched it once finished) Select the Updater.Desktop.exe file and instead of clicking Add, I click the dropdown arrow on Add and select Add As Link In VS, I right-click the added existing item, and change it's properties to Copy If Neweryou create your updater and u add it to Gradebook? why you could just make it publish to the same folder if u need to ship them both together Well I dont think u need to link anything so long as they are shipped together all u need is the proper code in each project I see 2 scenarios, either u send Updater.exe to the user and if it does not find GradeBook.Desktop.exe it assumes its a new install and install the whole thing 2 scenario would be u ship the whole thing so it install everything together When you run GradeBook it would have some logic to check version, if verion does not match, it would close itself and launch the updater updater would check what it needs to do, do it, replace files, and call Desktop again
yea i built my own updater lol
that's fine you dont want your own app self updating it self as it would be classified as virus
so yeah I would probably just give the user the Updater for download and once they run it
no it doesnt. updater only updates gradebook. then closes
and installs and run the main app
ok so basically what I was going to do was have 3 projects in 1.
Project 1 is the installer that will handle downloading and extracting the zip folder from the github repo and placing the contents in the users Programs folder. Once finished, it'll launch GradeBook.Desktop.exe
Project 2 is the updater which will handle updating the project anytime I produce a new release. Unlike the installer and gradebook projects, the updater is built once and used forever. I may go back and optimize it, but that's not going to happen for a while so it'll handle updating the installer and gradebook projects accordingly and once the updates are finished, it relaunches GradeBook.Desktop.exe
Project 3 is the grade book program itself which the user uses. When it launches, it checks to see if the version.txt file exists > create if not. Then it checks the versions between the repo's latest release and the text file match. If not, then it presents a window to the user that update exists and asks do they want to update. When they click yes, it closes the GradeBook program, and starts a new process with the Updater.Desktop.exe file
technically that is 4 projects
are u producing Updater as a single file?
if so I would just set a Post build event to copy it over to Dekstop publish folder
installer (one), updater (two), gradebook (three)? I'm not understanding 4. and yes each project gets published down to its own executable
ah so you're also doing a separated installer
right. There will be a setup.json file that will be added in with that project and the json file will store a boolean value. Once the installer finishes setting up the program, it'll change that stored boolean to a true value so that way the installer only ever runs once. After that initial time, the updater takes over things from there
your logic there sounds fine
dont see anything wrong with that
oh ok cool 🙂
I'm writing my database logic for creating my relative database. I'm trying to find a good way to link these three tables together through a common variable. For example: The principle receives a new student and they get enrolled. The students information will go into the students table, the students parents information will go in the parents table, and the student will get assigned to a teacher, or number of teachers, and the teachers information already exists for when they were added to the gradebook on hire. So if a teacher needs to see parent/student information or the principle needs to see what teacher is assigned to the student, what's a good way to link these three tables together so that I can just do one database call and have access to the all the information from all 3 tables?
well that is a question for another topic 😛 u might want to create a separted #help for that or ask in #database
and $close this one
Use the /close command to mark a forum thread as answered