2012年12月23日 星期日

Issue of DISM.exe in Windows Deployment

DISM(Deployment Image Servicing and Management) is a image tools from Microsoft, it can apply, capture or other operations like add packages and features to create or modify Windows image even didn't  using the default of Windows setup process to install their operation system.

But it still has some issue about the DISM of Windows 8 and WindowsPE 4.0 environment, maybe it is a bug of DISM tool, or there're still having some issue from the newest operation system of Microsoft.

The issue was that when we want to add packages to the image, likes applies language packs, hotfix or the metro style apps to some specific images. Then using command parameters /LogLevel and /LogPath to export DISM working log for tracing event. The operation result is successful but still has some unreadable logs in logging files.

Originally there works fine in the previous image just only applies language packs, until found side effect in applying hotfix and metro apps to specific images. it makes some in-box drivers to unsigned status that we can not passing check logo requirement of Microsoft.

After doing some testing, we found the workaround was removes the /LogLevel and /LogPath command parameters can solving this issue.

Maybe there still has other side effects just we don't know yet....

2012年12月18日 星期二

Tips of Windows Runtime Component

Different with .NET dll, the Windows Runtime Component has some limitations when we want to build it using managed code. Here is something talking about creating Windows Runtime Component in managed code from MSDN.

In the section of Declaring types in Windows Runtime Components, we can know Windows Runtime only allowed Windows Runtime types for returned type of public method in the component, and something we should notice that the implementation of component. Following sample code may be help us knowing more easily.

 public sealed class WinRTClass  
 {  
   private List<string> _frusts;  
   public WinRTClass()  
   {  
     _frusts = new List<string> { "Apple", "Pear", "Strawberry", "Blueberry", "Plum" };  
   }  
   public List<string> GetFrusts()  
   {  
     return _frusts;  
   }  
 }  
This is very simple class for Windows Runtime Component, it has a private list to saving strings and a method to return that object. But it will show a compiler error when we build this project.
 Method 'testRTCompoment.WinRTClass.GetFrusts()' has a parameter of type 'System.Collections.Generic.List<System.String>' in its signature. Although this generic type is not a valid Windows Runtime type, the type or its generic parameters implement interfaces that are valid Windows Runtime types. Consider changing the type 'System.Collections.Generic.List<T>' in the method signature to one of the following types instead: 'System.Collections.Generic.IList<T>, System.Collections.Generic.IReadOnlyList<T>, System.Collections.Generic.IEnumerable<T>'.  
It shows the return type List<T> in its signature, this generic type is not a valid Windows Runtime type.

Because of coding managed code in Windows Store app, the compiler (Visual Studio 2012) will enumerate .NET framework types to Windows Runtime types in compiling phase, likes IList<T> will be transfer to IEnumerable<T> automatically. So we can use .NET framework type to coding Windows Store app, but can not use them for component return type to other applications.

We can modify the return type to IEnumerable<T> to commit the requirement of Windows Runtime.
  public sealed class WinRTClass   
  {   
   private List<string> _frusts;   
   public WinRTClass()   
   {   
    _frusts = new List<string> { "Apple", "Pear", "Strawberry", "Blueberry", "Plum" };   
   }   
   public IEnumerable<string> GetEnumFrusts()  
   {  
     return _frusts;  
   }  
  }   

In another sample, we want to use asynchronous task for return type in functional method. But the reason is same of List<T>, the Task<T> is also a .NET framework type not a valid Windows Runtime type.
So we can design the codes like.
 /// it will fail to compiling stage because Task<T> is not a valid Windows Runtime component  
 /*  
 public async Task<IEnumerable<string>> GetBerriesAsync()  
 {  
   return await Task.Run(() => _frusts.Where(x => x.Contains("berry")));  
 }  
 */  
 ///complies OK because it is private  
 private async Task<IEnumerable<string>> GetBerriesAsync()  
 {  
   return await Task.Run(() => _frusts.Where(x => x.Contains("berry")));  
 }  
 ///using WinRT type for accessing method to GetBerriesAsync()  
 public IAsyncOperation<IEnumerable<string>> GetBerriesAsyncOperation()  
 {  
   return GetBerriesAsync().AsAsyncOperation();  
 }  
In GetBerriesAsyncOpeartion method, it uses extension method of Task object which named AsAsyncOperation to enumerate IAsyncOperation.