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

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

Closed
xiaoyuvax opened this issue Dec 13, 2024 · 1 comment
Labels
needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Comments

@xiaoyuvax
Copy link

xiaoyuvax commented Dec 13, 2024

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

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Dec 13, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Dec 13, 2024
@xiaoyuvax xiaoyuvax changed the title GetType() in base class constructor returns differently between normally compiled and published as single package. GetType() in base class constructor returns differently as in a plugin assembly, with its host program either normally compiled or published as single package. Dec 13, 2024
@xiaoyuvax
Copy link
Author

Finally turns out to be caused by duel dependency on both compiled .dll and the source project, i don't the underlying cause, but the problem sovled by remove the .dll libs from dependencies!

@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners
Projects
None yet
Development

No branches or pull requests

1 participant