Skip to content

XmlSerializer does not work with collections in collectible ALC #100518

Open
@gnattu

Description

@gnattu

Description

The XmlSerializer in collectible ALC can use the direct types from the ALC fine, but if the type is wrapped inside a collection like List, then it will throw System.NotSupportedException: A non-collectible assembly may not reference a collectible assembly.

Reproduction Steps

Get this repo: https://github.com/uffebjorklund/AssemblyLoadContextBug

Change line 10 of https://github.com/uffebjorklund/AssemblyLoadContextBug/tree/master/Module/Foo.cs to use typeof(List<Bar>) instead of typeof(Bar)

Run CrashSample, see the System.NotSupportedException: A non-collectible assembly may not reference a collectible assembly.

Expected behavior

The context created successfully just like when using typeof(Bar).

Actual behavior

It throws with System.NotSupportedException: A non-collectible assembly may not reference a collectible assembly.

Regression?

No

Known Workarounds

The collection can be wrapped in another class so that it can be used with XmlSerializer

Configuration

dotnet 8
macOS 14
arm64
Not specific to this configuration

Other information

I'm not very sure if this is a bug or an intended behavior. But there is some use cases where we want to use a collection directly and not wrapping it with a class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions