TemplateText TT 在Runtime发生 Could not load type ...... because the format is invalid

Severity Code Description Project File Line Suppression State
Error Running transformation: System.TypeLoadException: Could not load type ‘TKTFRS.BondVarietyEx’ from assembly ‘TKTFRSCommonDataTypeLibrary, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null’ because the format is invalid.
at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
at System.Reflection.RuntimeMethodInfo.get_ReturnType()
at norlib.CommonHelper.GetAsyncMethods(Type arg_tpInterface) in E:\Projects\norlib.tt\Common.cs:line 40
at Microsoft.VisualStudio.TextTemplatingFBE6B5AC633D2EBF765C1C720C201C41C55150808C444DDC45A30A738B537D2C6396CF0B87B3F8DD688B7E5B8C42607BD3EFFEC8C03484E019EEDA5489CE5F1F.GeneratedTextTransformation.Async2Sync(Type arg_tpInterface)
at Microsoft.VisualStudio.TextTemplatingFBE6B5AC633D2EBF765C1C720C201C41C55150808C444DDC45A30A738B537D2C6396CF0B87B3F8DD688B7E5B8C42607BD3EFFEC8C03484E019EEDA5489CE5F1F.GeneratedTextTransformation.TransformText() IWindModuleClient_TKTFRS E:\Projects\TKTFRS\Server\IWindModuleClient_TKTFRS\helper.TKTFRS.sync.tt 1

在这个例子中我们是BondVarietyEx这个对象无法装载,这个特别奇怪。因为编译完全没有错误,.net 版本也正确, 也都是AnyCpu,

去掉含有BondVarietyEx的函数后再次跑tt则没有错误,说明有罪的就是BondVarietyEx, 仔细查看BondVarietyEx的声明:

  [Serializable]
    [StructLayout(LayoutKind.Sequential)]
    public class BondVarietyEx
        : BondVariety
    {
        public double 转换因子
        {
            get
            {
                return _cf;
            }
            set
            {
                _cf = value;
            }
        }
        public static BondVarietyEx FromBondVariety(BondVariety arg_BondVariety, double arg_d转换因子)
        {
           ........
        }

        double _cf;
    }

发现[StructLayout(LayoutKind.Sequential)], 但是其基类BondVariety已经放弃了这个Attribute, 因为无法做到定长, 但是衍生类却声明为定长, 难道是这个错误?

去掉此Attribute后一切OK~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值