none
IntelliTrace doesn't work properly once "ngen install ... /profile" is used

    Question

  • Hello,

    We're developing an application that greatly benefits from Profiled Native Images of .NET framework. Due to that, during our installation, we're running the following on several .NET assemblies:

    ngen install "ASSEMBLY NAME" /Profile

    Shortly after deploying our application, we've received a complaint that users' IntelliTrace feature in Visual Studio 2010 stopped working. After a short investigation we found that as soon as there is a Profiling Native Image of mscorlib.dll, IntelliTrace stops working. Also, when it happens, we get the following message in the Event Viewer: "The TraceLog Profiler detected an NGEN /profile assembly loaded into the process. Such assemblies are not supported. Collection will be disabled."
    This is especially troubling since mscorlib.dll is a dependency of any other .NET assembly, which means that using "ngen install ... /profile" on any assembly causes mscorlib.dll to be generated as well.
    Below is a simple reproduction of the issue:
    1. Create a new console application, set its target framework to .NET 2. Add code as appears in the image and set a breakpoint after SomeFunction.



    2. Set IntelliTrace to "IntelliTrace events and call information"
    3. Start debugging. Once the breakpoint is hit you should get the following, correctIntelliTrace:



    4. Stop debugging and exit Visual Studio.
    5. Open new cmd.exe in elevated mode
    6. Execute: 

      %windir%\Microsoft.NET\Framework\v2.0.50727\ngen install "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /Profile

    7. Start Visual Studio again and start debugging. The same breakpoint will be hit. This time, however, the IntelliTrace will look the following way:



    8. To make IntelliTrace run again in the same cmd window:

      %windir%\Microsoft.NET\Framework\v2.0.50727\ngen uninstall "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /Profile
    We've also tried to use /NoDependencies flag of ngen.exe to add only specific assemblies, without mscorlib, however, it seems that it the flag is ignored - Even though we've executed ngen install ... /Profile /NoDependencies, the dependencies are installed. Running ngen display | find "<profiling>" reveals that mscorlib is still installed even though /NoDependencies flag was used.
    Questions

    1. Is there a way to NGEN uninstall mscorlib /profile, even if there are other ngen /profile assemblies installed?
    2. Is there a workaround to make IntelliTrace work correctly after NGen /Profile is executed?
    3. Why doesn't the /NoDependencies flag work as expected?
    Thank you,
    Vitaly Belman
    • Moved by Paul Zhou Thursday, December 01, 2011 9:21 AM (From:Building Development and Diagnostic Tools for .Net)
    Wednesday, November 30, 2011 3:07 PM

Answers

  • Hi, Vitaly.

    I can give you some background on this, but unfortunately I have nothing to share that will really help the situation for you in the short-term.
     
    NGEN /Profile images create problems with IL-rewriting profilers, as the metadata from NGEN /Profile images cannot be modified.  As a result, Intellitrace is unable to continue if /Profile images are present because it cannot instrument them.  Unfortunately, there’s no way to tell the CLR to go back to JITting when /Profile images are present.  In our next release, we are enabling the ability to ignore even /Profile images and force JITting if desired.  So this should hopefully eliminate your problem at that time.  (You can generate /Profile images, and instrumenting profilers may opt into ignoring them when they run.)  But for now, I’m afraid your stuck.
     
    As for /NoDependencies...  That option is a bit of a misnomer.  It’s really just a hint to NGEN to ask it to try NGENing as few assemblies as possible, but doesn’t actually eliminate all dependencies from the list that will get NGENd.  In practice, you will always see mscorlib getting NGENd regardless of whether you specify /NoDependencies (assuming mscorlib had not yet been NGENd for that scenario).  Conversely, if a dependency is removed from the NGEN cache (like mscorlib), then all modules depending on it would have to be removed as well.

    Thanks,
    Dave

    • Marked as answer by CodeValue Ltd Tuesday, December 06, 2011 9:56 PM
    Tuesday, December 06, 2011 9:40 PM

All replies

  • Hi Vitaly,

    It seems that it is a little bizare.

    You can submit your suggestions to Microsoft Connect feedback portal http://connect.microsoft.com, Microsoft engineers will evaluate them seriously, thanks. 

    If this issue is urgent, please contact support at http://support.microsoft.com

     

    Thanks for your posting and understanding.

    Have a nice day.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Friday, December 02, 2011 8:26 AM
  • Hi, Vitaly.

    I can give you some background on this, but unfortunately I have nothing to share that will really help the situation for you in the short-term.
     
    NGEN /Profile images create problems with IL-rewriting profilers, as the metadata from NGEN /Profile images cannot be modified.  As a result, Intellitrace is unable to continue if /Profile images are present because it cannot instrument them.  Unfortunately, there’s no way to tell the CLR to go back to JITting when /Profile images are present.  In our next release, we are enabling the ability to ignore even /Profile images and force JITting if desired.  So this should hopefully eliminate your problem at that time.  (You can generate /Profile images, and instrumenting profilers may opt into ignoring them when they run.)  But for now, I’m afraid your stuck.
     
    As for /NoDependencies...  That option is a bit of a misnomer.  It’s really just a hint to NGEN to ask it to try NGENing as few assemblies as possible, but doesn’t actually eliminate all dependencies from the list that will get NGENd.  In practice, you will always see mscorlib getting NGENd regardless of whether you specify /NoDependencies (assuming mscorlib had not yet been NGENd for that scenario).  Conversely, if a dependency is removed from the NGEN cache (like mscorlib), then all modules depending on it would have to be removed as well.

    Thanks,
    Dave

    • Marked as answer by CodeValue Ltd Tuesday, December 06, 2011 9:56 PM
    Tuesday, December 06, 2011 9:40 PM