下面是 Vendor.cs文件的内容开始在开始处声明
private  AcmeReaderLayer reader1;
// AcmeReaderLayer 是一个类文件函数里的一段代码:byte[] aa = new byte[36];
                ApplyPropertyProfileCommand applyPropertyProfileCommand = (ApplyPropertyProfileCommand)command;
               if (null != applyPropertyProfileCommand.PropertyProfile)
                {
                foreach (KeyValuePair<PropertyKey, object> property in applyPropertyProfileCommand.PropertyProfile)
                {
                    bool error = false;                    
                    try
                    {
                       aa= setAppProperty((AcmeReaderLayer)reader1, (string)property.Key.PropertyName, (string)property.Value);
 在这错误:  “ Error 3 An object reference is required for the nonstatic field, method,orproperty Microsoft.Rfid.Reader.Driver.Acme.VendorHelper.setAppProperty(Microsoft.Rfid.Reader.Driver.Acme.Framework.AcmeReaderLayer, string, string)' “
                    }
                    catch (Exception e)
                    {
                        throw new ConnectionFailedException("SetProperty to reader failed", e, "", null);
                    }
                }setAppProperty函数声明如下:
internal  byte[] setAppProperty(AcmeReaderLayer reader1, string propertyName, string propertyValue)
        {
            this.reader1 = reader1;
            byte[] para = { 0x01, 0x02 };
           switch (propertyName)
            {
               case "ID":
               return para;
            break;
          case "NAME":
             reader.name = propertyValue; //TODO: Currently unsupported.
    return para;
            break;
      }
}

解决方案 »

  1.   

    是不是因为你的reader1没有初始化...
      

  2.   

    hi 
    您指的init 是什么意思?问题中的 代码都是 在一个 cs文件里, AcmeReaderLayer 是一个类文件名
    因此我在 这个vendor.cs文件里 
    首先声明 private  AcmeReaderLayer reader1;
    而在调用时aa= setAppProperty((AcmeReaderLayer)reader1, (string)property.Key.PropertyName, (string)property.Value);报的错误:“ Error 3 An object reference is required for the nonstatic field, method,orproperty Microsoft.Rfid.Reader.Driver.Acme.VendorHelper.setAppProperty(Microsoft.Rfid.Reader.Driver.Acme.Framework.AcmeReaderLayer, string, string)' “
    大家都帮想个法子,问过MS 那哥们了,目前还没答案,他说等他回复呢 正个项目快好了, 这个问题解决了,基本就ok了 等BizTalk 发布,就能用了
      

  3.   

    函数里的一段代码:aa= setAppProperty((AcmeReaderLayer)reader1, (string)property.Key.PropertyName, (string)property.Value);
     在这错误:  “ Error 3 An object reference is required for the nonstatic field, method,orproperty Microsoft.Rfid.Reader.Driver.Acme.VendorHelper.setAppProperty(Microsoft.Rfid.Reader.Driver.Acme.Framework.AcmeReaderLayer, string, string)' “
    =================
    这段函数代码在什么样的一个函数里
    An object reference is required for the nonstatic field
    你这段函数是static的???
      

  4.   

    TO:
    而在调用时aa= setAppProperty((AcmeReaderLayer)reader1, (string)property.Key.PropertyName, (string)property.Value);
    你的这段代码是不是static的??类似:
    pulbic static void test()
    {
        ...
        aa= setAppProperty((AcmeReaderLayer)reader1, (string)property.Key.PropertyName, (string)property.Value);
        ...
    }
      

  5.   

    try..Vendor vendor=new Vendor();
    aa=vendor.setAppProperty((AcmeReaderLayer)reader1, (string)property.Key.PropertyName, (string)property.Value);
      

  6.   

    //这段函数代码在什么样的一个函数里
    //An object reference is required for the nonstatic field
    //你这段函数是static的???
     
    internal static byte[] GetCommandBytes(Command command)
            {
              if (command is ApplyPropertyProfileCommand)
                {byte[] aa = new byte[36];
                    ApplyPropertyProfileCommand applyPropertyProfileCommand = (ApplyPropertyProfileCommand)command;
                   if (null != applyPropertyProfileCommand.PropertyProfile)
                    {
                    foreach (KeyValuePair<PropertyKey, object> property in applyPropertyProfileCommand.PropertyProfile)
                    {
                        bool error = false;
                        
                        try
                        {
                           aa= setAppProperty((AcmeReaderLayer)reader1, property.Key.PropertyName, (string)property.Value);
                        
                        }
                        catch (Exception e)
                        {
                            throw new ConnectionFailedException("SetProperty to reader failed", e, "", null);
                        }
                    }
                     return RfCmd.RfSetFactoryParameter(aa);
                    }                
          }
       return null;       
        }处理的函数是这样的
      

  7.   

    //Vendor vendor=new Vendor();
    //aa=vendor.setAppProperty((AcmeReaderLayer)reader1, (string)//property.Key.PropertyName, (string)property.Value);还是这个错误:
    Error 3 An object reference is required for the nonstatic field, method, or property 'Microsoft.Rfid.Reader.Driver.Acme.VendorHelper.reader1' C:\Documents and Settings\Administrator\Desktop\AcmeReaderProvider\VendorHelper.cs 106 62
      

  8.   

    Error 3 An object reference is required for the nonstatic field, method, or property 'Microsoft.Rfid.Reader.Driver.Acme.VendorHelper.reader1' C:\Documents and Settings\Administrator\Desktop\AcmeReaderProvider\VendorHelper.cs 106 62
    =======================
    reader1 也要有个实例,类似this.reader1
    or 
    yourclass yc = new yourclass
    yc.reader1
    因为静态方法没有this实例,无法确定reader1属于哪个具体对象
      

  9.   

    //reader1 也要有个实例,类似//this.reader1
    //or 
    //yourclass yc = new yourclass
    //yc.reader1
    //因为静态方法没有this实例,无法确定reader1属于哪个具体对象就是说开始在开始处声明
    private  AcmeReaderLayer reader1;  这个声明没有用?AcmeReaderLayer reader1 = new AcmeReaderLayer() ;
      

  10.   

    建议lz线看看c#基础的语法
      

  11.   

    C# 程序员参考   static请参见
    C# 关键字 | 修饰符
    使用 static 修饰符声明属于类型本身而不是属于特定对象的静态成员。static 修饰符可用于字段、方法、属性、运算符、事件和构造函数,但不能用于索引器、析构函数或类型。备注
    常数或者类型声明隐式地是静态成员。 
    不能通过实例引用静态成员。然而,可以通过类型名称引用它。例如,请考虑以下类: 
    public class MyBaseC 
    {
       public struct MyStruct {
          public static int x = 100;
       }
    }
    若要引用静态成员 x,请使用完全限定名(除非可从相同范围访问): MyBaseC.MyStruct.x
    尽管类的实例包含该类所有实例字段的单独副本,但每个静态字段只有一个副本。 
    不可以使用 this 引用静态方法或属性访问器。 
    注意   static 关键字在使用上比在 C++ 中有更多限制。若要与 C++ 关键字进行比较,请参见 C++ Language Reference 中的 static。
    为了说明实例成员,请看一个表示公司雇员的类。假设该类包含一种对雇员计数的方法和一个存储雇员数的字段。该方法和字段都不属于任何实例雇员,而是属于公司类。因此,应该将它们声明为此类的静态成员。有关构造函数的更多信息,请参见 10.10 实例构造函数。示例
    该示例读取新雇员的名称和 ID,逐个增加雇员计数器并显示新雇员的有关信息以及新的雇员数。为简单起见,该程序从键盘读取当前的雇员数。在实际的应用中,应从文件读取此信息。// cs_static_keyword.cs
    // Static members
    using System;
    public class Employee 
    {
       public string id;
       public string name;   public Employee () 
       {
       }   public Employee (string name, string id) 
       {
          this.name = name;
          this.id = id;
       }    public static int employeeCounter;   public static int AddEmployee() 
       {
          return ++employeeCounter;
       }
    }class MainClass: Employee 
    {
       public static void Main() 
       {
          Console.Write("Enter the employee's name: ");
          string name = Console.ReadLine();
          Console.Write("Enter the employee's ID: ");      
          string id = Console.ReadLine();
          // Create the employee object:
          Employee e = new Employee (name, id);
          Console.Write("Enter the current number of employees: ");
          string n = Console.ReadLine();
          Employee.employeeCounter = Int32.Parse(n);
          Employee.AddEmployee();
          // Display the new information:
          Console.WriteLine("Name: {0}", e.name);
          Console.WriteLine("ID:   {0}", e.id);
          Console.WriteLine("New Number of Employees: {0}",
                             Employee.employeeCounter);
       }
    }
    输入
    Tara Strahan
    AF643G
    15
    示例输出
    Enter the employee's name: Tara Strahan
    Enter the employee's ID: AF643G
    Enter the current number of employees: 15
    Name: Tara Strahan
    ID:   AF643G
    New Number of Employees: 16
    请参见
    C# 关键字 | 修饰符--------------------------------------------------------------------------------向 Microsoft 发送有关此主题的反馈&copy; Microsoft Corporation。保留所有权利。
      

  12.   

    给您说中了
    我也是临时做C#的,做MCU DSP 多是刚用C#就做 MS 的BizTalk 中间件,很多基本的东西是不怎么过关啊前面大家给了不少帮助,特别是liujia0421 兄弟现在基本完成了,如果这个问题解决了,再去MS 和他们联调,测试 就ok了望大家能指点一下,很诚恳的向大家学习 谢谢
      

  13.   

    你这里是必须用静态成员函数吗?internal static byte[] GetCommandBytes(Command command)改成internal byte[] GetCommandBytes(Command command)行不?
      

  14.   

    //改成//internal byte[] GetCommandBytes(Command command)行不?不行啊
    在AcmeReaderLayer.cs的文件里
     internal Response GetResponse(Command command)
            {
                lock (this)
                {
                    byte[] cmd = VendorHelper.GetCommandBytes(command);
    //这里有报错了 
    //An object reference is required for the nonstatic field, method, or property 
                    if (cmd == null)
                    {
                        return null;
                    }
                 }
       }
      

  15.   

    看来你真的有必要好好把静态成员与非静态成员间的关系搞清楚了...等项目做完好好看看吧...TO:
    byte[] cmd = VendorHelper.GetCommandBytes(command);
    //这里有报错了 
    //An object reference is required for the nonstatic field, method, or property 你这里的VendorHelper是类的名称吧,由于你前面将GetCommandBytes(command)改成成员函数了..所以这里就不能直接"类名.方法名"..try..
    VendorHelper vendor=new VendorHelper();
    vendor.GetCommandBytes(command);
      

  16.   

    TKS liujia 兄弟昨天那个问题没了但新问题又来了 呵呵internal static byte[] GetCommandBytes(Command command)
            {
              if (command is ApplyPropertyProfileCommand)
                {byte[] aa = new byte[36];
                    ApplyPropertyProfileCommand applyPropertyProfileCommand = (ApplyPropertyProfileCommand)command;
                   if (null != applyPropertyProfileCommand.PropertyProfile)
                    {
                    foreach (KeyValuePair<PropertyKey, object> property in applyPropertyProfileCommand.PropertyProfile)
                    {
                        bool error = false;
                        
                        try
                        {
                           aa= setAppProperty((AcmeReaderLayer)reader1, property.Key.PropertyName, (string)property.Value);
                        //走不到这里,目前还不知道原因
                        }
                        catch (Exception e)
                        {
                            throw new ConnectionFailedException("SetProperty to reader failed", e, "", null);
                        }
                    }
                     return RfCmd.RfSetFactoryParameter(aa);
                    }                
          }
       return null;       
        }
    谢谢两位的关注
      

  17.   

    那是不是因为你这里
    if (null != applyPropertyProfileCommand.PropertyProfile)
    判断时,applyPropertyProfileCommand.PropertyProfile为空造成的...
      

  18.   

    ApplyPropertyProfileCommand applyPropertyProfileCommand = (ApplyPropertyProfileCommand)command;
                   if (null != applyPropertyProfileCommand.PropertyProfile)
                    {
                    foreach (KeyValuePair<PropertyKey, object> property in applyPropertyProfileCommand.PropertyProfile)//走到这里也
                    {
                        bool error = false;
                        
                        try
                        {这里就进不来
                           aa= setAppProperty((AcmeReaderLayer)reader1, property.Key.PropertyName, (string)property.Value);
                        
    说白了,对他们的框架也不熟悉
      

  19.   

    foreach (KeyValuePair<PropertyKey, object> property in applyPropertyProfileCommand.PropertyProfile)//走到这里也
    就应该说明 这里不为空啊
      

  20.   

    恕我直言,你这个项目做完了后,对.net依然是知之甚少
      看看基础的东西把
      

  21.   

    谢谢你 呵呵 从这个项目做到现在来看,MS 的架构师 对G2 或其他卡的协议 应该不是很熟悉,
    当然了,不是说MS 的人不够聪明
    总之,有很多方面,是我们不能理解的。
      

  22.   

    //有可能输出路径不对
    不明白您的 这个说的是什么意思????能具体解析下么? 谢谢你说的对,做完后,也不会搞.net的,不过我还是会再看看的,如果有时间的话
    只是因为临时安排的,若招人的话,熟悉我们的产品也不是很容易的事
    起码时间上来不及。
      

  23.   

    //有可能输出路径不对补充下, 怎么和输出有关系呢?我这段代码是要 从BizTalk 的界面上,把各项属性里的值给取来,处理成合适的格式
    送给我们的设备的望能解释下 谢谢