C
C#2d ago
SergiuEs

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
SergiuEs
SergiuEsOP2d ago
public static async Task SaveXP()
{
string json = JsonConvert.SerializeObject(XP, Formatting.Indented);

await File.WriteAllTextAsync("Saved_XP.json", json);
}
public static async Task SaveXP()
{
string json = JsonConvert.SerializeObject(XP, Formatting.Indented);

await File.WriteAllTextAsync("Saved_XP.json", json);
}
this is the code itss pretty simple the issue lies in the File.WriteAllTextAsync apparently WriteAllTextAsync doesnt well exist
Angius
Angius2d ago
What's the exact error?
SergiuEs
SergiuEsOP2d ago
this is the error
No description
SergiuEs
SergiuEsOP2d ago
"File Does not contain a definition for "WriteAllTextAsync"
Angius
Angius2d ago
What's your .NET and C# version? It's in the .csproj file Or project properties
SergiuEs
SergiuEsOP2d ago
im using .Net Framework 4.7.2 i think
leowest
leowest2d ago
oof NSJ
SergiuEs
SergiuEsOP2d ago
No description
Angius
Angius2d ago
That's... old
SergiuEs
SergiuEsOP2d ago
oh
Angius
Angius2d ago
Any reason to use it in particular?
SergiuEs
SergiuEsOP2d ago
not one that i can think off
Angius
Angius2d ago
$newproject
MODiX
MODiX2d ago
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
SergiuEs
SergiuEsOP2d ago
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
Angius
Angius2d ago
"Not that bad" Man, C# is great lol Not "not that bad" :KEKW:
SergiuEs
SergiuEsOP2d ago
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"
Angius
Angius2d ago
You're in the wrong crowd lmao
SergiuEs
SergiuEsOP2d ago
so its good?
Angius
Angius2d ago
Yeah
SergiuEs
SergiuEsOP2d ago
well thats nice to know atleast im learning a language that is somewhat useful
Angius
Angius2d ago
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
SergiuEs
SergiuEsOP2d ago
i think those were java programmers
Angius
Angius2d ago
Maybe They have the Stockholm syndrome lol Regardless, the current version of .NET is 9.0 And current version of C# is 13.0
SergiuEs
SergiuEsOP2d ago
holy macaronie will i lose any progress?
Angius
Angius2d ago
Nah
SergiuEs
SergiuEsOP2d ago
neat, how do i update?
Angius
Angius2d ago
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 now
SergiuEs
SergiuEsOP2d ago
i have to copy paste it? :tear:
Angius
Angius2d ago
Well, you can try to upgrade the existing project Depending on what kind of .csproj file it is
MODiX
MODiX2d ago
leowest
Quoted by
<@85903769203642368> from #why am i missing Syntax? (click here)
React with ❌ to remove this embed.
Angius
Angius2d ago
Could try the upgrade assistant too
SergiuEs
SergiuEsOP2d ago
how do i check that 😭
Angius
Angius2d ago
Open the project dir in explorer, open the .csproj file with Notepad or whatever
SergiuEs
SergiuEsOP2d ago
where do i find the dir 😭:g_SadPepeClap:
Angius
Angius2d ago
Well, where you created the project
SergiuEs
SergiuEsOP2d ago
ive never programmed outside of unity so i suck directory?
Angius
Angius2d ago
ye Directory, folder, whatever
SergiuEs
SergiuEsOP2d ago
path i opened it and i see hella text
Angius
Angius2d ago
Paste the first few lines here
SergiuEs
SergiuEsOP2d ago
<?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
Angius
Angius2d ago
Yeah, that's the old-style .csproj
SergiuEs
SergiuEsOP2d ago
so that means i cant update the file directly?
Angius
Angius2d ago
Could still try ig
SergiuEs
SergiuEsOP2d ago
any chance of corruption?
Angius
Angius2d ago
Back it up somewhere, and replace the contents with
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>13</LangVersion>
</PropertyGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>13</LangVersion>
</PropertyGroup>

</Project>
Just in case something does break, keep a copy of the old one
SergiuEs
SergiuEsOP2d ago
what contents?
Angius
Angius2d ago
Of the file
SergiuEs
SergiuEsOP2d ago
from the .csproj?
Angius
Angius2d ago
ye
SergiuEs
SergiuEsOP2d ago
everything? do i delete everything from the file then paste that in?
Angius
Angius2d ago
Yes
SergiuEs
SergiuEsOP2d ago
well nothing seems to be broken
SergiuEs
SergiuEsOP2d ago
syntax seems to alos work now but now its saying this
No description
SergiuEs
SergiuEsOP2d ago
in the file thing it says that the bot is unloaded
Angius
Angius2d ago
Right... Let's see if you have the .NET SDK installed
SergiuEs
SergiuEsOP2d ago
that sounds bad
Angius
Angius2d ago
Should be, with VS, but let's double-check
SergiuEs
SergiuEsOP2d ago
i think i do
Angius
Angius2d ago
Open a terminal (Powershell, CMD, whatever) and type dotnet --list-sdks
SergiuEs
SergiuEsOP2d ago
8.0.204 [C:\Program Files\dotnet\sdk] thats all i got
Angius
Angius2d ago
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>12</LangVersion>
</PropertyGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>12</LangVersion>
</PropertyGroup>

</Project>
SergiuEs
SergiuEsOP2d ago
do i paste this in?
Angius
Angius2d ago
Or intall .NET 9 SDK
SergiuEs
SergiuEsOP2d ago
what do u recommend?
Angius
Angius2d ago
The latter
SergiuEs
SergiuEsOP2d ago
latter?
Angius
Angius2d ago
Yes
SergiuEs
SergiuEsOP2d ago
and that means?
Angius
Angius2d ago
No description
Angius
Angius2d ago
winget install Microsoft.DotNet.SDK.9
SergiuEs
SergiuEsOP2d ago
so update?
leowest
leowest2d ago
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
SergiuEs
SergiuEsOP2d ago
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
leowest
leowest2d ago
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
SergiuEs
SergiuEsOP2d ago
No description
SergiuEs
SergiuEsOP2d ago
No description
leowest
leowest2d ago
are u sure you are in extensions? and not nuget manager
SergiuEs
SergiuEsOP2d ago
i see the work NuGet alot so i think im in the nuget manager
leowest
leowest2d ago
yeah that is diferent place
leowest
leowest2d ago
No description
leowest
leowest2d ago
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
leowest
leowest2d ago
No description
SergiuEs
SergiuEsOP2d ago
smth like this?
No description
leowest
leowest2d ago
on that window bottom right u would see continue without code
SergiuEs
SergiuEsOP2d ago
yeah i clicked it
leowest
leowest2d ago
now just follow the rest of the guide
SergiuEs
SergiuEsOP2d ago
No description
leowest
leowest2d ago
is that from the 2nd page? or still on the first page
SergiuEs
SergiuEsOP2d ago
oh i updated it, i think i need to install smth else
leowest
leowest2d ago
well its saying you dont have .net 9
SergiuEs
SergiuEsOP2d ago
i do
leowest
leowest2d ago
but u could have upgrade it to ,net 8 instead if that is what u have
SergiuEs
SergiuEsOP2d ago
i have 8 and 9
leowest
leowest2d ago
are u sure because it says otherwise
SergiuEs
SergiuEsOP2d ago
8.0.204 [C:\Program Files\dotnet\sdk] 9.0.101 [C:\Program Files\dotnet\sdk]
leowest
leowest2d ago
:Hmm:
SergiuEs
SergiuEsOP2d ago
when i do dotnet --list-sdks it returns me this
Pobiega
Pobiega2d ago
Old VS?
SergiuEs
SergiuEsOP2d ago
what did i mess up 😭
leowest
leowest2d ago
can u post the content of the csproj it generated?
SergiuEs
SergiuEsOP2d ago
<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>
leowest
leowest2d ago
looks fine so I guess u have a conflicting install of .net sdks
SergiuEs
SergiuEsOP2d ago
No description
SergiuEs
SergiuEsOP2d ago
so what now?
leowest
leowest2d ago
also what is Gaming Bot? bot for some game
SergiuEs
SergiuEsOP2d ago
discord bot goofy ahh name
leowest
leowest2d ago
:catderp:
SergiuEs
SergiuEsOP2d ago
i was thinking that i can make games in unity, i can also make a discord bot names arent my strong suit
leowest
leowest2d ago
try changing it from .net9.0 to 8.0 in the csproj and see if it likes it
SergiuEs
SergiuEsOP2d ago
dont say it like that sounds to sexual
leowest
leowest2d ago
:bigthonk:
SergiuEs
SergiuEsOP2d ago
it seemed to "like" it no more errors
leowest
leowest2d ago
well now try building and see if it likes it
SergiuEs
SergiuEsOP2d ago
No description
SergiuEs
SergiuEsOP2d ago
No description
leowest
leowest2d ago
thats fine do u have that file in your project?
SergiuEs
SergiuEsOP2d ago
config.json? i do
leowest
leowest2d ago
select it and then on the properties
SergiuEs
SergiuEsOP2d ago
ohh
leowest
leowest2d ago
see if its set to copy if newer
SergiuEs
SergiuEsOP2d ago
No description
SergiuEs
SergiuEsOP2d ago
do not copy
leowest
leowest2d ago
then change to what I said above then try again
SergiuEs
SergiuEsOP2d ago
System.IO.FileNotFoundException: 'Could not find file 'C:\Users\celma\source\repos\Gaming Bot\Gaming Bot\bin\Debug\net8.0\config.json'.'
leowest
leowest2d ago
after changing it to copy it newer?
SergiuEs
SergiuEsOP2d ago
yes
leowest
leowest2d ago
well that doesnt sound right
SergiuEs
SergiuEsOP2d ago
oh no
leowest
leowest2d ago
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
SergiuEs
SergiuEsOP2d ago
where are builds storeD?
leowest
leowest2d ago
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
SergiuEs
SergiuEsOP2d ago
is it an exe file?
leowest
leowest2d ago
dont worry about what it is just hit build
SergiuEs
SergiuEsOP2d ago
i did hit build
leowest
leowest2d ago
and look at the output window of visual studio
SergiuEs
SergiuEsOP2d ago
yes it said build
leowest
leowest2d ago
and see if it says build success X/1
SergiuEs
SergiuEsOP2d ago
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ========== ========== Build completed at 18:44 and took 00.486 seconds ==========
leowest
leowest2d ago
ok
SergiuEs
SergiuEsOP2d ago
bueno?
leowest
leowest2d ago
so now u have to sort out why config.json is not being copied to the output folder
SergiuEs
SergiuEsOP2d ago
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
leowest
leowest2d ago
try setting the build action to content
leowest
leowest2d ago
No description
leowest
leowest2d ago
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
SergiuEs
SergiuEsOP2d ago
maybe its looking in the wrong spot
leowest
leowest2d ago
unless your config.json is inside a folder or something
SergiuEs
SergiuEsOP2d ago
yeah maybe its looking in the wrong spot
leowest
leowest2d ago
can u show me your solution explorer with where the config.json is
SergiuEs
SergiuEsOP2d ago
yeah i found the issue config.json is in a file named config
leowest
leowest2d ago
u mean it was named something else
SergiuEs
SergiuEsOP2d ago
the .json file?
leowest
leowest2d ago
yes because a file in a file sounds redundant
SergiuEs
SergiuEsOP2d ago
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
leowest
leowest2d ago
well u have no showed me the solution explorer of where the file is so I cannot tell
SergiuEs
SergiuEsOP2d ago
it has its own folder called config
SergiuEs
SergiuEsOP2d ago
No description
leowest
leowest2d ago
I mean i nvisual studio but yes if its inside a folder u need to append the folder name to the path
SergiuEs
SergiuEsOP2d ago
No description
leowest
leowest2d ago
i.e.: "config/config.json"
SergiuEs
SergiuEsOP2d ago
why does this file always open? i close it everytime
No description
leowest
leowest2d ago
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
SergiuEs
SergiuEsOP2d ago
:tired:
No description
SergiuEs
SergiuEsOP2d ago
pretty sure u cant help here since this is a DSharpplus issue
leowest
leowest2d ago
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
SergiuEs
SergiuEsOP2d ago
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
FusedQyou
FusedQyou23h ago
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

Did you find this page helpful?