[V8i C#] System.ExecutionEngineException Error

Hi,

I'm trying to place a cell using the C# API which worked previously in v8i (08.11.09..209) but I have recently switched to V8i (08.11.09.459) and after recompiling in this it crashed Microstation with the exception:  "An unhandled exception of type 'System.ExecutionEngineException' occurred in ustation.dll"

            BCOM.Application app = Utilities.ComApp;
            BCOM.Point3d origin = app.Point3dZero();
            BCOM.Point3d scale = app.Point3dZero();
            BCOM.Matrix3d rotMat = app.Matrix3dFromAxisAndRotationAngle(2, 0.0);

            scale.X = 1.0;
            scale.Y = 1.0;
            scale.Z = 1.0;
            MessageBox.Show("#1");
            app.AttachCellLibrary("c:\\temp\\library.dwg");
            MessageBox.Show("#2");
            BCOM.CellElement oCell = app.CreateCellElement2("test", ref origin, ref scale, true, ref rotMat);
            MessageBox.Show("#3");
            app.ActiveModelReference.AddElement(oCell);

It gets to MessageBox #2 and then next line causes the crash.

  • Hi Darren,

    Unknown said:
    after recompiling

    I see no reason to recompile NET code between V8i builds. What works in older V8i should work also in newer versions.

    Unknown said:
    it crashed Microstation with the exception

    Usually more details are provided when an exeption is reported, not only exception name. Also, did you try to debug and go step by step and check what is happening. To debug application using MessageBox is pretty ugly way, we have debug mode and tools to do it better.

    I see no error in your code, but what I miss are tests:

    • To check if the cell library was really attached.
    • Before you call CreateCellElement method, you should test if the cell really exists in the attached cell library. I have no experience with dwg used as cell libraries, but I suppose if you attach library.dwg, there will be no test cell in it.

    With regards,

     Jan

  • When i say recompiling I meant I had to change the paths to the various Bentley DLL references because they pointed to a previous version. There were also no details provided like you get in a normal exception Microstatation faded and a dialog saying Microstation V8i (Select Series 3) has stopped working. Then it trys to find a solutiion, fails, and gives me the option to Debug or Close program. If I press the Debug it opens in Visual Studio but just says "An unhandled exception of type 'System.ExecutionEngineException' occurred in ustation.dll"

    I will add the checks and also try a different cell library.
  • I have checked if the library is attached before creating the cell, and it was. It turns out its the truescale flag. If its set to true I get the error, false seems to work. Do you think something has changed between version of Microstation that could be causing this?
  • Hi Darren,

    Unknown said:
    I meant I had to change the paths to the various Bentley DLL references because they pointed to a previous version.

    Well, they do, but only in Visual Studio project. If there is existing NET assembly for older version of MicroStation and it's run in newer V8i, correct referenced assemblies are used automatically.

    Unknown said:
    There were also no details provided like you get in a normal exception Microstatation faded and a dialog saying Microstation V8i (Select Series 3) has stopped working.

    This is not pro-active debugging. I recommend to study what debugging is and it can be used in Visual Studio.

    Shortly: Compile your addin in Debug mode, place dll plus pdb files where they should be, start MicroStation, load you addin and attach Visual Studio to MicroStation process with Managed option to be able to debug NET addin. Define break points in your code. Start a proper function and the application will stop at defined break point, so you can check states of used variables and objects.

    Unknown said:
    Do you think something has changed between version of Microstation that could be causing this?

    I don't know about any such change. Did you try to place the same cell to the same dgn file manually to be sure it works with such setting?

    One more question about your code: BCOM.Application app = Utilities.ComApp means your addins name is Utilities?

    With regards,

      Jan

  • When you say the correct assemblies are used when using running an older .NET assembly in a newer version, what if Bentley change some of the classes and such like, wont it causes issues? When you deploy a .NET addin are you not supposed to distribute the bently dlls aswell then?

    I've done debugging by attaching to the ustation process when i step into the cell creation line i get the same ustation exception.

    In the output window i get:
    Step into: Stepping over method without symbols '<Module>.Bentley.MicroStation.ManagedTextStyleEventHelper.OnTextStyleEvent'
    An unhandled exception of type 'System.ExecutionEngineException' occurred in ustation.dll

    In the call stack window it says:
    ustation.dll!<Module>.Bentley.MicroStation.ManagedTextStyleEventHelper.raiseEvent(Bentley.MicroStation.AddIn addIn, Bentley.MicroStation.AddIn.TextStyleChangeEventArgs args) + 0xd7 bytes
    ustation.dll!<Module>.Bentley.MicroStation.ManagedTextStyleEventHelper.OnTextStyleEvent(Bentley.Ustn.Text.DgnTextStyle* before, Bentley.Ustn.Text.DgnTextStyle* after, Bentley.Ustn.Text.TextStyleEventType type) + 0x1bf bytes
    [Native to Managed Transition]
    [Managed to Native Transition]

    The Utilities.ComApp is equal to Bentley.Microstation.InteropServices.Utilities.
    Is this not the correct way to do this?
  • Unknown said:
    what if Bentley change some of the classes and such like, wont it causes issues?

    If anything in API changed, of course it will cause troubles. But V8i VBA/NET API is pretty stabilized, for the whole V8i history I don't know about such case ... and we are not in native C/C++ world that is more fragile and sensitive about versions. So it's a kind of "trust based on personal experience and some assumptions".

    Unknown said:
    When you deploy a .NET addin are you not supposed to distribute the bently dlls aswell then?

    No, why?

    Unknown said:
    I've done debugging by attaching to the ustation process when i step into the cell creation line i get the same ustation exception.

    Of course you got the same exception, it would be really surprise if another exception just because of debugging. But you are able to better check the addin status including call stack etc.

    Unknown said:
    In the call stack window it says:

    Strange, why cell placement relates to TextStyle event?

    Unknown said:
    The Utilities.ComApp is equal to Bentley.Microstation.InteropServices.Utilities. Is this not the correct way to do this?

    It depends and it cannot be told from your code snippert. If you use Bentley.MicroStation.InteropServices.Utilities.ComApp directly every time, I am not sure if it is valid. All Bentley examples initialize private static variable to Bentley.MicroStation.InteropServices.Utilities.ComApp in Run method. And this variable, not  Bentley.MicroStation.InteropServices.Utilities.ComApp, is used when the reference to COM API is required. It makes sense, in Run method it tells "this reference is valid for this addin". I don't know if Bentley.MicroStation.InteropServices.Utilities.ComApp can change later or not, I use what is used in examples and what works.

    With regards,

      Jan

  • Yes i thought it was weird that it relates to a textstyle event but I don't know how I could debug the ustation.dll.
    My previous thought it was the TrueScale flag seemed not to be the case, to get it to work if I place the cell manually, delete it, and then run my addin to place the cell it works. Its like there is some variable/setting not initalized properly in my code. If I close Microstation after this has worked and go back in and run the addin it fails again until I add a cell.

    Also, I'm not sure this version of microstation 08.11.09.459 is working right because I tried to open the ToolBoxes from them menu and it crashed Microstation. It's like its not installed properly what do you think?

    System fault: 99
    "dpalhook.mc"dpalHook_genToolBoxList
    MDL Loader: Could not load application e:\Builds\pp081109459\Source\msj\mstn\mdlapps\draftpal\dpalhook.mc
    DRAFTPAL is the MDL debug application.
  • I recently encountered same issue and found a solution here:

    Deleted file Bentley.PowerPlatform.FeatureAspects.dll under the folder ...\MicroStation\mdlapps.