kain64b
kain64b

Reputation: 2326

MsiInstallProduct throw NullReferenceException on window 2016

I'm getting strange error:

ERROR:System.NullReferenceException: Object reference not set to an instance of an object.
   at WindowsInstaller.MsiInterop.MsiInstallProduct(String product, String commandLine)
   at msicontroller.Program.Main(String[] arg

declaration:

[DllImport(MSI_LIB, CharSet = CharSet.Auto,  SetLastError=true)]
    extern static public MsiError   MsiInstallProduct(string product, string commandLine);

i get this error on 1 pc only, pc is win server 2016

Upvotes: 0

Views: 291

Answers (1)

Stein Åsmul
Stein Åsmul

Reputation: 42206

UPDATE (for community): If you insist on doing the platform invokes directly, you can still benefit from DTF mentioned below since the DTF source code is available on github.com. You can see how the platform invokes / COM interops are done there.


DTF: It would be easier for you to use DTF (Deployment Tools Foundation) for this. This is a component / set of assemblies that is part of the WiX toolkit now and it takes care of all the platform invokes for you so you can use the MSI API as a regular managed API (thereabouts). In other words DTF is essentially a .NET wrapper for the Win32 Windows Installer API.

DTF Sample (from this answer, section 6):

using Microsoft.Deployment.WindowsInstaller;

public static void Uninstall( string productCode)
{
  Installer.ConfigureProduct(productCode, 0, InstallState.Absent, "REBOOT=\"R\"");
}

Procedure: Download the WiX toolset, install and add a reference in your Visual Studio project to the Microsoft.Deployment.WindowsInstaller.dll file and deploy this along with your other release files. Or, if this is for a Windows Installer custom action: wrap in your custom action project. Templates in WiX available for this once you install the Visual Studio integration - separate download from same link above. Essentially it should happen auto-magically on build I think. The deal is that the managed DLL (assembly) is converted during build to a native wrapper DLL which contains the required files to run the custom action.


Some Further Links:

Upvotes: 1

Related Questions