Ibraim Ganiev
Ibraim Ganiev

Reputation: 9410

Assembly identity names in SxS manifests

I have two questions regarding activation context API and SxS manifests. They look like very simple, but still I cannot find any good answer for them.

I have two dll libraries with filenames foo.dll and bar.dll, both with embedded manifests, foo depends on bar. Is there any way to assign these two with assemblyIdentity name other than their filename? For example if I want assembly identity of bar.dll to be CompanyName.Subsection.bar ? If I change it's identity like this - I get error while I try to load foo.dll "Dependent Assembly CompanyName.Subsection.bar,type="win32",version="0.1.2.3" could not be found". Of course if I specify name assembly identities as filenames (<assemblyIdentity name="bar") everything works, but is there a way to use these dotted names?

foo.dll

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity name="foo" version="0.1.2.3" type="win32"/>
<dependency>
    <dependentAssembly>
        <assemblyIdentity name="CompanyName.Subsection.bar" version="0.1.2.3" type="win32" />
    </dependentAssembly>
</dependency>
<file name="foo.dll">
</file>
</assembly> 

bar.dll

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity name="CompanyName.Subsection.bar" version="0.1.2.3" type="win32"/>
<file name="bar.dll">
</file>
</assembly> 

Upvotes: 2

Views: 760

Answers (1)

It can be done if instead of embedding the manifest for bar.dll you place it in a separate folder together with the dll itself. I.e.:

foo.dll
CompanyName.Subsection.bar/
├── bar.dll
└── CompanyName.Subsection.bar.manifest

You still need to embed the first manifest into foo.dll. I'm confident that you can remove the following snippet from that manifest, because it's an embedded manifest and therefore needs not to specify what dlls belong to the assembly:

<file name="foo.dll">
</file>

The manifest for bar.dll is good, but be sure to name the folder and the manifest file exactly as specified in the assemblyIdentity element (see example folder structure above).

Also note, that you can diagnose problems related to loading SxS assemblies with the sxstrace command line tool. Step by step instructions:

  1. Run sxstrace trace -logfile:mytrace.etl from a Visual Studio Command Line. The command will not return until you press ENTER. However, do not press ENTER yet.
  2. Start the application that loads foo.dll to reproduce your issue
  3. Then press ENTER in the Command Line window to stop sxstrace
  4. You now have a file mytrace.etl, which is not human readable. Convert it to a readable format by running sxstrace parse -logfile:mytrace.etl -outfile:mytrace.txt. You get a file mytrace.txt which shows what happens, when you load foo.dll and where it fails to resolve some of its dependencies.

Upvotes: 1

Related Questions