0

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

kain64b
  • 2,258
  • 2
  • 15
  • 27
  • Should have read the last line first - please remember that the below suggestions are also for others who find the Q/A, in case you find them irrelevant. What does the **MSI log** and the **event viewer** say? Did it work on other servers? Group policy settings? What kind of MSI file is it? Where is the file you try to install located? Can it be reached from that server? Did you try to install manually on the server? How many machines did you test on? – Stein Åsmul Nov 29 '18 at 01:53

1 Answers1

1

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:

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • 1
    OK, I forgot this link: [how to create a log file for an MSI installation](http://www.installsite.org/pages/en/msifaq/a/1022.htm). Just in case - and [quick hint for how to digest an MSI log file](http://robmensching.com/blog/posts/2010/8/2/the-first-thing-i-do-with-an-msi-log/). And if you go with DTF, remember to open the help file `DTF.chm`. Excellent help file. And pillage github for real-world examples. – Stein Åsmul Nov 29 '18 at 12:29