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

Support loading ASP.NET Core into non-default load contexts #21159

Open
rynowak opened this issue Apr 23, 2020 · 7 comments
Open

Support loading ASP.NET Core into non-default load contexts #21159

rynowak opened this issue Apr 23, 2020 · 7 comments
Assignees
Labels
affected-very-few This issue impacts very few customers area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions feature-platform Deprecated: Cross-cutting issues related to ASP.NET Core as a platform investigate severity-minor This label is used by an internal tool unloadability The ability to unload from collectable AssemblyLoadContext
Milestone

Comments

@rynowak
Copy link
Member

rynowak commented Apr 23, 2020

Describe the solution you'd like

Users creating a module system that uses ASP.NET Core will run into problems if they are using a non-default AssemblyLoadContext. The reason is that we have various features that operate outside of a load context, usually by using LoadFile instead of one of the more context-aware methods.

Known features that don't support ALCs:

  • Loading related application parts (views/pages)
  • (possibly more)

Additional context

While we haven't totally ignored this as an area, it's not something we document and test. At a minimum completing this would would require identifying a few scenarios that are good as samples and documenting them. We have not done a full effort to ensure that ever part of ASP.NET Core will work in this mode.

Original source: filing a feature request based on a support ticket for an unsupported scenario.

@rynowak rynowak added the feature-platform Deprecated: Cross-cutting issues related to ASP.NET Core as a platform label Apr 23, 2020
@davidfowl
Copy link
Member

The good news is, using Assembly.Load is good using Assembly.LoadFrom/LoadFile isn't so good. We only have one place that does this in the product today so we're in pretty good shape so far.

@vitek-karas
Copy link
Member

Depending on what the overall feature should be Assembly.Load may be problematic as well.

Currently runtime doesn't support loading frameworks into isolated ALCs, so the typical use case is actually loading ASP.NET itself into default ALC (since it's a framework) and loading the app into a secondary ALC. This has been asked for several times, recently for example here: dotnet/runtime#37584. Scenarios I know of are for example:

  • Running multiple smaller apps in one process to save resources
  • Ability to reload an app without restarting process

In such case even Assembly.Load doesn't work well. It uses the ALC of the immediate caller, which is ASP.NET which lives in default ALC. So it will load whatever assembly it wants into the default ALC - even if the app was started from a secondary ALC.

It might be possible to workaround this by using AssemblyLoadContext.CurrentContextualReflectionContext which tells Assembly.Load which ALC to use. This would obviously need testing.

Also note that similar issues to Assembly.Load are with many other reflection APIs, like Type.GetType - see https://github.com/dotnet/coreclr/blob/master/Documentation/design-docs/AssemblyLoadContext.ContextualReflection.md#currently-affected-apis for the full list.

Ability to load ASP.NET itself into a secondary ALC is more complex. Not only it would likely require testing and other work on the ASP.NET side, but it's actually a rather non-trivial runtime feature. It's also unclear if this is the actual intent (Do we expect customers to run different versions of the ASP.NET framework inside one process?).

Yet another issue is unloadability - to correctly support the ability to reload an app without restarting the process not only the app has to run in a secondary ALC, but such ALC must be able to unload. Currently there are several issues in the core framework (Microsoft.NETCore.App) around this where different types of caches hold on to things regardless of ALCs (for example caches in TypeConverter - dotnet/runtime#30656). Similarly on ASP.NET side there's a discussion about it here: #21744.

@ghost
Copy link

ghost commented Oct 1, 2020

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@JunTaoLuo
Copy link
Contributor

Sounds like this issue will need investigation. Potentially for the next release.

@JunTaoLuo
Copy link
Contributor

@Pilchie looks like we might need someone to investigate what we want to do here, potentially for 6.0. Is there a higher level initiative to modules support across dotnet?

@davidfowl
Copy link
Member

We have a bunch of these issues around what happens when you try to use various parts of ASP.NET Core with AssemblyLoadContext. The goal is to spend some time understanding those scenarios so that we can make a better judgement call as to whether we want to do something about them.

Here's another example of an issue that came up with ALC in MVC #21744

@ghost
Copy link

ghost commented Aug 11, 2021

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 24, 2023
sunnycase added a commit to kendryte/nncase that referenced this issue Apr 7, 2024
* Add cpu module

* Fix build

* Pass unary

* Use custom pe loader

* Remove unused code

* Skip some tests cpu codegen doesn't support

* Add linux support

* Fix win

* Fix

* Fix macos

* Add pack

* Add macho loader

* Fix unary test

* fix call function

* Add -fno-stack-protector

* Fix find vs

* Add sinh cosh

* Add linear_size()

* Fix macos

* Add square

* Add sign

* Add ntt(nncase tensor template)

* Fix macos

* Fix macos

* Add rsqrt

* Import memcpy for gcc

* Disable lto

* Compile-time apply

* Add binary

* Setup ninja

* Fix build

* Fix build

* Fix slicing codegen

* Fix findvc

* Fix build

* Disable macos cpu module

* Add pow

* Link __chkstk on win32

* Avoid stackoverflow

* Optimize unary apply

* Fix build

* Update unary impl

* Fix build

* Add l2 fuse

* fix test

* Add missing parts

* Update

* Add AllocateBufferView

* Pass test simple unary

* add rewriter

* fix codegen

* fix elf loader

* fix mac build

* fix ci

* fix ci

* Move AffineMap

* Fix ut

* fix mac build

* Add Affine.Grid

* Start to code auto tiling

* refactor code

* pass packed layernorm

* add binary

* add binary test

* Try matmul tiling

* More generic cost

* Tiling: parameterize

* pass unittests

* format

* reverse cpu target

* add packed kernel

* add unary simd support

* Add grid auto tile

* fix ci

* fix mac build

* fix linux build

* fix packed matmul evaluator

* disable cnblogs source

* Chain the pipeline

* Add allocate buffer scope

* fix dotnet build

* add packing

* refactor vector type

* fix vector type

* fix cmake path

* add x86 pack unpack kernel

* Move auto tile to schedule proj

* Fix win build

* fix repeated AutoPacking

* fix mac build

* Add buffer subview

* Fix cmakelist template

* Fix win32 runtime build

* fix mac test

* add layer norm

* skip the failed case

* add layer norm case

* fix layernorm test

* pass packed layer norm

* fix mac build

* fix packed transpose vi

* add arm neon packed softmax

* add packed softmax

* fix mac ci

* add blame

* add 1d packed matmul

* disable pack test

* add packed matmul

* fix mac

* add packed matmul

* add more kernel

* refactor cpu kernels test

* fix some bug

* add copy

* fix ci

* fix mac build

* fix mac build

* add gather

* Add ranked_shape support for pack and some test cases.

* compile decode layer success

* Add ranked_shape support for unpack and some test cases.

* fix bug

* Support softmax axis != packed axis for packed_softmax.

* add  buffer schedule

* fix mac loader

* pass mac loader

* opt copy and matmul

* pass 65b decode layer

* fix ci

* Fix layer norm axis > pack axis and support broadcasting for scale/bias.

* add pad/fix bugs

* fix packed layer norm

* fix arm vector 4 reduce sum

* add packed layernorm case

* fix ci

* Remove unused deps

* Refactor ntt

* Fix

* fix linux ci

* Fix build

* Fix build on Ubuntu.

* Add aarch64 types

* fix mac build

* Fix build

* Fix load model with binary mode

* Use M1 runners

* Use python 3.10

* Use python 3.10

* Fix macos CI

* Remove halide

* Remove halide

* Skip TestDecodeLayer in CI

* Add ctest for ntt and fix unary bugs.

* Rename ctest files to avoid confliction.

* Fix msvc empty bases bug

* Fix build

* onnxoptimizer==0.2.7

* Update vulkan

* Update torch

* Update mac vulkan

* Remove caffe

* Update CI

* Upgrade packages

* Move setup python

* Fix win deps

* Remove omp

* debug

* Add floor_mod and ctest cases for ntt binary.

* Add bin to python search path

* Remove gsl

* Fix build

* Fix build

* Fix win test

* Disable F.InterpolationMode.BILINEAR

* Disable test_conv2d_transpose

* Disable test_expand_dims

* Disable test_fully_connected

* Disable test_conv2d_prelu

* Disable test_squeeze_transpose_shape

* Add x86_64 avx optimization and test cases for unary.

* Disable test_mobilenetv1

* Disable test_mobilenetv2

* Disable tflite_model test

* Disable ncnn test as ncnn pypi doesn't support arm64

* Disable test_pad_reduce_window2d and enable ncnn test

* Disable test_reduce_window2d

* Upgrade packages

* Downgrade Microsoft.CodeAnalysis.CSharp to 4.7.0

* Disable DOTNET_INIT_FOR_CONFIG as aspnet doesn't support non-default ACL dotnet/aspnetcore#21159

* Fix kernel tests

* All extract with null constrains

* Apply code-format changes

---------

Co-authored-by: 郑启航 <597323109@qq.com>
Co-authored-by: zhangyang2057 <zhangyang@canaan-creative.com>
Co-authored-by: sunnycase <sunnycase@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affected-very-few This issue impacts very few customers area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions feature-platform Deprecated: Cross-cutting issues related to ASP.NET Core as a platform investigate severity-minor This label is used by an internal tool unloadability The ability to unload from collectable AssemblyLoadContext
Projects
None yet
Development

No branches or pull requests

8 participants