why am i missing Syntax?
im watchign a tutorial that is teaching me how to save stuff in a json file and then in the tutorial he procedeed to use Syntax that i dont have, and when i do it gives me an error
169 Replies
this is the code itss pretty simple
the issue lies in the File.WriteAllTextAsync
apparently WriteAllTextAsync doesnt well exist
What's the exact error?
this is the error
"File Does not contain a definition for "WriteAllTextAsync"
What's your .NET and C# version?
It's in the
.csproj
file
Or project propertiesim using .Net Framework 4.7.2 i think
oof NSJ
That's... old
oh
Any reason to use it in particular?
not one that i can think off
$newproject
When creating a new project, prefer using .NET over .NET Framework, unless you have a very specific reason to be using .NET Framework.
.NET Framework is now legacy code and only get security fix updates, it no longer gets new features and is not recommended.
https://cdn.discordapp.com/attachments/569261465463160900/899381236617855016/unknown.png
only time i used C# was in unity but i want to use it for other stuff since i heard its not all that bad
"Not that bad"
Man, C# is great lol
Not "not that bad" :KEKW:
im used to people calling it dogshit
i like it, but everyone else said its useless outside of unity
and its carried by unity
"its just java made by microsoft"
You're in the wrong crowd lmao
so its good?
Yeah
well thats nice to know
atleast im learning a language that is somewhat useful
Ever since .NET Core it runs everywhere and does basically everything
Web, desktop, mobile, games
Unity's implementation of it might be dogshit, yeah
But not the language itself
i think those were java programmers
Maybe
They have the Stockholm syndrome lol
Regardless, the current version of .NET is 9.0
And current version of C# is 13.0
holy macaronie
will i lose any progress?
Nah
neat, how do i update?
You can create a new .NET 9 project, copy-paste your existing code, and let it rip
You can even skip adding
Newtonsoft.Json
since JSON serialization is built-in nowi have to copy paste it? :tear:
Well, you can try to upgrade the existing project
Depending on what kind of
.csproj
file it isleowest
Quoted by
<@85903769203642368> from #why am i missing Syntax? (click here)
React with ❌ to remove this embed.
Could try the upgrade assistant too
how do i check that 😭
Open the project dir in explorer, open the
.csproj
file with Notepad or whateverwhere do i find the dir 😭:g_SadPepeClap:
Well, where you created the project
ive never programmed outside of unity so i suck
directory?
ye
Directory, folder, whatever
path
i opened it and i see hella text
Paste the first few lines here
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{FC88AF97-EE09-4E6C-9AA7-2B7BBE1250D3}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Gaming_Bot</RootNamespace>
<AssemblyName>Gaming Bot</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
only things that i think are usefull aree the TargetFrameworkl which is 4.7.2
Yeah, that's the old-style
.csproj
so that means i cant update the file directly?
Could still try ig
any chance of corruption?
Back it up somewhere, and replace the contents with
Just in case something does break, keep a copy of the old one
what contents?
Of the file
from the
.csproj
?ye
everything?
do i delete everything from the file then paste that in?
Yes
well nothing seems to be broken
syntax seems to alos work now but now its saying this
in the file thing it says that the bot is unloaded
Right...
Let's see if you have the .NET SDK installed
that sounds bad
Should be, with VS, but let's double-check
i think i do
Open a terminal (Powershell, CMD, whatever) and type
dotnet --list-sdks
8.0.204 [C:\Program Files\dotnet\sdk]
thats all i got
do i paste this in?
Or intall .NET 9 SDK
what do u recommend?
The latter
latter?
Yes
and that means?
winget install Microsoft.DotNet.SDK.9
so update?
upgrade assistant works nicely have suggested it to plenty of people that came back to me saying its nice there is also a wizard on visual studio now for it
sorry been busy irl
I just dont remember if it creates a backup for u but im fairly sure it does
oh updating is just an .exe file
Gaming Bot.csproj : error : The project file could not be loaded. Data at the root level is invalid. Line 1, position 1. source\repos\Gaming Bot\Gaming Bot\Gaming Bot.csproj
:tiredge:
wdym by wizard
mmmm its a visual thing on visual studio
let me see if I can find the guide
how to install
https://learn.microsoft.com/en-us/dotnet/core/porting/upgrade-assistant-install
and then u go to this one on how to upgrade
https://learn.microsoft.com/en-us/dotnet/core/porting/upgrade-assistant-how-to-upgrade
are u sure you are in extensions? and not nuget manager
i see the work NuGet alot so i think im in the nuget manager
yeah that is diferent place
up top in the menu
it also suggests u do this with no project open
so I dunno if that could be it
the first steps that is
smth like this?
on that window bottom right u would see continue without code
yeah i clicked it
now just follow the rest of the guide
is that from the 2nd page?
or still on the first page
oh i updated it, i think i need to install smth else
well its saying you dont have .net 9
i do
but u could have upgrade it to ,net 8 instead if that is what u have
i have 8 and 9
are u sure because it says otherwise
8.0.204 [C:\Program Files\dotnet\sdk]
9.0.101 [C:\Program Files\dotnet\sdk]
:Hmm:
when i do dotnet --list-sdks it returns me this
Old VS?
what did i mess up 😭
can u post the content of the csproj it generated?
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<OutputType>Exe</OutputType>
<RootNamespace>Gaming_Bot</RootNamespace>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AssemblyTitle>Gaming Bot</AssemblyTitle>
<Product>Gaming Bot</Product>
<Copyright>Copyright © 2024</Copyright>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ConcurrentHashSet" Version="1.3.0" />
<PackageReference Include="DSharpPlus" Version="4.5.0" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="4.5.0" />
<PackageReference Include="DSharpPlus.Interactivity" Version="4.5.0" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="4.5.0" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Collections.Immutable" Version="9.0.0" />
<PackageReference Include="System.ComponentModel.Composition" Version="9.0.0" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
<PackageReference Include="System.Threading.Channels" Version="9.0.0" />
</ItemGroup>
</Project>
looks fine so I guess u have a conflicting install of .net sdks
so what now?
also what is Gaming Bot? bot for some game
discord bot
goofy ahh name
:catderp:
i was thinking that i can make games in unity, i can also make a discord bot
names arent my strong suit
try changing it from .net9.0 to 8.0
in the csproj and see if it likes it
dont say it like that
sounds to sexual
:bigthonk:
it seemed to "like" it
no more errors
well now try building
and see if it likes it
thats fine
do u have that file in your project?
config.json?
i do
select it
and then on the properties
ohh
see if its set to copy if newer
do not copy
then change to what I said above
then try again
System.IO.FileNotFoundException: 'Could not find file 'C:\Users\celma\source\repos\Gaming Bot\Gaming Bot\bin\Debug\net8.0\config.json'.'
after changing it to copy it newer?
yes
well that doesnt sound right
oh no
but instead of running your app
just try to right click the project
and click build
we just want to ensure it builds right now
where are builds storeD?
if your in debug the same path as above
but build doesnt run the app
it just builds the executables and outputs etc
so we would know there are no errors within the code
runtime errors are something else
is it an exe file?
dont worry about what it is
just hit build
i did hit build
and look at the output window of visual studio
yes it said build
and see if it says build success X/1
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 18:44 and took 00.486 seconds ==========
ok
bueno?
so now u have to sort out why config.json is not being copied to the output folder
Could not find file 'C:\Users\celma\source\repos\Gaming Bot\Gaming Bot\bin\Debug\net8.0\config.json'.'
doesnt this mean that theres no file named config.json in net.8.0?
couldnt that be the issue?
maybe its looking in the wrong spot
try setting the build action to content
that is what it would mean yes
but if u have set it to copy if newer it should have copied it to that folder
maybe its looking in the wrong spot
unless your config.json
is inside a folder
or something
yeah
maybe its looking in the wrong spot
can u show me your solution explorer
with where the config.json is
yeah i found the issue
config.json is in a file named config
u mean it was named something else
the .json file?
yes because a file in a file sounds redundant
uhm btw im pretty sure its searching for the file in the wrong folder
because my config.json file isnt in the net8.0 folder
well u have no showed me the solution explorer of where the file is
so I cannot tell
it has its own folder called config
I mean i nvisual studio
but yes
if its inside a folder
u need to append the folder name to the path
i.e.:
"config/config.json"
why does this file always open? i close it everytime
well it says right there how to disable that
that happens in order for people to see their app output
otherwise the window just closes when the app terminates
making them having to add Console.ReadKey() or something to read the output before they exit it
:tired:
pretty sure u cant help here since this is a DSharpplus issue
yep 🙂 but im sure @Angius might be able to I never messed with discord bots
anyway glad u were able to upgrade it without much problems 😉 hf
theres 2 configs btw
thats interesting i think i found the issue
i had 2 config files one of them holding the token then the other one reading the token from that one then saving it in itself idk the tutorial said smth about more private token
It's not
It uses Mono but supports .NET Standard 2.1
The conventions they used it just horrible tbh
Can't wait until the switch to modern .NET hopefully soon