Hm. I was hoping to find more about this; all I found web-searching now was a side comment on this old blog

[link:blogs.msdn.com]

that says

This has the effect of marshaling the delegate into that AppDomain and then dispatching to it there. The assemblies containing the delegate and the target of the delegate will be created in the specified AppDomain.

which suggests this is the by-design behavior?

By on 4/4/2009 11:44 AM ()

Perhaps?

One thing, from here:

Data can only be marshaled across AppDomain boundaries if it is either remotable or serializable. Remotable data is an instance of a class that descends from System.MarshalByRefObject.

Are F# closures either remotable or serializable?

By on 4/4/2009 12:01 PM ()

F# closures are marked serializable, and I've actually persisted them to a database and reloaded them later. So in this case it's probably returning the serialized closure, and to deserialize it needs the concrete type?

I'm not too up on cross-AppDomain stuff, but the way I think I've solved this in the past is to make sure I'm executing everything in the target AppDomain. This consists of loading my executable code (the runner) into the new AppDomain, and having it do its work there. That way I don't get things leaking back into the original AppDomain.

By on 4/4/2009 12:14 PM ()

Ah, got it finally:

1
2
3
4
5
6
7
8
9
10
11
12
13
let appdom = AppDomain.CreateDomain("TestDomain")

let baz : (int -> int) ref = ref id

appdom.DoCallBack(fun () ->
let asm = Assembly.Load("MyTest") 
let test = asm.CreateInstance("MyTest.Test") :?> ITest
baz := test.Baz
) 

AppDomain.Unload(appdom)

File.Delete("MyTest.dll")

it appears that only a copy of baz gets modified within the scope of the DoCallBack lambda, the original baz is unmodified...

By on 4/4/2009 12:40 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper