Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

problem with AppDomain

$
0
0

I have have asked before about how to use the Appdomain to be able to load and unload Dll file and in the same time be able to pass arrays. And actually someone whom I thank a lot recommended me to use the AppDomain and he suggested to me the following code:

Public Class Form1 Private FortranDomain As AppDomain Private FortranAgent As DomainAgent '1) Create the domain Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click FortranDomain = AppDomain.CreateDomain("Domain") FortranAgent = CType(FortranDomain.CreateInstanceAndUnwrap(GetType(DomainAgent).Assembly.GetName().FullName, _ GetType(DomainAgent).FullName), DomainAgent) End Sub '2) Use the methods in the domain agent Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'Well, here the values are to be set right !! Dim IA() As Int32 = {1, 2, 3, 4, 5} Dim A() As Double = {} Dim IB() As Int32 = {1, 2, 3, 4, 5} Dim B() As Double = {} FortranAgent.oFortranDLL(A, IA) FortranAgent.oIntrFControl(B, IB) End Sub '3) Unload the domain and assemblies Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click AppDomain.Unload(FortranDomain) End Sub End Class Friend Class DomainAgent : Inherits MarshalByRefObject Public Sub New() End Sub Public Sub oFortranDLL(ByRef A() As Double, ByVal IA() As Int32) FortranDLL(A, IA) End Sub Public Sub oIntrFControl(ByRef A() As Double, ByVal IA() As Int32) IntrFControl(A, IA) End Sub Private Declare Sub FortranDLL Lib "C:\Sams2000\Applications\ATTIF2000\Engine\ATTIFDLLENG.dll" Alias "FORTRANDLL" (ByRef A() As Double, ByVal IA() As Int32) Private Declare Sub IntrFControl Lib "C:\Sams2000\Applications\ATTIF2000\Engine\ATTIFDLLENG.dll" Alias "INTRFCONTROL" (ByRef A() As Double, ByVal IA() As Int32) End the code can pass the arrays without any problems but the only problem come from

FortranAgent=CType(FortranDomain.CreateInstanceAndUnwrap(GetType(DomainAgent).Assembly.GetName().FullName, _ GetType(DomainAgent).FullName), DomainAgent)where the program will crash and give me the following attached error

I would like to thank the person who help me to have this code and I will be do appreciated if any one can help me to figure out what is the source of this problem

Many thanks

Ahmed

      

Viewing all articles
Browse latest Browse all 1710

Trending Articles