forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

.NET callback error

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
LEP



Joined: 06 Oct 2020
Posts: 2

PostPosted: Tue Oct 13, 2020 7:17 pm    Post subject: .NET callback error Reply with quote

I am getting the following exception when instantiating a .NET Class (Object) in which a method calls an interfaced FORTRAN subroutine. When the call to the subroutine is done using a method that's not in a Class, the error doesn't occur. However, calling the sub inside a method of a Class results in un-managed code that undergoes GC (garbage collection).

"Additional Information: A callback was made on a garbage collected delegate of type ftn95lib.mdl!Salford.Fortran.RTLibrary+clearwin_callback::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called."

I am also using

Code:
Implements IDisposable

inside the class, and immediately after instantiation I loop until a Boolean parameter is set to true at the end of the particular method (inside the class). Altogether the code is

Code:
Dim obj as new ClassName
Do Until IsFinished = True
Loop
obj.Dispose()

However, .NET's GC sees reference to the FORTRAN assembly as unmanaged code without a handle, and kills it.

Any suggestions?


Last edited by LEP on Tue Oct 13, 2020 8:36 pm; edited 2 times in total
Back to top
View user's profile Send private message
LEP



Joined: 06 Oct 2020
Posts: 2

PostPosted: Tue Oct 13, 2020 8:19 pm    Post subject: RESOLVED - Callback exception from .NET Reply with quote

RESOLVED.

The proper way to call a DLL or your FORTRAN subroutine from inside a .NET method (subroutine), that is inside a .NET Class object is to simply invoke the Using command. For example, instantiate the class directly in the following call:

Code:
Using obj As New ProcClass(param1, param2, param3)

End Using

and be sure to type "Implements IDisposable" after the class definsition like
Code:
Public ProcClass As Class
   Implements IDisposable
...
End Class


The
Code:
Using
environments requires the IDisposable feature of a class so it that the
Code:
End Using
can release resources for garbage collection (GC). This actually works very nicely and is seamless.

Also, FYI for .NET users, make sure you select "Prefer 32-bit" in the Compile tab of the C# or VB.NET project's Properties. If you don't do this you will receive an error at run-time.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group