. Net Native Series III:. NET Native deployment test scheme and example

Source: Internet
Author: User

Previous Article 《The performance of c ++, the capacity of c ?! The fish and the bear's paw can have both. net native's first lookI have received support and encouragement from many friends, and I am also a strong promoter of this technology. I hope that more friends can understand this technology, so I will start with the translation of official information.

This series is the original school translation of xiaojiu. It is translated from Microsoft's Official Development Guide and is divided into six themes. This article isThird topic:. NET Native deployment test and example.

 

Wizard link :《C ++ performance C # capacity ?! -. Net Native series: Development wizard"

 

  [Xiao JIU's school is dedicated to describing extraordinary technologies in ordinary languages. If you want to reprint it, please indicate the source: xiaojiu's school. Cnblogs.com/xfuture]

 

 

  Original article:. NET Native Getting Started

 . NET Native deployment test and example

. NET Framework 4.5

    

Tips

This topic depends on the pre-release. net native Developer Preview. : Microsoft Connect website. You are prompted to register the website ..

  

Development process step 2. NET Native development process details

Deployment and testing:

  

When the development process ends, the. Net Native Tools configuration is successful, and the runtime command file is updated, you can start reconstruction and deployment to test your application .. Net Native binary files are placed in the ILC. out subdirectory of the generated output directory of the Project property configuration. If this folder does not exist, it indicates that the project has not been successfully compiled by. Net Native.

. Net Native currently supports x64 and arm frameworks, so you can only deploy the application to the corresponding device. Then you need to test and solve the fault on the device.

If your application cannot run normally (especially when a MissingMetadataException or MissingInteropDataException exception is thrown), follow the following content to manually solve the metadata exception. Starting the First-chance exception (the program is caught and continues to run) can help you find these buckets.

After testing and debugging errors, you should test some performance optimization conditions after you have properly handled the above exceptions. To test the performance, you must change the project build from debug to release to test its release version.

 

Common problems:

The most common problem with. net native is MissingMetadataException. This exception may cause unpredictable behavior or even collapse of the program. This section describes how to debug and solve this type of exception by adding commands at runtime. For information about the running command format, see Runtime Directives (rd. xml) Configuration File Reference. after you add a Good Luck line command, you can deploy and test your application and solve metadata-related exceptions.

Note: Adding commands should not change the underlying code, but should be processed in a higher level. We recommend that you add commands at the beginning of the namespace or type, instead of each code segment. After commands are added, the Compilation Time of the machine code project also increases.

When handling metadata loss exceptions, consider the following:

 

   1. What did the application do to cause this exception?For example, is it data binding? Or get data through serialization and deserialization? Or reflection?

    2. Is this exception common?For example, if this exception occurs when an object is serialized, you need to check and test each serialized part.

 3. Use reflection as few as possible.Refactor the code and change the mechanism of the reflected part as much as possible.

 

Example of problems encountered during the test:

  

Example: Handling Exceptions When Binding Data

In this example, A. Net Native project encounters a MissingMetadataException when binding data. The exception information is as follows:

    

    This operation cannot be carried out as metadata for the following type was removed for performance reasons: App.ViewModels.MainPageVM

The following is the stack call information:

Reflection::Execution::ReflectionDomainSetupImplementation.CreateNonInvokabilityException+0x238Reflection::Core::ReflectionDomain.CreateNonInvokabilityException+0x2eReflection::Core::Execution::ExecutionEnvironment.+0x316System::Reflection::Runtime::PropertyInfos::RuntimePropertyInfo.GetValue+0x1cbSystem::Reflection::PropertyInfo.GetValue+0x22System::Runtime::InteropServices::WindowsRuntime::CustomPropertyImpl.GetValue+0x42App!$66_Interop::McgNative.Func_IInspectable_IInspectable+0x158App!$66_Interop::McgNative::__vtable_Windows_UI_Xaml_Data__ICustomProperty.GetValue__STUB+0x46Windows_UI_Xaml!DirectUI::PropertyProviderPropertyAccess::GetValue+0x3f Windows_UI_Xaml!DirectUI::PropertyAccessPathStep::GetValue+0x31 Windows_UI_Xaml!DirectUI::PropertyPathListener::ConnectPathStep+0x113

This application is a WPF program. The spatial element (View) in Xaml obtains the value of the context data carrier (ViewModel) attribute through binding and PropertyInfo. GetValue. However, the metadata of this attribute is lost, so an exception is reported.

 Solution:

    Step 1Set this object to be serializable to ensure it is accessible:

    

<Type Name="App.ViewModels.MainPageVM" Serialize="Required Public" />

 Step 2Consider whether it is a common problem. In this example, all viewmodels have this problem, so you should not modify only one place at a time and continue debugging. Because all viewmodels are in app. viewmodels, you can perform the following settings:

    

<Namespace Name="App.ViewModels " Serialize="Required Public" />

Because data binding is based on reflection, you cannot change the code to avoid reflection. However, there are some ways to associate the view with the viewmodel during compilation, without relying on the runtime to save the metadata. For example, you can set the Windows. UI. Xaml. Data. BindableAttribute attribute, which will enable the compiler to associate context during compilation and avoid using Default. rd. xml serialization during runtime to get metadata.

For more information about rd. xml, see Runtime Directives (rd. xml) Configuration File Reference.

 

 

You may encounter more problems during development. You can ask questions at the MSDN forum.

 

To view the first several articles in this series, click:Wizard

    

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.