View Issue Details

IDProjectCategoryView StatusLast Update
0000883.NET APIIOP Problempublic2010-12-19 23:36
ReporterMariusz Postol Assigned ToRandy Armstrong  
PrioritynormalSeverityminorReproducibilityrandom
Status resolvedResolutionfixed 
Summary0000883: Problem with marshaling OPCITEMPROPERTY in the OpcRcw.Da.OPCITEMPROPERTY
Description

Exception thrown while marshaling breaks the browse. It should be handled, like that:
/// <summary>
/// Unmarshals and deallocates a OPCITEMPROPERTY structures.
/// </summary>
internal static ItemProperty GetItemProperty(IntPtr pInput, bool deallocate)
{
ItemProperty output = null;

  if (pInput != IntPtr.Zero)
  {

    output = new ItemProperty();
    try
    {
      OpcRcw.Da.OPCITEMPROPERTY property = (OpcRcw.Da.OPCITEMPROPERTY)Marshal.PtrToStructure(pInput, typeof(OpcRcw.Da.OPCITEMPROPERTY));

      output.ID = GetPropertyID(property.dwPropertyID);
      output.Description = property.szDescription;
      output.DataType = OpcCom.Interop.GetType((VarEnum)property.vtDataType);
      output.ItemPath = null;
      output.ItemName = property.szItemID;
      output.Value = UnmarshalPropertyValue(output.ID, property.vValue);
      output.ResultID = OpcCom.Interop.GetResultID(property.hrErrorID);

      // convert COM DA code to unified DA code.
      if (property.hrErrorID == ResultIDs.E_BADRIGHTS) output.ResultID = new ResultID(ResultID.Da.E_WRITEONLY, ResultIDs.E_BADRIGHTS);

    }
    catch (Exception ex)
    {
      output.ID = GetPropertyID(99999);
      output.Description = &quot;Illegal property&quot;;
      output.DataType = typeof(string);
      output.ItemPath = null;
      output.ItemName = &quot;Illegal Property&quot;;
      output.Value = &quot;Illegal property&quot;;
      output.ResultID = ResultID.Da.E_INVALID_PID;
      Tracer.MainTracer.TraceWarning(547, typeof(OpcCom.Interop).ToString(), ex.Message);
    }
    if (deallocate)
    {
      Marshal.DestroyStructure(pInput, typeof(OpcRcw.Da.OPCITEMPROPERTY));
    }
  }

  return output;
}
TagsNo tags attached.

Activities

Mariusz Postol

2009-09-30 15:31

reporter   ~0001443

the problrm is in the OpcCom.Da.Interop.GetItemProperty(System.IntPtr, bool)

Randy Armstrong

2010-12-19 23:36

administrator   ~0002198

Added try catch in GetItemProperties()

Issue History

Date Modified Username Field Change
2009-09-30 15:28 Mariusz Postol New Issue
2009-09-30 15:31 Mariusz Postol Note Added: 0001443
2010-12-19 23:36 Randy Armstrong Status new => resolved
2010-12-19 23:36 Randy Armstrong Resolution open => fixed
2010-12-19 23:36 Randy Armstrong Assigned To => Randy Armstrong
2010-12-19 23:36 Randy Armstrong Note Added: 0002198