​金蝶云星空自定义webapi开发调用报错解析原创
金蝶云社区-制造与产能
制造与产能
68人赞赏了该文章 540次浏览 未经作者许可,禁止转载编辑于2023年11月25日 20:26:02

自定义开发webapi,部署到服务器后客户端调用报错。

未能加载文件或程序集“XXXX.K3Clou”或它的某一个依赖项。系统找不到指定的文件。

XXXX指的是四位的开发商码。

程序集全名是XXXX.K3Cloud.Plugin,但是报错信息里面却做了截断,只有11位长度(XXXX.K3Clou)。

金蝶云星空版本8.0.202301

看起来是金蝶云自身对自定义webapi插件的程序集名称长度做了限制11位字符串。

那么深究其原因

根据报错中的堆栈明细查看源代码

Kingdee.BOS.ServiceFacade.KDServiceFx.ServiceTypeManager.ReflectServiceType

public static ServiceType ReflectServiceType(string svcFullName)

        {

            if (string.IsNullOrEmpty(svcFullName))

            {

                throw new ArgumentNullException("ServiceName");

            }

            string text = ".common.kdsvc";

            int num = svcFullName.IndexOf(',');

            string text2 = string.Empty;

            string[] array;

            if (num > 0)

            {

                text2 = svcFullName.Replace(text, "").Substring(num + 1);

                array = svcFullName.Substring(0, num).Split(new char[]

                {

                    '.'

                });

            }

            else

            {

                array = svcFullName.Replace(text, "").Split(new char[]

                {

                    '.'

                });

            }

            if (array.Length <= 2)

            {

                throw new ArgumentException("ServiceName");

            }

            string text3 = "ServicesStub";

            ServiceType serviceType;

            try

            {

                int num2 = array.Length;

                string text4 = array[num2 - 1];

                string text5 = array[num2 - 2];

                string text6 = string.Empty;

                if (text2.Length == 0)

                {

                    text6 = svcFullName.Substring(0svcFullName.Length - text5.Length - text4.Length - 2 - text.Length);

                }

                else

                {

                    text6 = svcFullName.Substring(0svcFullName.Length - text5.Length - text4.Length - 3 - text2.Length - text.Length);

                }

                if (!ServiceTypeManager.svcTypeCache.TryGetValue(svcFullNameout serviceType))

                {

                    if (text2.Length == 0)

                    {

                        text2 = text6.Substring(0, text6.IndexOf(text3) + text3.Length);

                    }

                    serviceType = ServiceTypeManager.BuildServiceType(text2, text6, text5, text4);

                    ServiceTypeManager.svcTypeCache.TryAdd(svcFullName, serviceType);

                }

            }

            catch (ServiceException ex)

            {

                throw ex;

            }

            catch (Exception innerEx)

            {

                throw ServiceExceptions.Http500(string.Format(ResManager.LoadKDString("服务类型未找到。服务桩程序集必须以{0}结尾,所有对象必须基于程序集名称作为起始命名空间名称""002514030015535"SubSystemType.BOSnew object[0]), text3), innerEx);

            }

            return serviceType;

        }

引发限制程序集只能11位长度的源代码找到了

------------------------------------------------------

string text3 = "ServicesStub";

if (text2.Length == 0)

                    {

                        text2 = text6.Substring(0, text6.IndexOf(text3) + text3.Length);

                    }

 

------------------------------------------------------

就是这一段代码的逻辑,预设逻辑需要程序集命名以ServicesStub结尾就不会出现强制要求程序集名称字符串11位长度了!


赞 68