xamarin System.ArgumentException:在System.Reflection. MonoProperty中未找到“XXXXXXX”的Get方法

l5tcr1uw  于 2023-04-18  发布在  其他
关注(0)|答案(2)|浏览(146)

每当我试图通过reflection访问属性的值时,我都会得到这样的错误
“System.ArgumentException:在System.Reflection.MonoProperty.Get中未找到“XXXX”的Get方法
. Am使用Xamarin studio 6.3版本,属性也仅声明为public
型号:

using System;
namespace XXXX.Core
{
    public class ManufacturingParameters
    {
        public ManufacturingParameters()
        {
        }

        private int oemCode;
        public int OEMCode
        {
            get { return oemCode; }
            set { oemCode = value; }
        }
    }
}

Ex代码:

ValueString = deviceInfoContentVC.devInfo.manufacturingParameters.GetType().GetProperty(ParamSchema.Key).GetValue(deviceInfoContentVC.devInfo.manufacturingParameters).ToString();

上面的代码在Visual Studio中运行良好,但在xamarin Studio中却不行。
但是我可以通过下面的代码访问相同的属性:

ValueString = deviceInfoContentVC.devInfo.manufacturingParameters.oemCode.ToString();

因为我想动态访问它,我需要reflection类型的机制。
是否有其他解决方案/修复方法?
谢谢你。

hs1ihplo

hs1ihplo1#

终于解决了这个问题,这里是我找到的解决方案.
这是链接器剥离它。我已经改变了链接器的行为,以“链接框架SDK的唯一”从“链接所有”在iOS项目的设置,并在建立标题。
现在它的工作就像一个魅力。

63lcw9qa

63lcw9qa2#

Android Build Change:项目设置〉播放器〉优化〉托管剥离级别-将其设置为“最小”(不会删除任何用户编写的代码)。
https://docs.unity3d.com/Manual/ManagedCodeStripping.html

相关问题