AnsweredAssumed Answered

Getting a "Memory is locked" exception in VB.NET

Question asked by J. R. on Apr 16, 2018
Latest reply on Apr 16, 2018 by Jacob Corder

Hello,

 

I am transferring a big macro project from VBA to VB.NET (working with Visual Studio). Since the languages are almost identical, most things work right out of the box.

However, a certain procedure that uses a swModeler.CreateBodyFromBox3 method, using a 8 Double array as an argument, throws this exception:

 

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in Hydrostatics Calculator.exe

 

Additional information: Memory is locked. (Exception from HRESULT: 0x8002000D (DISP_E_ARRAYISLOCKED))

 

This is the part of the code that is relevant to this error:

 

        swModeler = swApp.GetModeler
        vBox = BodyCopy.GetBodyBox()
        width = BoatWidth * 10
        height = 0.001
        length = BoatLength * 10
        dBoxData(0) = (vBox(3) + vBox(0)) / 2 : dBoxData(1) = 0 : dBoxData(2) = (vBox(5) + vBox(2)) / 2
        dBoxData(3) = 0 : dBoxData(4) = 1 : dBoxData(5) = 0 'vector
        dBoxData(6) = width : dBoxData(7) = length : dBoxData(8) = height 'size
        swCutBody = swModeler.CreateBodyFromBox3(dBoxData)

 

The exception happens on line 9. I can't find much about this issue on google. This code worked fine when I used it in VBA macro, but doesn't work anymore in VB.NET compilation. I reviewed the examples of CreateBodyFromBox3 in the official documentation, but I can't seem to find any relevant difference between the sample code, and my code.

 

I would appreciate any suggestions. Thank you for your time.

Outcomes