I have a Webform MVP project and have some extensions methods declared in a class at App_Code folder that are not resolved in my webform code behind. both Webform and Static Class are in same namespace but something seems to not be working...
I did a quick sample to show you the issue...
Class at App_Code:
namespace ecommerce.mvp
{
public static class Class1
{
public static void Test1()
{
}
}
}
Code Behind:
using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
namespace ecommerce.mvp
{
public partial class pdp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Class1.Test1(); // <--- This symbol can't be resolved
Notice that both are at same namespace...but for some reason Class1 is not resolved at code behind...
I really will appreciate any help on that one. Thanks.
Right click on your Class1.cs class in the App_Code folder and check its properties. Build Action must be set to Compile . (Sometimes it is set to Content )
Just because 2 classes share the same namespace does not mean they are automatically visible to each other if they are in different assemblies/projects .
The only way I can see you having this problem is if Class1
is in assembly/project "Foo" (a made up name), and class pdp
is in assembly/project "Bar" (another made up name).
To resolve this you'd need to add a reference to the assembly holding Class1
to the assembly holding pdp
.
I faced similar problem, however, it was a different 'Project' that was complaining. In my case, I found out that there were some .cs files which were included as 'link', and I did not include my new .cs file as 'link' in the project that was complaining. Hope this might help someone who stumbles upon this. So, a word of advice: When error is listed in 'Error list', also check the 'Project' column as well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.