Hi Everyone,
I am trying to create a stand alone VB.NET EXE application that simply opens up MicroStation, pulls some tag information and closes. I have created these types of applications before but not for quite a while so i must be a bit rusty.
I am having issues with the error messages stating "RPC Server Unavailable" and similar. I can also see that once the new Instance is called that nothing is showing in task Manager. So my question is what am i doing wrong for MicroStation not to open?
I have looked at previous projects and the below used to work, but for troubleshooting I have created a new, very bare application just to test this functionality to remove any other potential issues but still having the same problem. I have referenced the MicroStationDGN library in Visual Studio and imported the namespace. The entire code is below. At this stage i'm just trying to get MicroStation to open, then i will add the tag functionality into it once i know im on the right track. I can open MicroStation with no issues from the Start Menu so it is working normally.
The version of MicroStation on this test machine is V8i SS3 (08.11.09.292) - Yes i know its old, but its just the test machine.
Imports MicroStationDGN Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim ustn As New MicroStationDGN.Application Dim odesignfile As MicroStationDGN.DesignFile Try odesignfile = ustn.OpenDesignFile("C:\Temp\rob.dgn") Catch ex As Exception MsgBox(ex.Message) End Try End Sub End Class
Robert Golding said:I have referenced the MicroStationDGN library in Visual Studio
To be sure, by "MicroStatioDGN library" you mean bentley.interop.microstationdgn.dll assembly or any other file?
Robert Golding said:I am having issues with the error messages stating "RPC Server Unavailable" and similar.
It looks weird. But where the message is displayed? And on what line of your code?
Robert Golding said:Yes i know its old, but its just the test machine.
As Jon wrote, to differentiate between V8 and CE requires the project modification (and of course also to reference different Interop assembly), so the code has always be tested with the right target product.
BTW Do you see the same behavior on other PC, when exe is copied from the test machined? ... just to ensure the problem is not in corrupted installation, because access through COM/Interop is notoriously fragile.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Thanks Jan.
Jan Šlegr said:To be sure, by "MicroStatioDGN library" you mean bentley.interop.microstationdgn.dll assembly or any other file?
Yes, it is the Interop.dll. Screengrab attached for reference
Jan Šlegr said:It looks weird. But where the message is displayed? And on what line of your code?
It fails on line 11... "odesignfile = ustn.OpenDesignFile("C:\Temp\rob.dgn")"
From what i can tell, an instance of MicroStation hasn't started, which should have opened at line 6. So Line 11 is calling something which isn't there, which results in the failure.
Jan Šlegr said:so the code has always be tested with the right target product.
The target is the V8i suite. In the past with these similar apps i haven't found an compatibility issues between SS1 and SS10, but perhaps im just lucky if they are fragile as you say.
Jan Šlegr said:BTW Do you see the same behavior on other PC, when exe is copied from the test machined? ... just to ensure the problem is not in corrupted installation, because access through COM/Interop is notoriously fragile.
I haven't tested on another machine yet as its still just in debugging stage. But my first step before posting here was to repair the installation of MicroStation and it does function fine when opening normally.
Robert Golding said:Yes, it is the Interop.dll. Screengrab attached for reference
I guess (but it's just a thought) it's not.
What I see on your screen capture is ActiveX / COM registered library (moreover, placed in the app folder), but not referenced Interop assembly (located in MicroStation folder structure).
How did you add this lib to the project? I do not know VB.NET well, but I guess you have to use Add Reference ... > Browse, not to select registered COM libraries.
Regards,
One more comment: I see an option Embed Interop Type in the library settings:
Jan Šlegr said:How did you add this lib to the project? I do not know VB.NET well, but I guess you have to use Add Reference ... > Browse, not to select registered COM libraries.
I browsed to the DLL in the MicroStation install folder. I have used this method before with no issues.
I did look through the COM list within the references and there is no MicroStation option there
Robert Golding said:I browsed to the DLL in the MicroStation install folder. I have used this method before with no issues.
I see different result in VS2017, when I add the reference to Interop assembly in VB.NET Framework 3.5 project:
I was able to add that file as a reference, it was found under
C:\Program Files (x86)\Bentley\MicroStation V8i (SELECTseries)\MicroStation\assemblies\bentley.interop.microstationdgn.dll
However, im now not able to declare ustn
Robert Golding said:However, im now not able to declare ustn
Yes. And Visual Studio tells you why: Application is interface, so you cannot to use new (to create an instance of the interface).
As I wrote above: In Interop, there are Application interface and ApplicationClass class.
So the correct code should be:
Imports Bentley.Interop.MicroStationDGN Module Module1 Sub Main() Dim mstnApp As Application mstnApp = New ApplicationClass mstnApp.Visible = True Dim designFile As DesignFile designFile = mstnApp.OpenDesignFile("C:\temp\blank.dgn") End Sub End Module
Thanks for all your help to date Jan, really appreciated!
I did try your suggestion above and receive the below error
Robert Golding said:I did try your suggestion above and receive the below error
The message is clear in my opinion, and it's what I mention earlier already: In the assembly reference specification, Embed Interop Type setting is True, but has to be False.
As I wrote, it's strange it's even displayed, because it means your project probably targets NET 4 or higher (this option is not available in NET 3), whereas MicroStation V8i is based on NET Framework 3.5. I am not sure whether it's fully supported / compatible to use NET 4 with NET 3.5 Interop.