Using Reflection in .NET Core

前端 未结 3 1648
悲&欢浪女
悲&欢浪女 2020-12-08 13:56

For cross-platform development, I\'m trying to make a .NET Core shared library. I used the Class Library (package) project template in VS 2015. My library nee

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 14:59

    Short Answer

    What am I doing wrong?

    You are trying to access members that are available in .NET 4.5.1 but not in 5.4.

    4.x                        Workaround in 5.x/Core
    
    Delegate.Method.           Delegate.GetMethodInfo()
    Type.BaseType.             Type.GetTypeInfo()
    Type.FilterName            -
    Type.InvokeMember          -
    Type.FindMembers           -
    

    Snip directly from Visual Studio.

    Visual Studio tells us this if we hover our mouse over the error.

    .NET Portability Report

    It is also worth looking at the .NET Portability Analyzer. It is an extension that we can install from the Visual Studio Gallery.

    Running it tells us, for instance, that Type.BaseType is not available and recommends a workaround.

提交回复
热议问题