Hi @shubham_joshiMKWPQ. I am not fluent in C#, but I can tell that you were attempting to access the Document.Thumbnail property in the code you posted above. I am not sure if you were aware of this or not, but the object you get as the value of that property is an IPictureDisp type object. That is not a normal, or native image file type. It is defined within the "stdole" Namespace, which must add a reference to in our code, to be able to access its methods & properties. I am not sure why it would cause a catastrophic failure by simply attempting to check if that property was Null (or Nothing) though. Take a look at the following iLogic rule (uses vb.net, instead of C#.net), which attempts to save the documents thumbnail out as a bmp type image file. It utilizes a 'Do...Loop' while setting the value of the oThumb variable, checking its 'Handle' each time until it is a positive value. I did not originally author that code, so I do not fully understand the need for that loop, but I'm showing it here just in case it might be an important detail, for some reason.
AddReference "System.Drawing"
AddReference "stdole"
AddReference "System.Windows.Forms"
Class ThisRule
Sub Main
Break
Dim oDoc As Document = ThisDoc.Document
Dim oThumb As stdole.IPictureDisp
Do
oThumb = oDoc.Thumbnail
Loop While oThumb.Handle < 0
Dim oAHConverter As New AxHostConverter
Dim oImage As System.Drawing.Image = oAHConverter.GetImageFromIPictureDisp(oThumb)
'this call must be created, but is never used
Dim myCallback As New System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)
'create a thumbnail before save - seems to generate a better quality
oImage.GetThumbnailImage(180, 180, myCallback, IntPtr.Zero).Save("C:\Temp\Thumbnail To BMP test.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
End Sub
Public Function ThumbnailCallback() As Boolean
Return False
End Function
End Class
Class AxHostConverter
Inherits System.Windows.Forms.AxHost
Public Sub New()
'MyBase.New("{63109182-966B-4e3c-A8B2-8BC4A88D221C}")
MyBase.New((New Guid).ToString)
End Sub
Public Function GetImageFromIPictureDisp(ByVal IPDisp As stdole.IPictureDisp) As System.Drawing.Image
Return MyBase.GetPictureFromIPicture(IPDisp)
End Function
End Class
Wesley Crihfield

(Not an Autodesk Employee)