0

I don't think there is a good way to do this...

but I have a vb.Net DLL which has an error handling method. Its good, and I want to use it in my C#.Net site.

So I add the vb.Net DLL to my C# project.

But wait! My vb.Net error handler method requires a 'Microsoft.VisualBasic.ErrObject' !


Hmm.. is it possible to create such a data type in C#? Even by some type of conversion?

Or is this just ugly and should I forget about even trying something so outrageous and just restart the project in vb.Net?

*note that I am not going to change the required data type in the DLL

Thanks!

1

1 Answer 1

2

You can add a reference to the Microsoft.VisualBasic dll to your C# project.

Right-click the References in the solution explorer click Add Reference,then search for Microsoft.VisualBasic:

enter image description here

How to: Add or Remove References By Using the Add Reference Dialog Box


But in general i would suggest to use the .NET error handling with exceptions that inherit from or are System.Exception and support using try-catch-finally.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes this allows you to create the object :) thank you! But to do a try-catch with this still causes a problem because you have to catch an object derived from System.Exception
@Christopher: good point, added it to my question. But OP hasn't mentioned that he wants to use try...catch. However, never used VisualBasic.ErrObject in VB.NET or C# so no idea if it works at all.
if you mean errors generated by Err.Raise vb method, such error can be distinguished by theException.TargetSite.DeclaringType (the fact that it is System.Exception still is PITA, as written by Christopher before)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.