✅ Does anyone know how to fix the error below

Severity Code Description Project File Line Suppression State Error (active) CS1061 'ToastContentBuilder' does not contain a definition for 'Show' and no accessible extension method 'Show' accepting a first argument of type 'ToastContentBuilder' could be found (are you missing a using directive or an assembly reference?) PCMonitor F:\App Development\PCMonitor\AlertReceiver\Services\NotificationService.cs 13
114 Replies
Joshman1412
Joshman1412OP2d ago
using Microsoft.Toolkit.Uwp.Notifications; namespace AlertReceiver { public class NotificationService { public void ShowNotification(Alert alert) { // Construct and display the notification new ToastContentBuilder() .AddText($"Alert from {alert.Hostname}") .AddText(alert.Message) .Show(); // Displays the notification } } } it is a worker app
greyfox
greyfox2d ago
do you have this reference added to your project?
No description
Joshman1412
Joshman1412OP2d ago
Yes Well I have it as a nuget package
greyfox
greyfox2d ago
is this a compiler error or runtime?
Joshman1412
Joshman1412OP2d ago
Compiler
leowest
leowest2d ago
did u set the -windows... in the csproj
Joshman1412
Joshman1412OP2d ago
It just shows in visual studio before doing anything No I don’t think so
leowest
leowest2d ago
can you show your csproj
Joshman1412
Joshman1412OP2d ago
Ok I’ll send it in 5 minutes
leowest
leowest2d ago
you have to have something like this net8.0-windows10.0.17763.0 as one example
Joshman1412
Joshman1412OP2d ago
Ok <Project Sdk="Microsoft.NET.Sdk.Worker"> <PropertyGroup> <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> <OutputType>Exe</OutputType> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" /> <PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="9.0.0" /> <PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" /> </ItemGroup> </Project>
leowest
leowest2d ago
looks fine this is a worker service template?
Joshman1412
Joshman1412OP2d ago
Yeah It’s a worker service app
leowest
leowest2d ago
I get no complains about it
No description
leowest
leowest2d ago
let me try running it works as expected
Joshman1412
Joshman1412OP2d ago
My project is a winform app and then this worker folder inside of the winsform app folder and another worker service they will all work together but be separate apps The winsform app will run as like a system tray icon so just in the background @leowest Is it because my app is a worker service
leowest
leowest2d ago
no the image above is from a worker service unless maybe you're using .net framework as opposed to .net
Joshman1412
Joshman1412OP2d ago
how would i check that
leowest
leowest2d ago
I mean u posted the csproj and it was not .net framework
Joshman1412
Joshman1412OP2d ago
No description
Joshman1412
Joshman1412OP2d ago
i have greater version of the package and greater .net so idk
leowest
leowest2d ago
perhaps try creating a separated solution with the worker service just to try it out because it definitively works
Joshman1412
Joshman1412OP2d ago
ok thanks for your help ill try that
leowest
leowest2d ago
or if u have a github with your solution and u can share it I can take a look
Joshman1412
Joshman1412OP2d ago
i still get it in a seperate solution
leowest
leowest2d ago
if you have github can u make a repo for that solution so I can take a look also did u try building just to make sure its not vs being dumb
Joshman1412
Joshman1412OP2d ago
no i havent building failed i dont know how to use github really
leowest
leowest2d ago
does it provide u any extra information besides what u already posted?
Joshman1412
Joshman1412OP2d ago
1>------ Build started: Project: YourWorkerServiceProjectName, Configuration: Debug Any CPU ------ 1>F:\App Development\YourWorkerServiceProjectName\NotificationService.cs(13,18,13,22): error CS1061: 'ToastContentBuilder' does not contain a definition for 'Show' and no accessible extension method 'Show' accepting a first argument of type 'ToastContentBuilder' could be found (are you missing a using directive or an assembly reference?) 1>Done building project "YourWorkerServiceProjectName.csproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== ========== Build completed at 20:03 and took 06.484 seconds ==========
leowest
leowest2d ago
good time to learn control versioning can save your ass
Joshman1412
Joshman1412OP2d ago
could this mean something .NET Framework desktop apps that still use packages.config must migrate to PackageReference, otherwise the Windows SDKs won't be referenced correctly. In your project, right-click on "References", and click "Migrate packages.config to PackageReference". .NET Core 3.0 WPF apps must update to .NET Core 3.1, otherwise the APIs will be absent. .NET apps must use one of the Windows TFMs, otherwise the toast sending and management APIs like Show() will be missing. Set your TFM to net6.0-windows10.0.17763.0 or later. this is on microsoft website
leowest
leowest2d ago
no your app is .net 8 to use the windows sdk all u need to do is specify the version
leowest
leowest2d ago
which is the
No description
Joshman1412
Joshman1412OP2d ago
ok are there any other specfic things that need to be right because it doesnt even work in a seperate solution
leowest
leowest2d ago
no, its literally that, the nuget and adding the using
leowest
leowest2d ago
No description
leowest
leowest2d ago
you made this one?
Joshman1412
Joshman1412OP2d ago
i did dotnet new worker -n YourWorkerServiceProjectName in cmd
leowest
leowest2d ago
are you not using visual studio?
Joshman1412
Joshman1412OP2d ago
yeah i am i just did it that way cuz quicker ig
leowest
leowest2d ago
:bigthonk:
Joshman1412
Joshman1412OP2d ago
is it because my visual studio out of date? is
leowest
leowest2d ago
that is more prone to error imo since visual studio handles all your solution for you doubt but you could try updating and see
Joshman1412
Joshman1412OP2d ago
ok
leowest
leowest2d ago
but I recommend u create the worker using visual studio instead to make sure its the same thing
Joshman1412
Joshman1412OP2d ago
ok should i try that quick
leowest
leowest2d ago
sure
Joshman1412
Joshman1412OPthis hour
yeah making project in visual studio still doesnt work
leowest
leowestthis hour
did u update your visual studio?
Joshman1412
Joshman1412OPthis hour
yeah this includes messages and warnings 'ToastContentBuilder' does not contain a definition for 'Show' and no accessible extension method 'Show' accepting a first argument of type 'ToastContentBuilder' could be found (are you missing a using directive or an assembly reference?) Namespace "AlertReceiver" does not match folder structure, expected "PCMonitor.AlertReceiver.Services" Member 'ShowNotification' does not access instance data and can be marked as static A PackageReference to Microsoft.AspNetCore.App is not necessary when targeting .NET Core 3.0 or higher. If Microsoft.NET.Sdk.Web is used, the shared framework will be referenced automatically. Otherwise, the PackageReference should be replaced with a FrameworkReference. aswell as the error
leowest
leowestthis hour
would be easier to help if u could upload your code to github but given the error message now looks like you're copy pasting stuff in a way and using it in a different way causing it to not recognize things you're mix matching cli with solution explorer causing a mess of namespaces
Joshman1412
Joshman1412OPthis hour
i have 2 worker services folders inside a winforms app but then it doesnt work in a separate solution
leowest
leowestthis hour
I mean this is how it usually works u create a solution you can have many projects inside a solution
leowest
leowestthis hour
No description
leowest
leowestthis hour
here is an example
Joshman1412
Joshman1412OPthis hour
ok i havent done that ive just moved the folders in
leowest
leowestthis hour
Joshman1412 is a worker service
greyfox
greyfoxthis hour
oh dude don't use separate solutions...
leowest
leowestthis hour
and that is the problem c# doesnt like moving things around like that you make 1 solution
Joshman1412
Joshman1412OPthis hour
ok but it doenst work in a seperate project
leowest
leowestthis hour
u add your worker service project you add your winforms project they will be separated projects
greyfox
greyfoxthis hour
add it as a reference to your project
leowest
leowestthis hour
so enlighten me why do u u need the worker service? just for the toast messages? because u dont need it if that is all its being used for
Joshman1412
Joshman1412OPthis hour
like the .show doesnt work in an enteriley different project because it will be a different app that recevies alerts from remote computers to let me know when somethings wrong so i just want it to run as a service to give me notifcations of when something goes wrong
leowest
leowestthis hour
ok but you can't have a worker service inside a winforms they are 2 separate things
Joshman1412
Joshman1412OPthis hour
ok but even if i take it out and do it seperatly as in a seperate project i still get the error
leowest
leowestthis hour
which is why I asked u multiple times to upload it to github so I can work with u I can't do much more with no info or code
Joshman1412
Joshman1412OPthis hour
ok ill try and work github out ok whats your github name so i can let you view the project
leowest
leowestthis hour
Create a Git repo or work remotely with a provider - Visual Studio ...
Create a repo in Visual Studio by using Git, browse to an Azure DevOps repo, or work remotely with the Git provider of your choice.
Joshman1412
Joshman1412OPthis hour
ive done it i think ive invited you to the github rep as a collaborater the project is a zip file
leowest
leowestthis hour
nah follow the link above we dont download zip files
Joshman1412
Joshman1412OPthis hour
ok there you go done
leowest
leowestthis hour
what is the link
Joshman1412
Joshman1412OPthis hour
does it need to be public i invited you as a collaborater https://github.com/Joshman1412/PCMonitor/
leowest
leowestthis hour
ok got it moment
Joshman1412
Joshman1412OPthis hour
ok
leowest
leowestthis hour
ok this is a holy mess 😛 let me see
Joshman1412
Joshman1412OPthis hour
ok😂
leowest
leowestthis hour
ok so if u close everything visual studio etc
Joshman1412
Joshman1412OPthis hour
ok
leowest
leowestthis hour
then go inside the folder
Joshman1412
Joshman1412OPthis hour
yeah
leowest
leowestthis hour
AlertReceiver and double click AlertReceiver.csproj
Joshman1412
Joshman1412OPthis hour
yeah
leowest
leowestthis hour
then right click the project and build does it error?
Joshman1412
Joshman1412OPthis hour
no
leowest
leowestthis hour
ok so the problem is when u build the winform app correct?
Joshman1412
Joshman1412OPthis hour
yes
leowest
leowestthis hour
so here is what u will have to do for a start move the folders AlertReceiver and RelayServer outside the PCMonitor
Joshman1412
Joshman1412OPthis hour
ok done
leowest
leowestthis hour
by doing that u should now be able to build your winform without errors so what I did was I made a folder named PCMonitor Then I moved the folders there like this
leowest
leowestthis hour
No description
Joshman1412
Joshman1412OPthis hour
yeah theres no errors now
leowest
leowestthis hour
then what I am doing now is I open the promp of command go to the folder
Joshman1412
Joshman1412OPthis hour
ok
leowest
leowestthis hour
and do
dotnet new sln --name PCMonitor
dotnet new sln --name PCMonitor
then you do
Joshman1412
Joshman1412OPthis hour
what does that do
leowest
leowestthis hour
it will create a solution file blank one
Joshman1412
Joshman1412OPthis hour
ok
leowest
leowestthis hour
then u open that file
No description
leowest
leowestthis hour
it will look like this
No description
leowest
leowestthis hour
u right click it and go to
leowest
leowestthis hour
No description
Joshman1412
Joshman1412OPthis hour
ok
leowest
leowestthis hour
and then u add each project by selecting the csproj file inside of each of those 3 folders
leowest
leowestthis hour
No description
Joshman1412
Joshman1412OPthis hour
ok
leowest
leowestthis hour
after u do that it will now look like this
No description
leowest
leowestthis hour
and now all the projects will properly work
Joshman1412
Joshman1412OPthis hour
ok thank you so much you have been so helpful I really really appreciate it
leowest
leowestthis hour
in the future try to always use visual studio to add new projects dont try mix matching drag and dropping folders around if u need to add a file right click the project
Joshman1412
Joshman1412OPthis hour
ok thank you so much
leowest
leowestthis hour
and add a class or whatever file u need to add $close
MODiX
MODiXthis hour
If you have no further questions, please use /close to mark the forum thread as answered
Want results from more Discord servers?
Add your server