3

I use the following code to access a VSS item:

Dim sItem As String = "$/MyVssProject/InexistentFile.txt"
Dim oItem As SourceSafeTypeLib.VSSItem = Nothing
Try
  oItem = m_oSourceSafe.VSSItem(sItem)
Catch ex As Runtime.InteropServices.COMException
  MsgBox(ex.Message, MsgBoxStyle.Exclamation)
Catch ex As Exception
  MsgBox(ex.Message, MsgBoxStyle.Exclamation)
End Try

The problem I face is when I try to get an instance to a file that doesn't exist in the VSSDB, thus leading to a COMException, which basically wouldn't be of a problem (I would expect). In fact the exception occurs, but instead of proceeding with the catch code, the debug cursor stays on the line "oItem = m_oSourceSafe.VSSItem(sItem)", showing a dialog with title "COMException crossed a native/managed boundary.

From here the execution doesn't proceed, until I change the content of sItem to an existing file.

Why does the exception not get caught, and how can I achieve it?

Environment: VS2010 with .Net 2.0 on WinXP SP3 x86

Thanks mates!

Robin Holenweger
  • 321
  • 3
  • 14
  • Hmm, that's quite unusual. And pretty fatal, the CLR can't recover from COM servers throwing hard exceptions instead of returning error codes. You didn't document the actual exception details at all so the question can't be answered. The usual advice applies: don't use VSS. – Hans Passant Feb 24 '12 at 10:02
  • Sry, thought it's selfexplanatory: retrieving an "InexistingFile.txt" fails because it doesn't exist. Not using VSS is not an option; wouldn't do it voluntarily - customer's decision/legacy code) – Robin Holenweger Apr 16 '12 at 11:09

1 Answers1

5

I found out how to catch:

In the project's settings, on the "Debug" tab, select "Enable unmanaged code debugging". From now on you should be able to chatch the exception.

The disadvantage of this though is, that it is no longer possible to edit code while stepping through the code.

Robin Holenweger
  • 321
  • 3
  • 14