I have a Windows console application in C# that acts as a phone book. I'm getting a Missing Directives error in the lines where the application is setting up the menu icons, such as this one:
cmsProgramMenu.Items.Add("&Settings", Properties.Resources.phone_receiver.ToBitmap(), OnSettings_Click);
'object' does not contain a definition for 'ToBitmap' and no extension method 'ToBitmap' accepting a first argument of type 'object' could be found (are you missing a using directive or assembly reference?)
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;
using System.Data;
using System.Windows.Media.Imaging;
The problem is that Properties.Resources.phone_receiver
is of type Object
and as the error message says Object
doesn't have a method called ToBitmap
. If you are sure that is is an Icon
(which your code suggests it is) then you can do the following:
((Icon)Properties.Resources.phone_receiver).ToBitmap()
This explicitly casts Properties.Resources.phone_receiver
to an Icon
and then the compiler knows that it can call the ToBitmap
method on it.