Wixsharp: candle.exe : error CNDL0125 when building bootstrapper application from existing msi and add bootstrapper variable

Created on 24 Aug 2020  路  5Comments  路  Source: oleg-shilo/wixsharp

I got the following error when trying to build the bootstrapper application

candle.exe : error CNDL0125 : The extension 'Microsoft.Tools.WindowsInstallerXml.Extensions.BalCompiler' uses the same xml schema namespace, 'http://schemas.microsoft.com/wix/BalExtension', as previously loaded extension 'Microsoft.Tools.WindowsInstallerXml.Extensions.BalCompiler'. Please either remove one of the extensions or rename the xml schema namespace to avoid the collision.

The issue is reproducible from the WixBootstrapper project in the samples. The following sample codes is the (overly) simplified codes that demonstrate the issue.

```c#
// Runs OK when build msi on runtime.
//var productMsi = BuildMainMsi()

// Failed with error when using pre-built msi.
var productMsi = @"D:\My Product.msi"

var bootstrapper = new Bundle("My Product", new MsiPackage(productMsi));
bootstrapper.Version = Tasks.GetVersionFromFile(productMsi)
// Error won't occur when this is disabled.
bootstrapper.Variables = new[] { new Variable("Foo", "Bar") };

var setup = bootstrapper.Build("app_setup");
```

WixSharp version: 1.14.7.0

The difference is that when building the .msi during the runtime, bootstrapper application build successfully, but that's not the case when using a pre-built .msi file. In both cases, WixExtension.Bal is being included twice into the Bundle instance, once during the instantiation, the other during calls to Variable.Process() at Bundle.ToXml(). Both case generated the same .wxs and looks OK (no duplication of http://schemas.microsoft.com/wix/BalExtension).

Done / Released bug

Most helpful comment

Fixed. Will be available in the very next release. Aiming on this weekend.
The problem was caused by the Distinct algorithm failing in case of path containing environment variables:

```c#
// before
foreach (string dll in project.WixExtensions.Distinct())
extensionDlls += " -ext \"" + dll + "\"";

// after
foreach (string dll in project.WixExtensions.DistinctBy(x => x.ExpandEnvVars()))
extensionDlls += " -ext \"" + dll + "\"";
```

All 5 comments

Thank you for reporting it.
Will have a look.
But in a mean time, can you please see if problem exists if you generate and execute the build batch file with bootstrapper.BuildCmd(...). Most likely it does and you can address it by editing the cmd before the execution.

Problem still exists when executing the build batch file generated with bootstrapper.BuildCmd(...). Unfortunately I'm not familiar with wix command and not sure what to edit to make it work correctly.

Is there any info that I can provide to help investigate this issue?

Nothing comes to my mind.
My immediate impression is that the namespace is injected in the wxs twice. But you are saying the same xml can be build under different scenario.

Then may be the extension dll is passed to the candle twice. But you saw the cmd file.... I am guessing there is no duplication there neither.

Will need to look at it and give it some thinking.

OK, the problem is caused by the flaw in the candle command generation algorithm. If you execute bootstrapper.BuildCmd(...) you will see that the produced batch file has the line -ext "C:\Program Files (x86)\WiX Toolset v3.11\bin\WixBalExtension. injected twice.

Thus your work around until the fix is available it to edit the batch file by removing the duplicated extension and then execute the batch file manually.

In a mean time I will have a look at the actual cayuse of the problem.

Fixed. Will be available in the very next release. Aiming on this weekend.
The problem was caused by the Distinct algorithm failing in case of path containing environment variables:

```c#
// before
foreach (string dll in project.WixExtensions.Distinct())
extensionDlls += " -ext \"" + dll + "\"";

// after
foreach (string dll in project.WixExtensions.DistinctBy(x => x.ExpandEnvVars()))
extensionDlls += " -ext \"" + dll + "\"";
```

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mgkeeley picture mgkeeley  路  5Comments

ju2pom picture ju2pom  路  5Comments

meytes picture meytes  路  3Comments

Chrissyoung1223 picture Chrissyoung1223  路  5Comments

ltemimi picture ltemimi  路  5Comments