0

I have been trying to implement a dll that basically registered as COM Object which get invoked through some external services (RMS - Retail Management Solution).

So, in order to implement the dll i have created a library project, add Windows form functionality that display some buttons, fields etc and, then get this DLL registered in assembly so external service can access it easily.

To test this dll, i created a Console project, add the dll inside and it works fine. However, when i registered in Assemblies and external Services (RMS) tries to call it, it doesn't open a Windows Form and end up with following exception. "Attempt to execute COM object failed. Internal error found".

FYI - I have added Windows.Forms and System.Drawing reference.

To debug it further, i added Message box that being called perfectly fine means DLL is registered properly.

Transaction

using QSRules;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Windows.Forms;

    namespace Sales
    {
    public class Transaction
    {
    public Boolean Process(Object session)
    {
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Service());
    return true;
    }
    }
    }

Second Class is called "Service" which extends Form to display windows Forms components like Button etc

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace Sales
{
public partial class Service : Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

public Service()
{
System.Windows.Forms.MessageBox.Show("In Service");
InitializeComponent();
System.Windows.Forms.MessageBox.Show("Loaded Successfully");
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
// 
// button1
// 
this.button1.Location = new System.Drawing.Point(76, 109);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
// 
// Service
// 
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.button1);
this.Name = "Service";
this.Text = "Service";
this.Load += new System.EventHandler(this.Service_Load);
this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.Button button1;

private void button1_Click(object sender, EventArgs e)
{

}

private void Service_Load(object sender, EventArgs e)
{

}
}
}

Any idea? why its getting failed.

2
  • Missing references? Commented Dec 18, 2016 at 16:13
  • Thanks for the reply. Reference of what? I have added Windows.Forms and System.Drawing reference. BTW, it works when i test it through Console application Commented Dec 18, 2016 at 16:16

1 Answer 1

0

Just found an solution. The problem was related to the following link

Application.Run(new Service());

Application.Run doesn't support when any component registered as COM Object. SO make t working, i removed the Applciation.Run and call ShowDialog method with service.

new Service().ShowDialog()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.