More in this section

Forums / Developing with Sitefinity / Error when using code inside APP_CODE folder

Error when using code inside APP_CODE folder

3 posts, 0 answered
  1. xman
    xman avatar
    4 posts
    Registered:
    07 Mar 2016
    03 Oct 2016
    Link to this post

    Hi,

    I have problem when using code from app_code folder.

    So when i set built action=compile to file SBC.cs then i will get Error    CS0433    The type 'Supplier' exists in both 'SBCNEW, Version=9.1.6110.0, Culture=neutral, PublicKeyToken=null' and '1_App_Code, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'    SBCNEW    D:\Program Files (x86)\Telerik\Sitefinity\Projects\SBCNEW\Module\Product\Admin\Product_Admin.ascx.cs    24

    But when i set built action=content to file SBC.cs then i will get "The name 'SBC' does not exist in the current context"

     

    I checked, there are two "SBCNEW" projects within the object browser.

    I've struggling to discover whats the problem for last few days,

    please any suggestions could be usefull for me


    These are steps to do my project:
    1. I created SF project named "SBCNEW" (with property assemby name="SBCNEW" , Default namespace="SBCNEW")
    2. I create Dinamic Module using module Builder for type Supplier
    3. I Put some code Class named SBC.cs inside the APP_CODE folder
            -----------
               SBC.cs at glance:

                using System;
                using System.Collections.Generic;
                using System.Linq;
                using System.Web;
                using Telerik.Sitefinity;
                using Telerik.Sitefinity.Model;
                using Telerik.Sitefinity.DynamicModules;
                using Telerik.Sitefinity.Data.Linq.Dynamic;
                using Telerik.Sitefinity.DynamicModules.Model;
                using Telerik.Sitefinity.GenericContent.Model;
                using Telerik.Sitefinity.Utilities.TypeConverters;
                using Telerik.Sitefinity.Security;
                using Telerik.Sitefinity.Lifecycle;
                using System.Web.UI.WebControls;
                using System.Text.RegularExpressions;
                using Telerik.Sitefinity.Modules.Libraries;
                using System.IO;
                using Telerik.Sitefinity.Taxonomies;
                using Telerik.Sitefinity.Taxonomies.Model;
                
                namespace SBC
                {
                   public class Supplier
                   {
                        public static IQueryable<DynamicContent> RetrieveCollectionOfSuppliers()
                        {
                            ...
                            return myCollection;
                        }
                ...
            ------------
        
    4. I create user control named "Product_Admin.ascx.cs" inside Module/Product/Admin

            -----------
               Product_Admin.ascx.cs at glance:

                using System;
                using System.Linq;
                using System.Web.UI.WebControls;
                using System.Collections.Generic;
                using System.Data;
                using Telerik.Web.UI;
                using Telerik.Sitefinity.Model;
                using Telerik.Sitefinity.Modules.Libraries;
                using Telerik.Sitefinity.DynamicModules;
                using Telerik.Sitefinity.DynamicModules.Model;
                using Telerik.Sitefinity.Taxonomies;
                using Telerik.Sitefinity.Taxonomies.Model;
                using Telerik.OpenAccess;

                public partial class Module_Product_Admin_Product_Admin : System.Web.UI.UserControl
                {
                    protected void Page_Load(object sender, EventArgs e)
                    {
                        ...
                        var supplierList = SBC.Supplier.RetrieveCollectionOfSuppliers();//here is the error occure
                    }
                ...
            ------------

  2. Suhasini
    Suhasini avatar
    0 posts
    Registered:
    10 Oct 2016
    23 Oct in reply to xman
    Link to this post
    I am also getting the same error. Could you suggest the resolution!
  3. Nidhi
    Nidhi avatar
    40 posts
    Registered:
    20 Jul 2010
    24 Oct
    Link to this post
    Can you try moving your class file to another folder and rename it like ~/SBC/Supplier.cs and then try to compile it - that should work.
3 posts, 0 answered