从JScript使用自己的类时,“类不支持自动化”错误

时间:2009-10-30 11:34:25

标签: .net javascript com scripting automation

我有一个项目,它公开了不同类型客户端使用的对象模型。用.Net 3.5编写,它将类暴露给COM。问题是虽然所有这些似乎都来自测试VB6客户端,但在尝试使用JScript和Windows脚本宿主进行自动化时遇到了奇怪的错误。

这是代码段:

var scComponent = new ActiveXObject("Mine.SCComponent");
var Prescription = new ActiveXObject ("Mine.CardHolderNewServedPrescriptionData");

Prescription.DiagnosisId = "Test Diagnosis";
Prescription.Date = "2009-01-01";

Prescription.DrugId = 1121;
Prescription.LpuId = 19;
Prescription.Number = 1024;
Prescription.OperatorId = 0;
Prescription.PhysicianId = 13;
Prescription.Quantity = 800;
Prescription.Series = 144;
//Prescription.ServedDate = "2009-01-01";
//Prescription.ServedDrugId = 1123;
//Prescription.ServedQuantity = 600;
//Prescription.Status = 0;
//Prescription.RecourseDate = "2009-01-01";

var addResult = scComponent.AddCardHolderServedPrescription(Prescription);

运行时遇到以下问题:

  • 注释行失败并显示错误“对象不支持此类属性或方法”
  • Prescription.Date被定义为System.DateTime,但是JScript Date的赋值在这里不起作用 - 但它似乎接受(或以某种方式转换)字符串日期。
  • 使用AddCardHolderServedPrescription调用的最后一行失败,并且“类不支持自动化”错误。

调用正确传递的其他scComponent方法,因此我认为CardHolderNewServedPrescriptionData类型存在一些问题。现在我需要一些线索来解决它 - 脚本错误消息不太有用。 Google搜索没有返回有关诊断方法的有用信息。

同样,它既适用于我的C#测试,也适用于VB6客户端,但不适用于JScript。谢谢你的任何想法。

类型定义和接口片段如下所示。

[Guid("08D183AF-BE28-4638-BAC0-C568C0FEAD45")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ICardHolderNewServedPrescriptionData
{
    int Series { get; set; }
    int Number { get; set; }
    DateTime Date { get; set; }
    string DiagnosisId { get; set; }
    int DrugId { get; set; }
    int Quantity { get; set; }
    int LpuId { get; set; }
    int PhysicianId { get; set; }
    int OperatorId { get; set; }
    int CategoryId { get; set; }
    int Status { get; set; }
    DateTime RecourseDate { get; set; }
    DateTime ServedDate { get; set; }
    int ServedDrugId { get; set; }
    int ServedQuantity { get; set; }
}

[Guid("E0842E24-163E-4580-9AD6-1593F781D314")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("Mine.CardHolderNewServedPrescriptionData")]
public class CardHolderNewServedPrescriptionData : ICardHolderNewServedPrescriptionData
{
    public int Series { get; set; }
    public int Number { get; set; }
    public DateTime Date { get; set; }
    public string DiagnosisId { get; set; }
    public int DrugId { get; set; }
    public int Quantity { get; set; }
    public int LpuId { get; set; }
    public int PhysicianId { get; set; }
    public int OperatorId { get; set; }
    public int CategoryId { get; set; }
    public int Status { get; set; }
    public DateTime RecourseDate { get; set; }
    public DateTime ServedDate { get; set; }
    public int ServedDrugId { get; set; }
    public int ServedQuantity { get; set; }
}

[Guid("7C1331D7-320D-4201-889C-AF56BFE0D71A")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("Mine.SCComponent")]
public class SCComponent : ISCComponent
{
/*class logic goes here*/
        public int AddCardHolderServedPrescription(CardHolderNewServedPrescriptionData newServedPrescriptionData)
    {
/*method body*/
            }
    }

1 个答案:

答案 0 :(得分:0)

好吧,经过另一个小时的调试和脚本重写 - 这是我的错。问题是另一个类在同一个库中注册了相同的ProgID,“Mine.CardHolderNewServedPrescriptionData” - 它有一些具有相同签名的属性,这增加了混乱。

因此,我只能推荐未来是ProgIDs的准确性(没有自动验证)和脚本调试器中对象本身的检查(wscript // X以调试模式运行脚本)