[UWP] MissingRuntimeArtifactException on type KeyValuePair while .net native tool chain enabled

Xiaoyi Liao 1 Reputation point
2021-04-07T12:56:16.19+00:00

I have the following code and works fine in release mode.

85298-20210407205836.png

I add project reference to Microsoft.Dynamic , Microsoft.Scripting.Metadata and Microsoft.Scripting that comes from IronPython2, even if I do not add any code to use the contents of these libraries, the function will trigger a MissingRuntimeArtifactException exception.

I tried the following operations, each of which can avoid the exception

  1. Modify KeyValuePair<,> type to Dictionary<,>
  2. Modify KeyValuePair<,> to class MyKeyValuePair<,>, notice the new type is class rather than struct
  3. Modify the function private static CallInstruction FastCreate(MethodInfo target, ParameterInfo[] pi) in file CallInstruction.Generated.cs in the library Microsoft.Dynamic, delete the internal implementation, and add single line "throw new Exception()"

I also tried the following operations, and each operation cannot avoid the exception

  1. Modify all the namesapce of the reference library, for example, modify Microsoft.xxx to AnyPrefix.Microsoft.xxx
  2. Modify the function name FastCreate that metioned above to FastCreate2
  3. Modify the class name CallInstruction to CallInstruction2
  4. Modify the parameters of the function FastCreate, and add the third parameter "int unused"
  5. Added a variety of possible content in Default.rd.xml, such as
    <Assembly Name="System.Private.Reflection.Core" Dynamic="Required All" Browse="Required All" />
    <TypeInstantiation Name="System.Func" Arguments="System.Object[],System.Object" Dynamic="Required All" />
    <TypeInstantiation Name="System.Collections.Generic.KeyValuePair" Arguments="System.Collections.IEnumerator, System.IDisposable" Dynamic="Required All" />
    <TypeInstantiation Name="System.Func" Arguments="System.Runtime.CompilerServices.CallSite, System.Object, System.Collections.Generic.KeyValuePair{System.Collections.IEnumerator, System.IDisposable}" Dynamic="Required All" / >
    <TypeInstantiation Name="System.Runtime.CompilerServices.CallSite" Arguments="System.Func{System.Runtime.CompilerServices.CallSite,System.Object,System.Collections.Generic.KeyValuePair{System.Collections.IEnumerator,System.IDisposable} }" Dynamic="Required All" />

The complete UWP sample project containing the library source code is at https://github.com/shuice/Microsoft.Dynamic_native_tool_chain/tree/master. The example project has two buttons, one button will crash and the other will not.

DjArt raised the issue of using IronPython2 in UWP. It took me 8 days and I can only follow up here.

Development environment

  1. IDE: Microsoft Visual Studio Community 2019 Version 16.9.3
  2. OS: Microsoft Windows 10 Home Version 10.0.19042
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
37,426 questions
0 comments No comments
{count} votes