Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
My Problem

Hello code project mates,
I am in mid of completion of an image stitching project. When I run my project I get an exception called "Non Com visible base class occurred". I know that there are lot of solutions around the internet on this like

"Uncheck the Non Com visible exception from the exception settings ".

But I don't need that kind of solution because I wanna deliver my project to client. I can't force them to change exception settings. So is there a way to ignore the exception at runtime. Is there any code to stop the exception from breaking the code.

Please help me to get rid of this exception.

What I have tried:

I tried something like DLLimport which can solve the problem but it doesn't. Please guide me what to do if the DLLimport really works with this........
Posted
Updated 21-Jun-18 0:52am
v3

try
{
    // your code here
}
catch(Exception exp)
{
    // you can log the exception here or simply do nothing
}
finally
{
    // the finally block is optional but you can put code you want to happen here after an exception occurs if you want
}


That answers your question but it isn't going to solve your problem.
 
Share this answer
 
Comments
Maciej Los 21-Jun-18 5:48am    
The last statement proves that should not ignore exceptions ;)
R. B. Krish 21-Jun-18 6:11am    
@F-ES Sitecore Hi, I can't catch the exception even through catch block. I don't know how to at-least stop the exception. Please help me.

Exception tells me like this.

Exception:
Additional information: A QueryInterface call was made requesting the class interface of COM visible managed class 'MS.Internal.AutomationProxies.WindowsEditBox'. However since this class derives from non COM visible class 'MS.Internal.AutomationProxies.ProxyHwnd', the QueryInterface call will fail. This is done to prevent the non COM visible base class from being constrained by the COM versioning rules.
F-ES Sitecore 21-Jun-18 6:16am    
Are you building your project in Debug mode? Try it in Release mode (you should always be shipping the Release version of your code anyway)
R. B. Krish 21-Jun-18 6:34am    
Yeah I tried that too but even in the release mode it still breaks. That's what my problem is. I can't handle the exception.
As F-ES Sitecore says, catching the exception is simple.
But ... it's a very bad idea. You get the exception because something is wrong, and the process can't continue. Catching the exception is there to let your code recover gracefully from a problem, it doesn't solve the problem.

I have no idea what a Noncom class is, but if it throws an exception then whatever you were trying to do with it has not worked, and that probably means that your app is not going to do what the user wants.

Instead of trying to ignore the exception so you can ship code, use the debugger to find out what is causing the problem and why. Shipping duff code is a very, very good way to annoy clients - far, far worse than being honest and delaying shipment for 24 hours while you fix and fully test it.
 
Share this answer
 
Comments
F-ES Sitecore 21-Jun-18 6:18am    
I think he means "non COM", which appears as NonCom in pascal case exceptions and "Noncom" when converted to sentence case.
OriginalGriff 21-Jun-18 6:30am    
You are probably right - but that still doesn't give us enough to suggest a proper fix! :laugh:
R. B. Krish 21-Jun-18 6:38am    
@OriginalGriff I use Teststack.White to run an application so that it can automates a process. So while at runtime it throws the non com exception. Even in the release mode I can't make it run without the exception.
OriginalGriff 21-Jun-18 6:46am    
Release mode or debug mode doesn't make a different to exceptions - if they are thrown, they have to be handled in release or production build or the app / thread will close.

I'm not familiar with Teststack.White, but if it's running an external app and that fails, you need to know why that app fails in order to prevent the problem.
Not a final solution but some insights:

nonComVisibleBaseClass MDA | Microsoft Docs[^]

Quote:
Uncheck the Non Com visible exception from the exception settings.
That is a VS option. So your clients do not have to change any settings on their side.

As far as I understood it, the exception (which is a diagnostic alert and not a "classic" exception so that it can't be catched) is only raised when running the appliction from within VS.

Have you tried running it standalone (outside VS)?
 
Share this answer
 
Comments
R. B. Krish 21-Jun-18 7:37am    
Yeah when I try to run it as a standalone exe it doesn't throw any error. Thank you.....
Jochen Arndt 21-Jun-18 7:58am    
That is what I have expected.

But it does not really solve a potentially present problem.

You might use the resolution from the MDA link:
"Do not expose the class interface. Define an explicit interface and apply the ClassInterfaceAttribute attribute to it."
R. B. Krish 21-Jun-18 8:15am    
Thanks @Jochen Arndt

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900