.NET Framework Bookmark and Share   
 index > Common Language Runtime > NGen seems to ignore application manifest
 

NGen seems to ignore application manifest

Hi all,

I have solution containing both C# and C++ projects. Some of the assemblies created by these projects reference native assemblies that are installed in the C:\Windows\WinSxS folder. In order to specify which version of a native assembly to load the .exe file of the application contains an application manifest like this:

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Test1" version="1.0.0.0" processorArchitecture="x86" publicKeyToken="<public key token>"></assemblyIdentity>
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Test2" version="1.0.0.0" processorArchitecture="x86" publicKeyToken="<public key token>"></assemblyIdentity>
</dependentAssembly>
</dependency>
</asmv1:assembly>

The native assemblies Test1 and Test2 consist of multiple dlls and config files and are, as mentioned above, installed in the WinSxS folder. When I run the .exe file containing the above (embedded) application manifest everything works just fine, i.e. the application starts as expected and dlls are successfully loaded from the WinSxS folder (verified with Process Explorer).

Now I would like to use NGen to create native assemblies for my application. The problem is that NGen seems to ignore this embedded application manifest. I'm assuming this because NGen throws warnings that modules used by some of the .NET assemblies cannot be found:

Warning: System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E) while resolving 0x1000027 - <Name of assembly that references native assembly "Test1" or "Test2".

It doesn't matter whether I compile the application manifest into the .exe file (using the project properties of the project that creates the .exe file (in Visual Studio 2008)) or have it as a separate file (<name>.exe.manifest).

Of course it is also possible to include a manifest into each assembly that references a native assembly (Test1 or Test2). But actually I prefer having a list of all required native assemblies in the .exe file.

Does anyone know why NGen.exe ignores my application manifest? Can this behaviour be changed (command line switches, etc.)?

The application runs fine, it's only NGen that's causing headache.

Thanks!


ACKH
You'll have to convince MSFT devs to mend their ways. Do so by posting to connect.microsoft.com
Hans Passant.
nobugz
Ngen has support for this to a point with the /ExeConfig command line option. Of course, that won't work when you use a manifest.
Hans Passant.
nobugz
Thanks for your reply.

My first approach was to install all my managed assemblies into the GAC and have all unmanaged dlls in the directory that also contains the applications exe file. First we had the problem that when the managed assemblies are loaded the unmanaged dlls in the applications directory are not found. We solved this by programmatically adding that directory to the PATH variable of the application. This works fine, i.e. the application runs as expected. BUT we ran into troubles with NGen: Our installer that deploys the application (created using Windows Installer XML v3.0 with NGen custom actions) runs NGen at installation time. Because of that the unmanaged dlls will not be found because only the PATH variable of the application is changed which means NGen will not find the unmanaged dlls at installation time. There isn't much that the installer can do here. First I thought this can be solved using the /AppBase switch of NGen but as it turned out that switch only resolves managed dependencies. Setting it to the directory of the application (which also contains the unmanaged dlls) does not help, i.e. the unmanaged dlls are still not found.

Because of these troubles I tried to create native assemblies out of my unmanaged dlls
and reference the in the application manifest. As mentioned in my previous posting the application still runs as expected but again I get problems with NGen because it seems to simply ignore the application manifest. Because of that the unmanaged stuff in not found.

It seems that if you want to use NGen the only solution is to have everything (managed assemblies and unmanaged dlls) in the same directory. Otherwise NGen will simply not find the unmanaged dlls. Unfortunately the project I want to use NGen for is a framework that is used in several applications. Therefore I'm forced to install the framework into each application folder because I simply cannot install it into the Global Assembly Cache AND use NGen. This is very disappointing.

It might be nice for some people that the command line interface of NGen is very simple. However, from my point of view it is too simple because it severly limits the use of NGen. There should really be a switch that lets you specify directories containing unmanaged dependencies. In addition to that NGen should simply not ignore the application manifest.

It might be that I completely misunderstand something. In that case please correct me!

Thanks!

ACKH
You'll have to convince MSFT devs to mend their ways. Do so by posting to connect.microsoft.com
Hans Passant.
nobugz
Good idea, I will do so. Thanks for your help.
ACKH

You can use google to search for other answers

Custom Search

More Threads

• Help with locating a TableCell by access method
• OutOfMemoryException when allocating arbitrary sized arrays
• Assembly referencing - Multiple versions in the same app? GAG?
• ContextSwitchDeadlock, debugging CLR errors, addresses?
• System out of memory exception in a Thread
• Determining if an object is referenced by any pointer
• System.Security.SecurityPermission in an AppDomain in a ClickOnce deployment.
• Generic function without parameter
• as we have "&&" for "AND" how can I denote "ANDLSO"
• How to Calculate size of a Class in C#