Problem
I have a WPF Application that is referencing Microsoft.mshtml Primary Interop Assembly. I'm creating a native image of my app using NGen. I'm afraid the native image is never being loaded if I start my app.
Reproduction Info
E.g. create new WPF Application "WpfApplication1" in Visual Studio, add reference to "C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\Microsoft.mshtml.dll", set Embed Interop Types to false, set Specific Version to false and set Copy Local to true. Use some type of Microsoft.mshtml like instantiating mshtml.HTMLDocumentClass. After building the app, run NGen from "c:\Windows\Microsoft.NET\Framework\v4.0.30319" like this:
ngen install "%PATHTOMYAPPDIR%\WPFApplication1.exe" /NoDependencies
NGen does not show any errors. After having started my app, I'm verifying if the native image has been loaded by using vmmap or process explorer. Unfortunately none of them is showing the created native image.
Fusion log
So I've enabled the fusion log viewer and this is what it tells me:
* Assembly Binder Log Entry (3/13/2016 @ 11:30:48 AM) *
The operation was successful. Bind result: hr = 0x0. The operation completed successfully.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll Running under executable C:\Users\azureuser\Documents\visual studio 2015\Projects\WpfApplication1\WpfApplication1\bin\Release\WpfApplication1.exe
--- A detailed error log follows.LOG: Start validating all the dependencies.
LOG: [Level 1]Start validating native image dependency mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
LOG: [Level 1]Start validating IL dependency PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
LOG: [Level 1]Start validating IL dependency WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
LOG: [Level 1]Start validating IL dependency System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
LOG: [Level 1]Start validating IL dependency PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
LOG: [Level 1]Start validating native image dependency System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
LOG: [Level 2]Start validating native image dependency mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
LOG: [Level 2]Start validating IL dependency System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
LOG: [Level 2]Start validating IL dependency System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
Native image has correct version information.
LOG: [Level 1]Start validating IL dependency UIAutomationTypes, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
LOG: [Level 1]Start validating IL dependency Microsoft.mshtml, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
WRN: Cannot load IL assembly. (hr = 0x80131040).
WRN: No matching native image found.
LOG: IL assembly loaded from C:\Users\azureuser\Documents\visual studio 2015\Projects\WpfApplication1\WpfApplication1\bin\Release\WpfApplication1.exe.
Remarks
- If I remove the Microsoft.mshtml reference including the mshtml code, the native image is loaded as expected. So in general ngening works on my systems.
- I've tested this behaviour on three different OSs producing the same result: Windows 7 Ultimate, Windows Server 2012 Datacenter and Windows 10.
- Disabling load verification by running
sn.exe -Vr *,*
does not change the behaviour - As the Microsoft.mshtml that is actually loaded from GAC is slightly different from the one in "C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies" (different certificates), I also tried to directly reference the one in the GAC producing no different result
- Putting the one under "C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies" into the GAC by running
gacutil -if
does not work either - I built this app using VS2013 targeting .net 4.5 and VS2015 targeting .net 4.6