Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssemblyLoadContext documentation #6016

Closed
jkotas opened this issue Jun 3, 2016 · 27 comments
Closed

AssemblyLoadContext documentation #6016

jkotas opened this issue Jun 3, 2016 · 27 comments
Assignees
Labels
area-AssemblyLoader-coreclr documentation Documentation bug or enhancement, does not impact product or test code
Milestone

Comments

@jkotas
Copy link
Member

jkotas commented Jun 3, 2016

There are a lot of questions being asked on how this works - we need to have documentation for it.

@jkotas
Copy link
Member Author

jkotas commented Jun 3, 2016

cc @gkhanna79

@jkotas
Copy link
Member Author

jkotas commented Jun 3, 2016

https://blogs.msdn.microsoft.com/dotnet/2016/05/27/making-it-easier-to-port-to-net-core/#comment-77765 has some frequently asked questions that this documentation should provide answers to.

@gkhanna79
Copy link
Member

Sounds good @jkotas I will look into this next week.

@Ninds
Copy link

Ninds commented Jun 8, 2016

On the blog at the link above you write :

"AssemblyLoadContext does not provide data isolation. Objects can be passed between them without"

.. but is this not then inconsistent with having separate static variables per context ?

Essentially I want parallelism with a very low dependency on having to write thread-aware code. Appdomains gave that to me.

@jkotas
Copy link
Member Author

jkotas commented Jun 8, 2016

I am not sure where you see the inconsistency. For both AppDomain and AssemblyLoadContext, the code that sets up your computation has to be thread-aware.

@Ninds
Copy link

Ninds commented Jun 14, 2016

Hi,
Sorry I wasn't very clear. It is true the "scaffolding" code written by developer A would have to be threadsafe. But the code that will run in each context written by developer B should not have to be threadsafe, Developer A would be the more experienced dev who is comfortable coding in a world consisting of multiple threads but developer B is .. for example a mathematician who shouldn't need to worry about writing code that is threadsafe. He should be able to write code that computes his formulae without having to concerns himself with some complex paradigms in software engineering. With the infrastructure that Devloper A provides the software is able to service multiple requests for computation of Developer B's algorithm. I realise it appears a bit of a contrived example however it is pretty close to what my situtation is. I don't want to tell Developer to not use static variables for example.

@jkotas
Copy link
Member Author

jkotas commented Jun 14, 2016

@Ninds Your example makes sense. It should be possible to build this with AssemblyLoadContext.

@Ninds
Copy link

Ninds commented Jun 14, 2016

ah great. so isolated static variables in each context ?
But I guess we would have to build our own proxies of class which are to be called across context boundaries .. but since they should be very minimal and light that should not be a big problem.

So will we be getting some doc on this feature soon ?
Will AssemblyContexts be added to .NET Framework in the future too ?

@Ninds
Copy link

Ninds commented Jun 14, 2016

.. one more thing will exceptions propagate across context boundaries ?

@jkotas
Copy link
Member Author

jkotas commented Jun 14, 2016

isolated static variables in each context ?

Correct.

some doc on this feature soon ?

@gkhanna79 is going to start working on the docs soon.

Will AssemblyContexts be added to .NET Framework in the future too ?

It is in our backlog - we do not have the date for it.

one more thing will exceptions propagate across context boundaries ?

Yes.

@Ninds
Copy link

Ninds commented Jun 14, 2016

That's GREAT !
Thanks very much !
I'll come back later with any other questions.

@OpinionatedGeek
Copy link

Hi

I'd like to chime in with a couple of other AssemblyLoadContext questions. (I'm told this is the place to ask them so they'll be addressed in the documentation - apologies if this isn't the right place.)

  • How do I unload/discard assemblies?
  • When I unload the assemblies, is the memory allocated to their objects freed (made available for GC)?

The scenario I'm interested in is a long-running server that compiles and loads some source code (and runs it etc.) but can unload it and recompile and reload a new instance of it if the source code is changed.

Looking at the current source code for AssemblyLoadContext (https://github.com/dotnet/coreclr/blob/d2f9a4dd588a1a9e6349c8bc4f0694e0d1130ab6/src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs) I'm not sure if this is even possible - a comment in the source code says 'Since unloading an AssemblyLoadContext is not yet implemented...'

Even if it's not possible, it'd be great if the docs could state that it wasn't possible. There's not a lot of info around for AssemblyLoadContext and some of it is contradictory.

Also, if it's not possible, how does Kestrel do this? I struggled finding that bit in Kestrel's source code so if you've any pointers I'd appreciate them.

Many thanks!

@gkhanna79
Copy link
Member

Correct - the runtime/ALC implementation does not support it. I have been a little behind in the doc but will ensure it is called out there as well.

I am not sure about Kestrel - can you point me to it?

@OpinionatedGeek
Copy link

Hi,

Thanks for that.

Kestrel's just the default web server when I do dotnetcore+MVC development on OS X, and I think it recompiles and reloads pages when they change which is sortof what I'm aiming for.

The code starts at: https://github.com/aspnet/KestrelHttpServer but it may be part of MVC that does the reloading.

Many thanks - I look forward to reading the docs when they're available!

@davidfowl
Copy link
Member

Kestrel doesn't unload anything. MVC (which sits on top) has a view engine (Razor) that compiles views on the fly. https://github.com/aspnet/Mvc/blob/7ce344270a63f6cb397c1ef9829e5c54e7c171ed/src/Microsoft.AspNetCore.Mvc.Razor/Internal/DefaultRoslynCompilationService.cs#L183

No magic 😄

@OpinionatedGeek
Copy link

Ah well - I was kinda hoping for some magic here!

Many thanks.

@Ninds
Copy link

Ninds commented Oct 7, 2016

Hi,
Where can we find the doc ?

Rgds
N

@jaredpar
Copy link
Member

Any updates on this? Trying to do some work in this area and can't find a lot of documentation on it.

@Ninds
Copy link

Ninds commented Feb 2, 2017

Hi ,
Can someone comment on this topic given the latest developments in .NET Core ?
Has the documentation project been discontinued ?

@agocke
Copy link
Member

agocke commented Mar 15, 2017

@jkotas @gkhanna79 I'm currently trying to implement AppDomain-like functionality using AssemblyLoadContext and would really appreciate some documentation on it.

Specifically, it would really help to know:

  1. If a type in the TPAs gets loaded in multiple LoadContexts is the JIT'd code shared between them?

  2. Are statics always shared across AppContexts?

  3. Assuming (2) is true, is it safe to lock a static for synchronization across AssemblyLoadContexts?

@agocke
Copy link
Member

agocke commented Mar 16, 2017

Also, it appears that Assembly.LoadFromStream doesn't support netmodules. Is there any other way to load a netmodule from a byte[]?

@jkotas
Copy link
Member Author

jkotas commented Mar 16, 2017

.NET Core as a whole does not support netmodules.

@gkhanna79
Copy link
Member

Please see dotnet/coreclr#10271

@agocke
Copy link
Member

agocke commented Mar 17, 2017

@gkhanna79 This is great, thanks!

@ro-jo
Copy link

ro-jo commented Feb 27, 2018

When I search Bing for AssemblyLoadContext documentation, it leads me to this page. I read through the whole post looking for a link to some documentation, maybe I missed it. Anyway, without a search engine I found this page:

https://docs.microsoft.com/en-gb/dotnet/api/system.runtime.loader.assemblyloadcontext?view=netcore-2.0

Can anyone please confirm if that's the documentation you've been referring to? Is it the total of all documentation produced on AssemblyLoadContext since June 2016?

@gkhanna79 do you have another link to the real documentation?

Thanks.

@svick
Copy link
Contributor

svick commented Feb 27, 2018

@ro-jo The Pull Request referenced by @gkhanna79 created this document. Did you look at that?

@ro-jo
Copy link

ro-jo commented Feb 27, 2018

@svick err... nope, but thanks. Might have seen it briefly in my search and skipped over it, since it doesn't use the term 'AssemblyLoadContext' ubiquitously. Hardly at all actually. I wouldn't have thought it was describing AssemblyLoadContext if you hadn't told me.

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 30, 2020
@msftgits msftgits added this to the Future milestone Jan 30, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-AssemblyLoader-coreclr documentation Documentation bug or enhancement, does not impact product or test code
Projects
None yet
Development

No branches or pull requests

10 participants