X++ to CIL

来源:互联网 发布:数据库事务详解 编辑:程序博客网 时间:2024/06/07 05:36


Dynamics AX 2012 is able to generate Common Intermediate Language from X++. That allows much more code running in Common Language Runtime and also switching between X++ runtime and CLR can be greatly reduced, both having positive impact on performance.

Many developers see it as a bit of black magic, which sometimes causes avoidable difficulties. That’s why I would like to share few findings. This article describes some basic terms and where the CIL code generated from X++ is stored. Later I want to write more about the actual translation from X++ to CIL.

CIL

CIL (Common Intermediate Language), formerly known as MSIL (Microsoft Intermediate Language) or sometimes simplyIL is a low-level language used by .NET Framework (and Mono). The runtime (CLR) doesn’t work directly with high-level languages like C#, it works with CIL and compilers of high-level languages simply generate CIL. The runtime handles CIL in the same way regardless it was generated from C#, Visual Basic, IronPython… or from X++.

When a piece of CIL code is used for the first time, CLR optimize it for the particular processor a compiles it to native code.

Generating CIL from X++

Some X++ code is run as CIL by default (batch jobs, web services) and you can explicitly run other X++ code in CIL too (seeX++ Compiled to .NET CIL). It’s always server-side code – the generated CIL is not available on client. Not all X++ code can be transformed to CIL – only types (classes, tables and enums) are supported, the code mustn’t use runbuf() method and so on.

To generate CIL, you typically use Generate Incremental CIL or Generate Full CIL buttons in the development workspace.

Assemblies and modules

As any other CIL code, CIL generated from X++ is saved in an assembly. Assemblies are basic building blocks of .NET applications grouping types together, providing additional information (manifest), versioning and so on. They may take form of an executable file (.exe) or a class library (.dll).

But unlike most assemblies, the assembly generated from X++ code consists of a high number of files. The DLL file doesn’t contain any types – it merely refers to other files known as modules, and all these files together make up a single logical unit. The advantage of this approach is that a module is loaded only if any type from that module is needed. As you’ll see, there is a lot of code generated from X++, so it makes a big difference if only a small part of it must be loaded.

Dynamics.Ax.Application

The assembly with CIL code generated from X++ can be found in bin\XppIL folder on AOS (for examplec:\Program Files\Microsoft Dynamics AX\60\Server\MyAos\bin\XppIL). It consists of these files:

FileDescriptionDynamics.Ax.Application.dllContains links to modules and information about where to find particular types.Enums.netmoduleContains CIL enums generated from X++ enums.InterfaceTypes.netmoduleContains interface types (e.g. Enumerable).KernelTypes.netmoduleContains types defined under System Documentation node in AOT. Note that some important types are already defined as CLR types in other assemblies and are not generated from X++.Dynamics.Ax.Application.dll{n}.netmodule
where {n} ∈ <0, 999>These modules contain all other X++ types (i.e. classes and tables, including table maps and views).The total size is about 200 MB, so it’s really important that we don’t have to load everything to memory.

Decompiling

One important advantage (and sometimes disadvantage) of CIL code it that it’s relatively readable and it can be decompiled back to high-level languages, which is great for examining existing code and learning how exactly it works. In this case, you can see how your X++ is translated to CIL (note that most of AX kernel is written in native code, so this doesn’t apply to it).

You can use IL Disassembler to get CIL code from assemblies. To decompile CIL back to C#, useReflector, for instance (unfortunately,  popular open-source program ILSpy doesn’t support multi-module assemblies).

To examine a specific type, you have to know in which module it can be found. One option is to look into the manifest in Dynamics.Ax.Application.dll – it contains references like this:

.class extern public Dynamics.Ax.Application.Dialog{    .file Dynamics.Ax.Application.dll11.netmodule    .class 0x02000025}

Use text search to find the requested type; you can see module name in the .file property.

Or you can follow the way used by AX for distributing types to modules. Take an object ID, divide it by 10, round it down, take last three digits, remove leading zeros and use this number in name of the .netmodule file. For example:AifExceptionMap table has ID 100029. After dividing by ten and rounding down, you get 10002. Last three digits are 002, thereforeAifExceptionMap can be found in Dynamics.Ax.Application.dll2.netmodule file. Of course, this is an implementation detail that may change at any time (the number of modules is even configurable), but knowing it surely can’t harm.


referance:

http://dev.goshoom.net/en/2013/03/x-to-cil/

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 苹果手机邮件无法连接服务器怎么办 好记星平板电脑开不了机怎么办 邮箱里的文件过期了怎么办 小米手机邮件发不了怎么办 有人加我qq邮箱怎么办 文件太大发邮件太慢怎么办 爱又米发信息怎么办 手机上电子邮件己停止运行怎么办 苹果电子邮件密码忘了怎么办 玩游戏时电脑烫怎么办 qq邮箱独立密码忘记了怎么办 qq邮箱中转站容量不足怎么办 qq邮箱忘记密码了怎么办 qq邮箱超大附件过期怎么办 忘记qq邮箱独立密码怎么办 网易邮箱账号忘了怎么办 微信登录密码忘了怎么办 微信太久没登录登录不上怎么办 邮箱独立密码忘记了怎么办 苹果设置id没有邮箱怎么办 苹果手机设置id没有邮箱怎么办 邮箱的附件过期了怎么办 邮箱里的附件过期了怎么办 邮箱中附件过期了怎么办 扣扣邮箱附件过期怎么办 公司网页版邮箱进不去了怎么办 农行客户端密码忘记了怎么办 中国银行客户端密码忘记了怎么办 建行客户端登录密码忘记了怎么办 中国移动客户端密码忘记了怎么办 再歪一点授权码绑定怎么办 网易邮箱号忘了怎么办 忘记支付宝账号和密码怎么办 支付宝账号密码忘了怎么办 发邮箱文件超2g怎么办 报考计算机二级邮箱不存在怎么办 苹果邮箱登录要imap密码怎么办 注销微信支付后怎么办 手机卡注销后支付宝怎么办 12306手机邮箱都换了怎么办 网易手机邮箱手机换了怎么办