471,330 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 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 1300
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Fisch von Gestern | last post: by
5 posts views Thread by Jeffry van de Vuurst | last post: by
1 post views Thread by David C. allen | last post: by
1 post views Thread by Andy G | last post: by
4 posts views Thread by pepcag | last post: by
4 posts views Thread by Steffen Bobek | last post: by
1 post views Thread by Mike Hofer | last post: by
reply views Thread by John Vines (CISD/HPCD) | last post: by

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.