473,231 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

extension method error

Hi everyone. Something weird is happening when I use the extension
methods feature (of C# 3.0) on VS2008 for a web application project.

I've wrote this extesion for String class:

(MyExtension.cs):

namespace MyNamespace
{
public static class MyExtension
{
public static string SubstringEx(this string str, int startIndex,
int length)
{
return str.Substring(startIndex, (length str.Length) ?
str.Length : length);
}
}
}

Then in another file I've written this:

desc.SubstringEx(0, 256);

When I compile the solution everything goes well. No errors at all.
Intellisense works just fine. No problems. But, then, when I open the
browser and I try to access the url for the webpage I get a compiler
error saying:
"CS0117: 'string' does not contain a definition for 'SubstringEx'"

Any idea? Is there something I could be doing wrong?

Thanks in advance.

Best regards.
Daniel.
Aug 20 '08 #1
4 1335
On Aug 20, 5:19*pm, daniel <daniel...@gmail.comwrote:
I meant in a .cs file and the namespace was imported. Everything goes
well
till I try to access the webpage.
Is the web server on the same machine as your development environment?
You'll need .NET 3.5 installed on the web server. I'd be surprised if
this were failing on your dev box though. Are you running with IIS or
the built-in web server in Visual Studio?

Jon
Aug 20 '08 #2
Yes, this is happening on my development environment.
Things like Linq and lambda expressions work just fine
in the same project but in other webpages. I'm running
the webapp on IIS.

Daniel.

On Aug 20, 1:38*pm, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Aug 20, 5:19*pm, daniel <daniel...@gmail.comwrote:
I meant in a .cs file and the namespace was imported. Everything goes
well
till I try to access the webpage.

Is the web server on the same machine as your development environment?
You'll need .NET 3.5 installed on the web server. I'd be surprised if
this were failing on your dev box though. Are you running with IIS or
the built-in web server in Visual Studio?

Jon
Aug 20 '08 #3
On Aug 20, 5:45 pm, daniel <daniel...@gmail.comwrote:
Yes, this is happening on my development environment.
Things like Linq and lambda expressions work just fine
in the same project but in other webpages. I'm running
the webapp on IIS.
If you put a syntax error in the MyExtensions class, does that show
up? I wonder whether it's not compiling that file at all.

What about if you put the MyExtensions class in the same file as the
class which uses it? I'm not suggesting that as a long-term fix, of
course, but it would be interesting to try to diagnose the problem.

Jon
Aug 20 '08 #4
Hi Jon. Putting the class on the same file cause the same error.
I can't figure out what can be happening. I've solved my problem
doing things in a different way.

However I appreciate your help. As soon as I have a little of free
time I'll continue working around this and I if figure out what is
causing this error I'll let you know.

Thanks again.

Best regards.
Daniel.

On Aug 20, 1:55*pm, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Aug 20, 5:45 pm, daniel <daniel...@gmail.comwrote:
Yes, this is happening on my development environment.
Things like Linq and lambda expressions work just fine
in the same project but in other webpages. I'm running
the webapp on IIS.

If you put a syntax error in the MyExtensions class, does that show
up? I wonder whether it's not compiling that file at all.

What about if you put the MyExtensions class in the same file as the
class which uses it? I'm not suggesting that as a long-term fix, of
course, but it would be interesting to try to diagnose the problem.

Jon
Aug 21 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Fisch von Gestern | last post by:
I have tried to run the extension function/element examples provided with the Xalan-J download. I believe that my classpath is correct, and that my versions are up-to-date. However, I can't get...
5
by: Jeffry van de Vuurst | last post by:
Hi, I'm working on an xml schema and I'm running into some problems relating substitutionGroups and extensions. This xsd validates fine: There are three elements and three complex types and...
1
by: David C. allen | last post by:
I have created a simple Client-side SOAP Extension for a webclass that I have. When I apply the extension attribute to the the calling function in the proxy class I get an error 'Value cannot be...
1
by: Andy G | last post by:
I hate to post just a general error like this but one of my clients that coded this system is getting an error when loading a page. I know that you can't point out the specific problem so forget...
4
by: pepcag | last post by:
I used http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconalteringsoapmessageusingsoapextensions.asp as a template to create a very simple web method with soap...
3
by: Phoe6 | last post by:
Hi all, I had a filesystem crash and when I retrieved the data back the files had random names without extension. I decided to write a script to determine the file extension and create a newfile...
4
by: Steffen Bobek | last post by:
Extension methods are made for use with instances. I'd like to "misuse" them as static methods, too. Let me tell you my ambition: I use an extension method to serialize objects somehow like this:...
1
by: Mike Hofer | last post by:
We have an extension method defined that is causing all sorts of compiler grumpiness in one of our projects, and we don't know why. The method in question isn't rocket science, so here it is, in...
3
by: raylopez99 | last post by:
The headline says it all. Great minds think alike: read the blog below from three years ago, as endorsed by Ritchie, who coinvented C. BTW the below lambda expression code will not work (.Where...
0
by: John Vines (CISD/HPCD) | last post by:
All, I am trying to create an extension module and keep getting an error, "/usr/local/lib/python2.5/site-packages/mytest.so: undefined symbol: PyInitModule" thanks in advance, *Here is my...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.