0

I have a project written in MVC2 and VB.NET. I use a lot of htmlhelper extension methods, and I have them all in a public module. They work just fine, and I can compile and run my project. I reference the namespace they are in with this:

<%@ Import Namespace="MyProject.WebUI.Extensions" %>

So, again, they work great, my project runs and compiles without a hitch.

The problem is that each one of these extension methods is shown as an error:

Error 33 'TabbedMenu' is not a member of 'System.Web.Mvc.HtmlHelper(Of Object)'. C:\Projects\MyProject\MyProject.WebUI\Views\Shared\Site.Master 23 21 MyProject.WebUI

This doesn't prevent the project from compiling and running, it just creates an error, which is annoying. I've tried looking for solutions, but all of the solutions I've found were for projects that don't compile, all with simple solutions like referencing the right namespace or making sure your module is declared public. Any thoughts?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
user961794
  • 111
  • 11

2 Answers2

0

Have you included an import statement in your site.Master to include the extensions class where your extensions are defined. Also I assume your extension class is a public static class with public static methods defined?

Also check this out if you haven't already, it may be related to what you are after.

How do I use an extension method in an ASP.NET MVC View?

Community
  • 1
  • 1
dreza
  • 3,605
  • 7
  • 44
  • 55
  • First of all, if I didn't import the namespace, the project wouldn't run as I said it does (see above comment). Second, this is in VB.NET. Extension methods have to be in modules which automatically have shared methods defined. Again, the website works perfectly, as do the extension methods. They just throw errors before compile time.... though they do end up compiling. – user961794 Nov 22 '11 at 23:26
  • Perhaps if you posted an example of the Extensions class and a method that is not working to give more insight into what the potential problem might be? From what you have said, it seems like it should be working. – dreza Nov 23 '11 at 03:25
  • It is working, perfectly, that's what I'm trying to tell you. It just flags an error before compiling. That error obviously doesn't exist after compiling because the extension method compiles and runs just fine. The issue is that I want to clean up the errors listed, not that I need my project to work. – user961794 Nov 23 '11 at 18:06
  • Are they in the same project? Do you perhaps have to set the build order of your solution to ensure the appropriate projects are built first. This is just a suggestion, just trying to offer some help. – dreza Nov 23 '11 at 21:36
0

You need to import the namespace where you have placed your extension. And since it is a bit annoying that this problem shows up no sooner than in runtime, you can enable view compilation to have the compiler detect the problem. I should warn you that compiling the views is a time consuming operation though.

Community
  • 1
  • 1
Kristoffer
  • 834
  • 6
  • 22
  • If you read my question, I say that I do in fact import the namespace in which I place my extension. In fact, I even show the code in which I do that. If I did not import the namespace in which I placed my extension, the project would not run, as I said it does. But the project does run. It works perfectly. The only problem is the annoying errors that get flagged before compile. – user961794 Nov 22 '11 at 23:23