RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.
Your new application will encounter a MissingFieldException.
Use ILDAsm to examine the generated MSIL code for each of the assemblies from steps 2 and 4.
You will observe that in the emitted code, the data type of the array field in IL is "int32[,]", but for the compiled assembly, the type of the array field in IL is "int32[0...,0...]".
The two representations are functionally equivalent ways to express the two-dimensional array field with zero lower bounds. But if you have another assembly that was built with a reference to one of these assemblies, and try to replace it with the other, you will encounter a MissingFieldException.
Although the two fields are functionally equivalent, the compiler changes the field info string enough that the .NET Runtime thinks it hasn’t found a matching type, and cannot load the field. Thus, a MissingFieldException is thrown. Reflection.Emit generates a different signature than the C# compiler and the type loader rejects it because the two signatures don’t match. Note that C# was used in the example, but the same difference will be observed if VB.NET or another .NET language compiler is used.
Avoid using multidimensional arrays in classes where this anomaly might be a problem for you.
Microsoft has recognized this problem, and it is currently planned that a future release of the .NET Framework will include a System.Reflection.Emit namespace that will have corrected this.
The same problem will be observed if you try to emit overrides of inherited members of compiled types that use multidimensional array types, or if you try to emit implementations of compiled interface members that use multidimensional array types.
See also:
System.Reflection.Emit Namespace
(http://msdn.microsoft.com/en-us/library/system.reflection.emit.aspx)
MSIL Disassembler (Ildasm.exe)
(http://msdn.microsoft.com/en-us/library/f7dy01k1.aspx)
MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALSâ€) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.