The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))"

i am trying to convert dgn file to pdf file and that pdf file has to be get printed.But, not able to convert dgn file to pdf file in bentley microstation v8i. 

code :

for (i = 0; i < dt.Rows.Count; i++)
{
oCopyContext = new CopyContextClass();
Element ele = default(Element);
DLong Id = default(DLong);
Id.High = 0;
Id.Low = Convert.ToInt32(dt.Rows[i][0].ToString());

{
ele = (Element)(ofile.DefaultModelReference.GetElementByID(ref Id));
if (ele != null)
{
ele.IsLocked = false;
ele.Color = 152;
ofile.DefaultModelReference.CopyElement(ele, oCopyContext);
}
}
}

error at the line : ofile.DefaultModelReference.CopyElement(ele, oCopyContext);

source : Interop.MicroStationDGN

stack Trace : at MicroStationDGN.ModelReferenceClass.CopyElement(_Element Element, CopyContext CopyContext)
at Xorail.CADAutomation.CADInterface.BentleyInterfaceBase.StartPDFForSingleFileComparer(String designfile, String outFileName, String pdfpath, DataTable dt, DataTable dt1, String Filetype) in d:\VisualStudioProjects\CADAutomation\CADInterface\BentleyInterfaceBase.cs:line 10124

please provide me solution..its much needed.

Parents
  • Hi shiv,

    at first, a few notes:

    • Please read and follow Programming forum best practices and accordingly to these practices to specify MicroStation version (not just V8i, but its build number) and also language used. I am aware we are in Addins/.NET forum and from your code it can be deduced you use C#, but it's better to be "forum good citizen" and to share as much information as possible in a clear form.
    • Please use Syntax Highlighter tool (yellow pencil icon in Advanced Editor) whenever you posted any code. If you will use this tool and will choose C# as a language, it will be displayed, formated and colored in a correct way.

    I have to say I don't understand too much what your code does (e.g. why you use default() which is used in parametrized code usually, why you cast an element to element, where ofile is defined etc.), so it's hard to investigate why there is a problem with an element copy.

    Unknown said:
    i am trying to convert dgn file to pdf file and that pdf file has to be get printed.

    Why to don't use MicroStation pdf.pltcfg driver and to print a design file to pdf using standard MicroStation tools?

    With regards,

      Jan

  • Hi Jan,
    I am converting dgn file to pdf file through c# programatically. i having all the element id of dgn file in table dt and dt1. its all working fine,
    but there is an error at the line : ofile.DefaultModelReference.CopyElement(ele, oCopyContext);
    error : The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))
    while copying all the element values at that line.
    please help me

    .ofile is defined as   ofile = _app.OpenDesignFileForProgram(sfilepath, false);

      where , string sfilepath = pdfpath + "\\" + sfile;

    where ,   string sfile = outFileName + "x" + ".dgn";

    what can i use instead of default()..?

    just i need to copy element to ofile and finally saving  as

    ofile.save();

  • Hi,

    again, why you did not use Syntax highlighter to post your code? Reading code displayed as a normal text is ugly.

    Unknown said:
    I am converting dgn file to pdf file through c# programatically.

    Well, this looks strange to me and I don't know how converting dgn to pdf relates to copying elements into another desgin file, but I don't know all details. Just my person opinion.

    Unknown said:
    i having all the element id of dgn file in table dt and dt1.

    Again, I don't know why such solution is used and not e.g. enumerator is used. A question is what does it means "all the element id"? There are elements that cannto be copied (e.g. level table, design file header, model definition etc.) and also elements with relation to another element (e.g. if I have element it of element inside a cell, I probably want to copy the whole cell, not this element).

    I think you have to debug what element causes the error. Maybe you are trying to copy element from cell or some special element? If it will be a normal graphic element, I guess there will be some problem with accessing MicroStation using application object (and to share more code will be required).

    With regards,

      Jan

  •  [Microstation V8i CONNECT C#]

    my work is to compare two files and highlight the changes in both the files by changing element color. it is comparing correctly and highlighting the changes. 

    In next event, when i click the another button,same functionalities will repeats... it compares both the file, highlights the changes by changing element color. then, that element id is saved in dt table. 

    then, below code begins,

    before  code changing :

    oCopyContext = new CopyContextClass();
    Element ele = default(Element);
    DLong Id = default(DLong);
    try
    {
    // CloseDesignFile(); //Shiva J code changes
    for (i = 0; i < dt.Rows.Count; i++)
    {


    Id.High = 0;
    Id.Low = Convert.ToInt32(dt.Rows[i][0].ToString());
    {
    ele = (Element)(ofile.DefaultModelReference.GetElementByID(ref Id));
    if (ele != null)
    {
    ele.IsLocked = false;
    ele.Color = 152;
    try
    {
      ofile.DefaultModelReference.CopyElement(ele, oCopyContext);

    }
    catch (Exception ex) // shiva J code Changes
    {
    Trace.WriteLine("StartPDFWrk", ex.ToString());
    Trace.WriteLine("StartPDFWrk", ex.StackTrace);
    // ofile.Save();
    System.GC.Collect();
    }
    }
    }
    }
    }
    catch (Exception ex)
    {
    Trace.WriteLine("StartPDFWrk", ex.ToString());
    }
    finally
    {
    oCopyContext = null;
    ele = null;
    }

    after code changing :

    oCopyContext = new CopyContextClass();
    Element ele = default(Element);
    DLong Id = default(DLong);
    try
    {
    // CloseDesignFile(); //Shiva J code changes
    for (i = 0; i < dt.Rows.Count; i++)
    {


    Id.High = 0;
    Id.Low = Convert.ToInt32(dt.Rows[i][0].ToString());
    {
    ele = (Element)(ofile.DefaultModelReference.GetElementByID(ref Id));
    if (ele != null)
    {
    ele.IsLocked = false;
    ele.Color = 152;
    try
    {
    // ofile.DefaultModelReference.CopyElement(ele, oCopyContext);
    _app.ActiveModelReference.CopyElement(ele, oCopyContext);
    }
    catch (Exception ex) // shiva J code Changes
    {
    Trace.WriteLine("StartPDFWrk", ex.ToString());
    Trace.WriteLine("StartPDFWrk", ex.StackTrace);
    // ofile.Save();
    System.GC.Collect();
    }
    }
    }
    }
    }
    catch (Exception ex)
    {
    Trace.WriteLine("StartPDFWrk", ex.ToString());
    }
    finally
    {
    oCopyContext = null;
    ele = null;
    }

    after changing code just by,

     ofile.DefaultModelReference.CopyElement(ele, oCopyContext);   to       _app.ActiveModelReference.CopyElement(ele, oCopyContext);

    It created pdf file in my system.But, i needed highlighted color file as pdf . but i my getting normal dgn file

     as pdf.

    Can i change code with in this  loop only to get expected pdf. please, provide some answer to this. 

  • Unknown said:
    [Microstation V8i CONNECT C#]

    What exactly does it mean? Are you developing for V8i or for CONNECT Edition? These versions provide different APIs to be used from C# and also on different NET Framework versions.

    Unknown said:
    please, provide some answer to this. 

    No at least until you will post properly formatted code. If you are not willing to use Syntaxhighlighter tool to make your posts readable easily, why other peopl should be willin to investigate a solution and to write answers? The discussion always have to balanced in terms of invested effort.

    With regards,

      Jan

Reply Children
No Data