[UWP] MissingRuntimeArtifactException on type KeyValuePair while .net native tool chain enabled
I have the following code and works fine in release mode.
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
- Modify
KeyValuePair<,>
type toDictionary<,>
- Modify
KeyValuePair<,>
to classMyKeyValuePair<,>
, notice the new type is class rather than struct - Modify the function
private static CallInstruction FastCreate(MethodInfo target, ParameterInfo[] pi)
in fileCallInstruction.Generated.cs
in the libraryMicrosoft.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
- Modify all the namesapce of the reference library, for example, modify
Microsoft.xxx
toAnyPrefix.Microsoft.xxx
- Modify the function name
FastCreate
that metioned above toFastCreate2
- Modify the class name
CallInstruction
toCallInstruction2
- Modify the parameters of the function
FastCreate
, and add the third parameter "int unused
" - 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
- IDE: Microsoft Visual Studio Community 2019 Version 16.9.3
- OS: Microsoft Windows 10 Home Version 10.0.19042