{"id":390,"date":"2023-11-20T14:03:02","date_gmt":"2023-11-20T06:03:02","guid":{"rendered":"https:\/\/live-d365fo.pantheonsite.io\/?p=390"},"modified":"2023-11-30T10:30:01","modified_gmt":"2023-11-30T02:30:01","slug":"working-with-clr-exceptions-in-dynamics-ax","status":"publish","type":"post","link":"https:\/\/dev-d365fo.pantheonsite.io\/working-with-clr-exceptions-in-dynamics-ax\/","title":{"rendered":"\u5982\u4f55\u5728 DynamicsAX \u4e2d\u5904\u7406CLR\u5bf9\u8c61\u62a5\u9519\u7684\u95ee\u9898\uff08Working-with-CLR-exceptions-in-Dynamics AX\uff09"},"content":{"rendered":"\n
\u5728 Dynamics AX \u4e2d \u65e0\u8bba\u7248\u672c\u662f2009\u8fd8\u662f2012\u6216\u8005D365\uff0c\u603b\u662f\u4f1a\u9047\u5230\u4e0b\u9762\u8fd9\u4e24\u4e2a\u62a5\u9519\uff1a<\/p>\n\n\n\n
\u800c\u4e14\u7cfb\u7edf\u7ed9\u51fa\u7684\u65e5\u5fd7\u5b9e\u5728\u662f\u592a\u7b80\u77ed\u4e86\uff0c\u8ba9\u4eba\u6478\u4e0d\u7740\u5934\u8111\u3002\u4e0d\u8fc7\u4e00\u822c\u51fa\u73b0\u8fd9\u4e24\u4e2a\u95ee\u9898\u90fd\u662f\u5728AX\u4e2d\u5904\u7406 .net \u76f8\u5173\u7684 dll \u6216\u8005\u5728\u8c03\u7528 web service\u3001WCF\u3002\u90a3\u4e48\u5269\u4e0b\u7684\u95ee\u9898\u5c31\u662f\u6211\u4eec\u8be5\u600e\u4e48\u6837\u5f97\u77e5\u5728\u8c03\u7528 .net \u6846\u67b6\u7684\u65f6\u5019\u7a76\u7adf\u51fa\u4e86\u4ec0\u4e48\u95ee\u9898\u5462\uff0c\u4e00\u65e6\u77e5\u9053\u4e86\u5177\u4f53\u539f\u56e0\u5c31\u597d\u529e\u4e86\u3002<\/p>\n\n\n\n
\u597d\uff0c\u90a3\u6211\u4eec\u901a\u8fc7\u4e00\u4e2a Job \u6f14\u793a\u4e00\u4e0b\u5427\uff1a<\/p>\n\n\n\n
\nstatic void RaiseCLRException(Args _args)\n{\n ;\n \/\/Necessary if executed on the AOS\n new InteropPermission(InteropKind::ClrInterop).assert(); \n\n try\n {\n \/\/This will cause an exception\n System.Int32::Parse(\"abc\");\n }\n catch(Exception::CLRError)\n {\n \/\/Access the last CLR Exception\n info(CLRInterop::getLastException().ToString());\n\n \/\/See AifUtil::getClrErrorMessage for another alternative\n \/\/how to parse the Exception object \n\n }\n \/\/Revert CAS back to normal\n CodeAccessPermission::revertAssert();\n}\n<\/pre>\n\n\n\n\u6267\u884c\u4e0a\u9762\u4ee3\u7801\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u5982\u4e0b\u4fe1\u606f\uff1a<\/p>\n\n\n\n
\nSystem.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. \u2014> **System.FormatException: Input string was not in a correct format.**\n at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)\n at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)\n at System.Int32.Parse(String s)\n \u2014 End of inner exception stack trace \u2014\n at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)\n at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)\n at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)\n at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)\n at ClrBridgeImpl.InvokeClrStaticMethod(ClrBridgeImpl* , Char* pszClassName, Char* pszMethodName, Char* assemblyName, Int32 argsLength, ObjectWrapper** arguments, Boolean* argsAreByRef, Boolean* isException)\n<\/pre>\n\n\n\n<\/p>\n\n\n\n
\n=> The part System.FormatException: Input string was not in a correct format.<\/em><\/strong><\/p>\n<\/blockquote>\n\n\n\n\u4ece\u8fd9\u4e00\u6bb5\u5c31\u53ef\u4ee5\u770b\u51fa\u5230\u5e95\u662f\u54ea\u91cc\u51fa\u95ee\u9898\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
CLR\u5bf9\u8c61\u62a5\u9519 \u5728 Dynamics AX \u4e2d \u65e0\u8bba\u7248\u672c\u662f2009\u8fd8\u662f2012\u6216\u8005D365\uff0c\u603b\u662f\u4f1a\u9047\u5230\u4e0b\u9762\u8fd9\u4e24\u4e2a\u62a5\u9519\uff1a \u800c\u4e14\u7cfb\u7edf\u7ed9\u51fa\u7684\u65e5\u5fd7\u5b9e\u5728\u662f\u592a\u7b80\u77ed\u4e86\uff0c\u8ba9\u4eba\u6478\u4e0d\u7740\u5934\u8111\u3002\u4e0d\u8fc7\u4e00\u822c\u51fa\u73b0\u8fd9\u4e24\u4e2a\u95ee\u9898\u90fd\u662f\u5728AX\u4e2d\u5904\u7406 .net \u76f8\u5173\u7684 dll \u6216\u8005\u5728\u8c03\u7528 web service\u3001WCF\u3002\u90a3\u4e48\u5269\u4e0b\u7684\u95ee\u9898\u5c31\u662f\u6211\u4eec\u8be5\u600e\u4e48\u6837\u5f97\u77e5\u5728\u8c03\u7528 .net \u6846\u67b6\u7684\u65f6\u5019\u7a76\u7adf\u51fa\u4e86\u4ec0\u4e48\u95ee\u9898\u5462\uff0c\u4e00\u65e6\u77e5\u9053\u4e86\u5177\u4f53\u539f\u56e0\u5c31\u597d\u529e\u4e86\u3002 \u597d\uff0c\u90a3\u6211\u4eec\u901a\u8fc7\u4e00\u4e2a Job \u6f14\u793a\u4e00\u4e0b\u5427\uff1a static void RaiseCLRException(Args _args) { ; \/\/Necessary if executed on the AOS new InteropPermission(InteropKind::ClrInterop).assert(); try { \/\/This will cause an exception System.Int32::Parse(“abc”); } catch(Exception::CLRError) { \/\/Access the last CLR Exception info(CLRInterop::getLastException().ToString()); \/\/See AifUtil::getClrErrorMessage for another alternative \/\/how …<\/p>\n