Skip to content

GetType() in base class constructor returns differently as in a plugin assembly, with its host program either normally compiled or published as single package. #110679

@xiaoyuvax

Description

@xiaoyuvax

Description

GetType() in base class constructor, when call from derived class, returns differently between runs as a dynamically loaded plugin when the host loading program is:

  1. normally compiled (that returns derived type) and ,
  2. published as a single package (that return basetype)?
    targeting net8, but compiled with net9 compiler in my case.

Reproduction Steps

write an assembly with following class to be built as a plugin:

        public class BaseClass
        {
            public string TypeName;

            public BaseClass()
            {
                TypeName = GetType().FullName;
            }
        }

        public class SubClass : BaseClass
        {
            public SubClass()
            {
            }

            /// <summary>
            /// This method behave and output differently from run compiled and published as single package.
            /// </summary>
            public void PrintMyTypeInfo()
            {
                Console.WriteLine(TypeName);   //<- outputs "SubClass" as as the host program run as normal compiled, but outputs "BaseClass"  when host program published as single package.
            }
        }

Load this plugin with above classes from the host program which is built as normlly or published as a single package, the output of PrintMyTypeInfo() are different.

Expected behavior

it should behave the same!

Actual behavior

output "SubClass" as run compiled but "BaseClass" as published single package, targeting net8.

Regression?

No response

Known Workarounds

Write Gettype() in constructors of all derived subclasses.

Configuration

targeting net8 but compiled by net9 compiler

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions