2012-07-22 24 views
0

我已經查看了有關此問題的很多問題,並且通過將Net 4.0客戶端中的應用程序目標更改爲Net 4.0來解決這個問題,我已經像那,這不是問題。這種情況是我剛剛Json.Net,我創建了一個類,客戶,用它來使用,如下:嘗試使用類時出錯,表示找不到類型或名稱空間

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 

namespace CC 
{ 
    public class Customer 
    { 
     private string location; 

     public string Location 
     { 
      get { return location; } 
      set { location = value; } 
     } 

     private string name; 

     public string Name 
     { 
      get { return name; } 
      set { name = value; } 
     } 

     private int serviceTimeMin; 

     public int ServiceTimeMin 
     { 
      get { return serviceTimeMin; } 
      set { serviceTimeMin = value; } 
     } 

     public Customer() 
     { 
     } 
    } 
} 

,然後在我的網頁代碼隱藏我有以下代碼:

protected void Button_Click(object sender, EventArgs e) 
     { 
      Customer customer = new Customer(); 
      customer.Location = txtCustomerAddress + ", " + txtCustomerCity + ", " + txtCustomerState + " " + txtCustomerZipcode; 
      customer.Name = txtCustomerFirstName + " " + txtCustomerLastName; 
      customer.ServiceTimeMin = 3; 
      string json = JsonConvert.SerializeObject(customer); 
     } 

它是在同一個命名空間,所有,已確認的是,當我鍵入它已經沒有錯誤,只是當我建立調試,我得到如下:

CS0246: The type or namespace name 'Customer' could not be found (are you missing a using directive or an assembly reference?) 

和源點到線:

Line 290:   Customer customer = new Customer(); 

我錯過了什麼?

編輯:只是想澄清,這是所有在同一個命名空間和相同的項目(大會)。

回答

1

命名空間中的代碼隱藏也在CC?否則,您需要將using CC添加到文件的頂部。

我能想到的唯一的其他事情是,如果Customer沒有正確構建。是否還有其他錯誤或警告?這可能是一個副作用錯誤。

+0

它在同一個命名空間 – cb1295 2012-07-22 23:04:08

+0

它們在同一個項目中嗎? (Assembly) – 2012-07-22 23:04:42

+0

是的,他們在同一個項目中。 – cb1295 2012-07-22 23:05:03

0

您是否正在運行測試,並且您是否啓用了代碼覆蓋?有時候,這種情況下你的項目DLL不會被更新。

+0

我正在調試(在visual studio 2010中按下綠色的「播放」三角形)。我沒有更改任何默認值,因此除非默認情況下啓用了該功能,否則我沒有啓用它,哪裏可以找到Visual Studio?沒關係,我只是看着它,我沒有做這種測試,只是簡單的調試。 – cb1295 2012-07-22 23:59:40

相關問題