I'm using ASP.NET with VB, and .NET version 3.5. In the project, I've got some utility functions that I call from expressions in the aspx pages and also in code behind. This all works fine on my local machine, but when I deploy to the production server, I get this compilation error on each of those utility methods:
BC30456: 'XXX' is not a member of 'String'.
where XXX is an extension method defined on System.String. I'm baffled about this for a number of reasons:
- Why is ASP.NET compiling anything at all, since I've precompiled the application and put everything in the bin directory.
- ASP.NET knows the functions are there because they work in code behind. It's only when used in the aspx page that I have this problem. (e.g. if I do something like this: <%= "A string to XXX-ify".XXX())%>)
- This method is public, which I verified with Reflector.
- I imported the relevant namespaces in the web.config file, and I can see that these namespaces are being imported in the call th开发者_JAVA技巧at ASP.NET makes to the compiler.
What on earth is going on here? I really need access to these utility functions because, well, they're really useful.
Check the .Net version of the site in IIS.
This may be set to a version that does not support extension methods.
When I looked more closely at one example, the function in question was a Friend (internal in c#), and the page can't see them. So maybe I was hallucinating about the method being public. Still, it's something to look out for.
I guess I don't fully understand the compilation system in ASP.NET, but maybe the page is compiled into a separate assembly from the code modules, and so such functions must be public if you want it to work.
精彩评论