Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extension Method is not a member of Class

For some time now I have been using extension methods to expand the functionality of already existing classes. An example:

<System.Runtime.CompilerServices.Extension()> _
Public Sub DrawRoundedRectangle(graphics As Graphics, pen As Pen, x As Single, y As Single, width As Single, height As Single, radius As Single)
    graphics.DrawRoundedRectangle(pen, x, y, width, height, radius, RectangleEdgeFilter.All)
End Sub

This happily extends the graphics object so that I can call: e.graphics.DrawRoundedRectangle()

However every so often Visual Studio will report:

DrawRoundedRectangle is not a member of System.Drawing.Graphics

This means that I am unable to build due to the errors, and as of yet other than restarting Visual Studio (time consuming) I am yet to find a way to overcome these errors.

I have numerous extension methods (currently around 10) on various different classes, all of which fall over at the same time, this generates 66 errors.

My question is, Is there anything I am missing whilst creating these extension methods, or is there anything that can be done to stop these errors occuring?

like image 808
Matt Skeldon Avatar asked Jan 28 '13 14:01

Matt Skeldon


1 Answers

Do you define the extensions in a Public Module? Tried to 'rebuild solution', does it fix the issue?

like image 81
Amegon Avatar answered Oct 05 '22 20:10

Amegon