473,398 Members | 2,368 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,398 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 1341
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.