✅ 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
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
do you have this reference added to your project?
Yes
Well I have it as a nuget package
is this a compiler error or runtime?
Compiler
did u set the -windows... in the csproj
It just shows in visual studio before doing anything
No I don’t think so
can you show your csproj
Ok I’ll send it in 5 minutes
you have to have something like this
net8.0-windows10.0.17763.0
as one example
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>
looks fine
this is a worker service template?
Yeah
It’s a worker service app
I get no complains about it
let me try running it
works as expected
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
no the image above is from a worker service
unless maybe you're using .net framework as opposed to .net
how would i check that
I mean u posted the csproj and it was not .net framework
i have greater version of the package and greater .net so idk
perhaps try creating a separated solution with the worker service just to try it out
because it definitively works
ok thanks for your help ill try that
or if u have a github with your solution and u can share it I can take a look
i still get it in a seperate solution
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
no i havent
building failed
i dont know how to use github really
does it provide u any extra information besides what u already posted?
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 ==========
good time to learn control versioning can save your ass
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
no your app is .net 8
to use the windows sdk all u need to do is specify the version
which is the
ok are there any other specfic things that need to be right
because it doesnt even work in a seperate solution
no, its literally that, the nuget and adding the using
you made this one?
i did dotnet new worker -n YourWorkerServiceProjectName
in cmd
are you not using visual studio?
yeah i am i just did it that way cuz quicker ig
:bigthonk:
is it because my visual studio out of date?
is
that is more prone to error imo since visual studio handles all your solution for you
doubt but you could try updating and see
ok
but I recommend u create the worker using visual studio instead
to make sure its the same thing
ok should i try that quick
sure
yeah making project in visual studio still doesnt work
did u update your visual studio?
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
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
i have 2 worker services folders inside a winforms app
but then it doesnt work in a separate solution
I mean
this is how it usually works
u create a solution
you can have many projects inside a solution
here is an example
ok i havent done that ive just moved the folders in
Joshman1412 is a worker service
oh dude don't use separate solutions...
and that is the problem
c# doesnt like moving things around like that
you make 1 solution
ok but it doenst work in a seperate project
u add your worker service project
you add your winforms project
they will be separated projects
add it as a reference to your project
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
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
ok but you can't have a worker service inside a winforms
they are 2 separate things
ok but even if i take it out and do it seperatly as in a seperate project i still get the error
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
ok ill try and work github out
ok whats your github name so i can let you view the project
this should get u going https://learn.microsoft.com/en-us/visualstudio/version-control/git-create-repository?view=vs-2022
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.
ive done it i think ive invited you to the github rep as a collaborater
the project is a zip file
nah follow the link above we dont download zip files
ok
there you go done
what is the link
does it need to be public i invited you as a collaborater
https://github.com/Joshman1412/PCMonitor/
ok got it moment
ok
ok this is a holy mess 😛
let me see
ok😂
ok so if u close everything
visual studio etc
ok
then go inside the folder
yeah
AlertReceiver and double click AlertReceiver.csproj
yeah
then right click the project and build
does it error?
no
ok
so the problem is when u build the winform app
correct?
yes
so here is what u will have to do
for a start move the folders AlertReceiver and RelayServer outside the PCMonitor
ok
done
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
yeah
theres no errors now
then what I am doing now is
I open the promp of command
go to the folder
ok
and do
then you do
what does that do
it will create a solution file
blank one
ok
then u open that file
it will look like this
u right click it and go to
ok
and then u add each project by selecting the
csproj file inside of each of those 3 folders
ok
after u do that it will now look like this
and now all the projects will properly work
ok thank you so much you have been so helpful I really really appreciate it
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
ok thank you so much
and add a class or whatever file u need to add
$close
If you have no further questions, please use /close to mark the forum thread as answered