.net 从JScript使用自己的类时出现“类不支持自动化”错误
我有一个项目,它公开对象模型供不同类型的客户端使用。用.NET3.5编写,它向COM公开类。问题是,虽然所有这些似乎都可以从测试VB6客户端运行,但在尝试使用JScript和Windows脚本主机将其自动化时,我遇到了奇怪的错误 下面是代码片段:.net 从JScript使用自己的类时出现“类不支持自动化”错误,.net,javascript,com,scripting,automation,.net,Javascript,Com,Scripting,Automation,我有一个项目,它公开对象模型供不同类型的客户端使用。用.NET3.5编写,它向COM公开类。问题是,虽然所有这些似乎都可以从测试VB6客户端运行,但在尝试使用JScript和Windows脚本主机将其自动化时,我遇到了奇怪的错误 下面是代码片段: var scComponent = new ActiveXObject("Mine.SCComponent"); var Prescription = new ActiveXObject ("Mine.CardHolderNewServedPrescr
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);
运行时出现以下问题:
错误对象失败的注释行不支持此类属性或方法
Date被定义为System.DateTime,但JScript日期的赋值在这里不起作用-但它似乎接受或以某种方式强制转换字符串Date。
带有AddCardlerServedPrescription调用的最后一行失败,类不支持自动错误。
对正确传递的其他scComponent方法的调用,因此我认为CandleNewServedPrescriptionData类型存在一些问题。现在我需要一些线索来解决它-脚本错误消息的信息量不太大。谷歌搜索没有返回关于诊断方法的有意义的信息
同样,它可以在我的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*/
}
}
好吧,在又一个小时的调试和脚本重写之后——这是我的错。问题是另一个类在同一个库中注册了相同的ProgID,Mine.candlerNewServedPrescriptionData,并且它的某些属性具有相同的签名,这增加了混淆 因此,我对未来唯一的建议是使用ProgIDs的准确性—不自动执行验证,并在脚本调试器wscript//X中检查对象本身,以便在调试模式下运行脚本