开发者

"Class does not support automation" error when using own class from JScript

I have a project which exposes object model to use by different types of clients. Written in .Net 3.5 it exposes classes to COM. Problem is while all seems to work from test VB6 client, I faced strange errors while trying to automate it with JScript and Windows Script Host.

Here's code snippet:

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);

Got following problems while running it:

  • commented lines failing with error "Object does not support such property or method"
  • Prescription.Date is defined as System.DateTime, but assignment of JScript Date does not work here - but it seems to accept (or somehow cast) string date.
  • final line with AddCardHolderServedPrescription call fails with "Class does not support automation" error.

Calls to other scComponent methods passing correctly, so I suppose there are some problems with CardHolderNewServedPrescriptionData type. Now I need some clues to troubleshoot it - script error messages aren't too informative. Google searches return no meaningful information about diagnostics methods.

Again, it works both in my C# tests and VB6 client, but not JScript. Thanks for any ideas.

Type definitions and interface fragments goes below.

[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*/
            }
    }


Well, after another hours of debugging and script rewriting - that's my fault. Problem was another class was registered with same ProgID, "Mine.CardHolderNewServedPrescriptionData" in the same library - and it has some of the properties with same signatures, which added confusion.

So, only recommendation I could make for the future is accuracy with ProgIDs (no validation perfromed automatically) and examination of the object itself in the script debugger (wscript //X to run script in debug mode)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜