[wix-users] Deployment Tools Foundation: GetStream Method (fieldName)

Herman van Drie hvandrie at outlook.com
Mon Feb 6 14:14:34 PST 2017


Narrowed it down a little more, it's a permission problem...
A snippet from the log:

--------------------------------------
Action start 22:51:19: RunMyCa.
MSI (s) (74:30) [22:51:19:245]: Invoking remote custom action. DLL: C:\Windows\Installer\MSI3B4A.tmp, Entrypoint: MyCA
MSI (s) (74:A8) [22:51:19:245]: Generating random cookie.
MSI (s) (74:A8) [22:51:19:247]: Created Custom Action Server with PID 16100 (0x3EE4).
MSI (s) (74:58) [22:51:19:271]: Running as a service.
MSI (s) (74:58) [22:51:19:273]: Hello, I'm your 32bit Impersonated custom action server.
SFXCA: Extracting custom action to temporary directory: C:\Windows\Installer\MSI3B4A.tmp-\
SFXCA: Binding to CLR version v4.0.30319
Calling custom action MyCA!MyCA.CustomActions.MyCA
Begin WindowsUpdate Installer Custom Action
MSI (s) (74!30) [22:54:10:263]: Note: 1: 2263 2: Binary.MyXml 3: -2147287035 
Name = MyXml
Read stream into memory
Attempt to read stream
Exception error message = Object reference not set to an instance of an object.
Error code = -2147467261
Stack trace =    at MyCA.CustomActions.MyCA(Session session)
Data = System.Collections.ListDictionaryInternal
--------------------------------------

Windows Installer error 2263 = Could not open stream [2]. System error: [3].
-2147287035 = FFFFFFFF80030005 = access denied = permission problem...

Any ideas?


-----Original Message-----
From: wix-users [mailto:wix-users-bounces at lists.wixtoolset.org] On Behalf Of Herman van Drie
Sent: maandag 6 februari 2017 22:44
To: WiX Toolset Users Mailing List <wix-users at lists.wixtoolset.org>
Subject: Re: [wix-users] Deployment Tools Foundation: GetStream Method (fieldName)

Yes, attempted through both Orca and WiStream.vbs to load binary data into the field. Also extracted using Orca the data field to temporary file on disk, opened... data is exactly there.
No, like the docs (.chm) say... "Remarks: This method is not capable of reading substorages. To extract a substorage, use Microsoft.Deployment.WindowsInstaller.Record.GetStream(System.String,System.String)." 
However. Binary table isn't part of that... it's a stream.
Even when attempting to use GetStream(string, string) function, it doesn't work...

Also saw limitations on binary data streams: https://msdn.microsoft.com/en-us/library/windows/desktop/aa370551(v=vs.85).aspx
But is not relevant in my case as I am opening a different record and different streams as seen from CA executing (self-extracting) data stream perspective.

Also already attempted to read something else, ie something from the Binary table, no go... here a bit more context:

// ----------------------------------
	Microsoft.Deployment.WindowsInstaller.View MyRecordView = session.Database.OpenView("Select `Name`, `Data` from `Binary` where `Name` = 'MyXml'");

                MyRecordView.Execute();

                if (MyRecordView != null && MyRecordView.Count() > 0)
                {
                    Record MyRecord = MyRecordView.Fetch();

                    
                    while (MyRecord != null)
                    {

	          session.Log(String.Format("Name = {0}", MyRecord.GetString("Name")));   // works, we get a nice log entry showing string data of Name column

	          session.Log(String.Format("Read stream into memory"));
                        MemoryStream msMyPackageXml = new MemoryStream();

                        session.Log(String.Format("Attempt to read stream"));
                        int byteRead;
                        while ((byteRead = MyRecord.GetStream("Data").ReadByte()) != -1)    // < null reference exception :(
                            msMyPackageXml.WriteByte((byte)byteRead);

	    }
	}  	
// ----------------------------------


-----Original Message-----
From: wix-users [mailto:wix-users-bounces at lists.wixtoolset.org] On Behalf Of Hoover, Jacob
Sent: maandag 6 februari 2017 22:08
To: WiX Toolset Users Mailing List <wix-users at lists.wixtoolset.org>
Subject: Re: [wix-users] Deployment Tools Foundation: GetStream Method (fieldName)

Are you certain there is data in your table for that field? The only way DTF is going to return a null (as opposed to an exception) is if the field is null. Also, you aren't trying to read a substorage, are you?

       /// <summary>
        /// Gets a record stream field.
        /// </summary>
        /// <param name="field">Specifies the field of the Record to get.</param>
        /// <returns>A Stream that reads the field data.</returns>
        /// <exception cref="ArgumentOutOfRangeException">The field is less than 0 or greater than the
        /// number of fields in the Record.</exception>
        /// <remarks><p>
        /// This method is not capable of reading substorages. To extract a substorage,
        /// use <see cref="GetStream(int,string)"/>.
        /// </p><p>
        /// Win32 MSI API:
        /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msirecordreadstream.asp">MsiRecordReadStream</a>
        /// </p></remarks>
        public Stream GetStream(int field)
        {
            this.CheckRange(field);

            return this.IsNull(field) ? null : new RecordStream(this, field);
        }

        /// <summary>
        /// Reports whether a record field is null.
        /// </summary>
        /// <param name="field">Specifies the field to check.</param>
        /// <returns>True if the field is null, false otherwise.</returns>
        /// <exception cref="ArgumentOutOfRangeException">The field is less than 0 or greater than the
        /// number of fields in the Record.</exception>
        /// <remarks><p>
        /// Win32 MSI API:
        /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msirecordisnull.asp">MsiRecordIsNull</a>
        /// </p></remarks>
        public bool IsNull(int field)
        {
            this.CheckRange(field);
            return RemotableNativeMethods.MsiRecordIsNull((int) this.Handle, (uint) field);
        }


-----Original Message-----
From: wix-users [mailto:wix-users-bounces at lists.wixtoolset.org] On Behalf Of Herman van Drie
Sent: Monday, February 06, 2017 2:10 PM
To: WiX Toolset Users Mailing List <wix-users at lists.wixtoolset.org>
Subject: Re: [wix-users] Deployment Tools Foundation: GetStream Method (fieldName)

I did already.



Tried session.database, and also from within the CA to even open the database from sourcepath as readonly, doesn't make a difference.



Text fields in the record return correct string values. It's the binary data field that doesn't return anything.



The SQL query was simple: Select * from TableName.

Even tried different methods to get a Record object, it gets the string data but it's as if it can't acquire the data stream.



Using tue sdk wistreams vbscript I am able to see that the data streams exist in the database, it returns <table>.<primary key> value of the record for each stream. But just somehow impossible to read it from within CA. Tried different scheduling options as well as sequence order (before and after InstallInitialize)... doesn't matter.



Greetz,



Herman





From: Hoover, Jacob<mailto:Jacob.Hoover at greenheck.com>
Sent: maandag 6 februari 2017 19:33
To: WiX Toolset Users Mailing List<mailto:wix-users at lists.wixtoolset.org>
Subject: Re: [wix-users] Deployment Tools Foundation: GetStream Method (fieldName)





Not enough context...  What does your query look like? Also, try breaking apart the code a bit to find out which method is returning null.

-----Original Message-----
From: wix-users [mailto:wix-users-bounces at lists.wixtoolset.org] On Behalf Of Herman van Drie
Sent: Monday, February 06, 2017 11:01 AM
To: wix-users at lists.wixtoolset.org
Subject: [wix-users] Deployment Tools Foundation: GetStream Method (fieldName)

Hi,

I have created a CA using WiX C# CA project.
During execution of the CA, I am attempting to read a Stream from a field #3 (binary data column) in a custom table using Record GetStream function (within Microsoft.Deployment.WindowsInstaller namespace):

RecordView.Execute();
Record myRecord = MsuRecordView.Fetch();

while (myRecord != null)

               {
MemoryStream ms = new MemoryStream();
byte[] inputBuffer = new byte[65535];
int ReadAmount;
while ((ReadAmount = myRecord.GetStream(3).Read(inputBuffer, 0, inputBuffer.Length)) > 0)         // <-- exception occurs: "Object reference not set to an instance of an object."
{
session.Log(String.Format("Reading stream...")); ms.Write(inputBuffer, 0, ReadAmount); } }

However, whatever I do... also different methods, like CopyTo (MemoryStream) don't seem to be able to obtain an instance. I receive an "object reference not set to instance of an object" upon calling the Record.GetStream(fieldname/number).
I use ExecuteQuery to obtain multiple Records, and subsequenty parse each Record.

Any help is very appreciated!

Thanks,

Herman van Drie


____________________________________________________________________
WiX Toolset Users Mailing List provided by FireGiant http://www.firegiant.com/

____________________________________________________________________
WiX Toolset Users Mailing List provided by FireGiant http://www.firegiant.com/

____________________________________________________________________
WiX Toolset Users Mailing List provided by FireGiant http://www.firegiant.com/

____________________________________________________________________
WiX Toolset Users Mailing List provided by FireGiant http://www.firegiant.com/

____________________________________________________________________
WiX Toolset Users Mailing List provided by FireGiant http://www.firegiant.com/


More information about the wix-users mailing list