I am getting an issue regarding running autocad application using C#. As i am beginner most of my code is copy pasted from net.
The problem is i am developing an web application using c# which will create an instantiate autocad instance at runtime. Every thing goes fine on development server as well as on my local IIS server. but when i am deploying the web application on the server(window server 8) i am getting the below error
Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))
at System.Runtime.InteropServices.Marshal.GetActiveObject(Guid& rclsid, IntPtr reserved, Object& ppunk)
at System.Runtime.InteropServices.Marshal.GetActiveObject(String progID)
at DQMF.CDQMF.createAacdApplicationInstance(String progID)
I think it is because of some privilege issue. as on my local machine autocad instance is running with privilege of system and on server(windows server 8) it is running(with development server) as administrative privilege.
AcadApplication createAacdApplicationInstance(string progID)
{
AcadApplication app = null;
try
{
app = (AcadApplication)Marshal.GetActiveObject(progID);
}
catch (Exception e)
{
try
{
Type acType = Type.GetTypeFromProgID(progID);
app = (AcadApplication)Activator.CreateInstance(acType, true);
app.Visible = false;
app.Width = 1;
app.Height = 1;
app.WindowState = AutoCAD.AcWindowState.acMin;
app.Visible = false;
}
catch (Exception ex)
{
//File.AppendAllText("D:/test/DQMS_log.txt", ex.Message+" progID is: "+progID+Environment.NewLine+"app caption: "+app.Caption);
}
}
return app;
}
If you want some more detail i can give
Your marshalling is failing because the ASP.NET process runs on a separate account, and has a completely different Running Object Table (ROT). I am pretty sure for this to work you'll have to instanciate a new session from the ASP.NET side.
When working with visual interops, it is not as straightforward to run instances of applications that expect direct user interaction from asp.net.
You may have to use a windows form or WPF application to work with AutoCAD. The issue may be that the AutoCAD.Application interop does not allow for non-visual interaction.
User contributions licensed under CC BY-SA 3.0