locked
ERROR AT PROGRAM RRS feed

  • Question

  • User1013200534 posted

    Error    1    'Models.StateInfo' does not contain a definition for 'StateCode' and no extension method 'StateCode' accepting a first argument of type 'Models.StateInfo' could be found (are you missing a using directive or an assembly reference?)    

    C:\Users\Station\Desktop\Test\Test\BusinessLayer\StateOperation.cs    17    58    BusinessLayer

    I do have included definition for 'StateCode' in 'Models.StateInfo' but still why i am getting this error? Just for this error my project is not running. Just a single error. Hope sumone will have a solution for me. Thanks.

    Wednesday, August 14, 2013 7:16 AM

Answers

  • User1109032460 posted

    Are both pieces of code in the same assembly, or are they in different assemblies?

    It might just be a problem with Visual Studio, especially if you only recently added the StateCode property. So clean the solution thoroughly, if necessary restart VS, and then try again.

    Oh, and try one other trick.

    Comment out the faulty line of code.

    Rebuild.

    And then uncomment the line of code.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 14, 2013 12:22 PM
  • User1109032460 posted

    It's almost certainly just a VS issue, with it holding some reference to a defunct version of the Models assembly.

    Clean everything.

    If you're feeling paranoid, delete the BIN folders containing all the assemblies.

    Shut down and restart VS.

    Build Models.

    Build the BusinessLayer.

    From your code, there's no reason why it shouldn't work.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 14, 2013 12:38 PM

All replies

  • User1109032460 posted

    Please post your code.

    Wednesday, August 14, 2013 7:54 AM
  • User1013200534 posted

    public int ACSaveStateInfo(StateInfo paramStateInfo)
           {
               DBAccess oDBAccess = new DBAccess();
               SqlDataReader rdrStateInfo = (SqlDataReader)oDBAccess.ExecuteSP(Constants.SP_ACSaveState, paramStateInfo.StateId,
                   paramStateInfo.StateName, paramStateInfo.StateSName, paramStateInfo.StateCode, paramStateInfo.IsActive);
               oDBAccess.CloseConnection();
               return 0;
           }

    Wednesday, August 14, 2013 8:40 AM
  • User1109032460 posted

    We need to see the code for the Models.StateInfo class

    Wednesday, August 14, 2013 9:29 AM
  • User1013200534 posted

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace Models
    {
     public class StateInfo
        {
         public Guid StateId
            {
                get;
                set;
            }

         public string StateName
            {
                get;
                set;
            }

         public string StateSName
            {
                get;
                set;
            }

            public bool IsActive
            {
                get;
                set;
            }

            public string StateCode
            {
                get;
                set;
            }
        }
    }

    Wednesday, August 14, 2013 12:13 PM
  • User1109032460 posted

    Are both pieces of code in the same assembly, or are they in different assemblies?

    It might just be a problem with Visual Studio, especially if you only recently added the StateCode property. So clean the solution thoroughly, if necessary restart VS, and then try again.

    Oh, and try one other trick.

    Comment out the faulty line of code.

    Rebuild.

    And then uncomment the line of code.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 14, 2013 12:22 PM
  • User1013200534 posted

    StateOperation.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Models;
    using DBAccessLayer;
    using System.Data.SqlClient;

    namespace BusinessLayer
    {
       public class StateOperation
        {
           public int ACSaveStateInfo(StateInfo paramStateInfo)
           {
               DBAccess oDBAccess = new DBAccess();
               SqlDataReader rdrStateInfo = (SqlDataReader)oDBAccess.ExecuteSP(Constants.SP_ACSaveState, paramStateInfo.StateId, paramStateInfo.StateName,
                   paramStateInfo.StateSName, paramStateInfo.StateCode, paramStateInfo.IsActive);
               oDBAccess.CloseConnection();
               return 0;
           }
        }
    }

    ---------------------------------------------------------

    The above StateOperation.cs is under BusinessLayer and the last one that is StateInfo.cs is under Models .

    Wednesday, August 14, 2013 12:32 PM
  • User1109032460 posted

    It's almost certainly just a VS issue, with it holding some reference to a defunct version of the Models assembly.

    Clean everything.

    If you're feeling paranoid, delete the BIN folders containing all the assemblies.

    Shut down and restart VS.

    Build Models.

    Build the BusinessLayer.

    From your code, there's no reason why it shouldn't work.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 14, 2013 12:38 PM
  • User1013200534 posted

    Yes.. I just recently added the StateCode property. Now trying to solve the probs. Hope my previous post helped u to understood the probs properly. N thanx for your help. trying to solve it and also waiting for your rply on the basis of my last post. thanks.

    Wednesday, August 14, 2013 12:38 PM
  • User1013200534 posted

    Thanx for guiding. Let me try. Will post you if i can solve my probs. Thanx. Got your rply.

    Wednesday, August 14, 2013 12:39 PM
  • User1013200534 posted

    Nope :( Now its showing many errors like The type or namspace name Models could not be found, country info could not be found etc.. Will give you the feedback when i will do this on my office PC.. thanks.

    Wednesday, August 14, 2013 2:10 PM
  • User-1426144113 posted

    Hi Saakey7,

    May be you can remove the Model reference from BusinessLayer, then rebulid the Model class library and add it to the BusinessLayer. Check the result. If you still have the issue, I suggest that you can create new Model class Library and copy your code to it.

    Thanks

    Best Regards

    Thursday, August 15, 2013 9:14 AM
  • User1013200534 posted

    Remove the Model reference from BusinessLayer, then rebulid the Model class library and add it to the BusinessLayer - Means ?? Models are different class and BusinessLayer is also a different class.

    Now i am getting 2 error:

    Error    1    The type or namespace name 'EmpInfo' could not be found (are you missing a using directive or an assembly reference?)    C:\Users\Station\Desktop\Test\Test\BusinessLayer\EmpOperation.cs    13    33    BusinessLayer
    Error    2    The type or namespace name 'EmpOperation' could not be found (are you missing a using directive or an assembly reference?)    C:\Users\Station\Desktop\Test\Test\Test\EmpEntry.aspx.cs    15    8    Test

    But both the 'EmpInfo' and 'EmpOperation' class are there... Then why still its showing this type of error???

    Also.

    EmpOperation.cs contains -

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Models;
    using DBAccessLayer;
    using System.Data.SqlClient;

    namespace BusinessLayer
    {
       public class EmpOperation
        {
           public int ACSaveEmpInfo(EmpInfo paramEmpInfo)
           {
               DBAccess oDBAccess = new DBAccess();
               SqlDataReader rdrEmpInfo = (SqlDataReader)oDBAccess.ExecuteSP(Constants.SP_ACSaveEmp, paramEmpInfo.EmpId, paramEmpInfo.EmpName,
                   paramEmpInfo.EmpTitle, paramEmpInfo.IsActive);
               oDBAccess.CloseConnection();
               return 0;

           }
        }
    }

    --------------------------------------------------

      public int ACSaveEmpInfo(EmpInfo paramEmpInfo)

    on the above line when im clicking on EmpInfo and clicking on Go To Defination then its showing "Cannot Navigate To EmpInfo".

    Do Help Me Plz... Thanks...




    Monday, August 19, 2013 2:24 AM
  • User1013200534 posted

    Thanx.... It worked On Yesterday Last hour in Office... Same project i wrote once again and it ran.. ia m surprised that why it didnot run on previous time... anywaz thanx for guiding..

    Tuesday, August 20, 2013 1:16 AM
  • User1013200534 posted

    Thanx everypne for your help.

    Thursday, August 22, 2013 5:27 AM