share violation when opening property set of occurance/suboccurance

Experimenter
Experimenter

I have an add-in which drills down through all the occurances/suboccurances of the active assembly and gathers all the property names and values for a report.

 

It works fine unless one of the sub-component files is open in another window.  If a file is open then a share violation exception is thrown STG_E_SHAREVIOLATION (0x80030020).

 

I would have expected the read-only = true to allow me to open the property set even though the file is already open elsewhere.

 

.NET 4.5 and ST8

 

Here is the pertinent code:

...
For Each Occurence As SolidEdgeAssembly.Occurrence In parentSE_Occurrences
fillProperties(Occurence.OccurrenceFileName)
Next
...

Private Sub fillProperties(docPath As String)
Dim objPropertySets As SolidEdgeFileProperties.PropertySets = Nothing

Try
objPropertySets = New SolidEdgeFileProperties.PropertySets
objPropertySets.Open(docPath, True) ''Exception thrown here

''grab all the property names & values from all property sets

objPropertySets.Close()


Catch ex As Exception
Dim a As Integer = 0
Finally
If Not (objPropertySets Is Nothing) Then
Marshal.ReleaseComObject(objPropertySets)
objPropertySets = Nothing
End If
End Try
End Sub

Thanks!

2 REPLIES

Re: share violation when opening property set of occurance/suboccurance

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom
Hi Rick,
You use the FileProperities object which opens the document in a new process what causes the exception.
Use the OccurrenceDocument from the Occurrence object and use its Properties property to access the file properties.
This should work because your adding does all in one process.
regards

JB
VS2015, SE ST10

Re: share violation when opening property set of occurance/suboccurance

Experimenter
Experimenter

Thank you very much for your prompt and correct solution