AccessViolationException : Catch/Finally block fails to Execute

AccessViolationException : Catch/Finally block fails to Execute

Anonymous
Not applicable
1,114 Views
4 Replies
Message 1 of 5

AccessViolationException : Catch/Finally block fails to Execute

Anonymous
Not applicable

I am developing an Add-on for Revit Structure 2012 that needs displaying the ThumbNail's of the RFA.

 

 Few of the RFA's have the preview available and few don't(I'm dislaying a default Image for these) After deploying, it fails to run on one of the machines and displays the below error

 "Revit encountered a System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

 

I implemented the try/Catch/Finally approach to log the errors.. but to my surprise found that the Catch block fails to execute and also the finally block on that machine.

 I tried building a standalone version of this application and found that all works well.

The execution fails when I integrate this into Revit.. Any advice is really appreciated...

Thanks

0 Likes
1,115 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

Can you post some code?

0 Likes
Message 3 of 5

Anonymous
Not applicable
        public void ExtractFamilyImage(string ImgPath, BitmapSource ThumbNailImage)
        {
            GenerateThumbnail objTc;
            Bitmap objBitmap;
            //BitmapImage objBmp;

            #region TRY
            try
            {
                objTc = new GenerateThumbnail();
                objBitmap = objTc.GetThumbNail(ImgPath);

                BitmapSource bmpsrc;
                bmpsrc=System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap				(objBitmap.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, 			BitmapSizeOptions.FromWidthAndHeight(128, 128));
                ThumbnailImage = bmpsrc;
                bmpsrc.Freeze();
                bmpsrc=null;

               
            }
            #endregion

            #region Catch
		catch (Exception ex)
                 {
         	 // Add error logging
                   ErrorLog(ex, "Extract Family Image " +ImgPath);
		 // Log error for those RFA's that donot have preview
			//Binding a default image 

			string folderpath =ImagesFolder;
			CobjBitmap = CobjTc.GetThumbNail("RFADefault.bmp");
			bmpsrc=System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap				                  (CobjBitmap.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, 			                  BitmapSizeOptions.FromWidthAndHeight(128, 128));
	             ThumbnailImage = bmpsrc;

		 }
            #endregion

	}

 

0 Likes
Message 4 of 5

Anonymous
Not applicable

The code in your catch block is the same in your try block. Any exceptions from that code is not going to be caught. 

Also try catching the exception you are getting, not just "Exception"

0 Likes
Message 5 of 5

Anonymous
Not applicable

But this code works on all the machines.

It does go to the Catch block and executes the remaining part of loading a Default image/ Writing to the Log File but only fails on one of the clients Machine and I could also see some information i the Event Viewer like below

 

".NET Runtime version 4.0.30319.239 - The profiler was loaded successfully.  Profiler CLSID: 'Revit.BorderSentinel'.  Process ID (decimal): 1152.  Message ID: [0x2507]"

 

 

Not sure if this would be helpful.

0 Likes