Why do people use ProjectData

I recently looked at some encodings on the Internet. I found that some people use the Microsoft.VisualBasic.CompilerServices.ProjectData.ProjectData class in the catch .
  catch (Exception exception1) { //ProjectData.SetProjectError(exception1); Console.WriteLine(exception1.ToString()); Console.WriteLine(); Console.WriteLine(sSQL); //ProjectData.ClearProjectError(); } 

I searched for it in msdn, which mentioned that this API supports the .NET Framework and is not intended to be used directly from your code.

I am curious why people use it. Can you explain this to me?

+7
source share
3 answers

My experience is that this type of code usage is found in C # / VB.NET projects that have been converted from VB6. When developing new C # / VB.NET solutions / projects, this practice should not be used.

Note. This method can be safely replaced with proper exception handling that you would use to look in other .NET solutions / projects.

+7
source

This code is either emitted by a code conversion tool that converted VB code to C #, or was the result of decompiling an assembly that was originally created using VB.

I transfer the VB project to Mono and find out that the VB compiler inserts these calls to ProjectData.SetProjectError(exception) and ProjectData.ClearProjectError() into any catch block and tries to find a way to prevent the compiler from doing this because Mono does not implement the ProjectData module. And I found your question during my research!

+2
source

so this is the result of the old vb6 legacy for those interested. when vb6 started, the err object appeared, which is still around, but moved to the projectdata object in vb. if someone like me remembers vb6 (it came back when dinosaurs roamed the earth), the next time there was a convenient little error call. this is if you do not like these annoying little exceptions. most vb6 programs used it abundantly and you had no exceptions because you ignored them. therefore it is explained here.

catch (exception exception1) // catch the exceptions that just occurred

  { ProjectData.SetProjectError(exception1); // set the information 

// in the err object, if someone really wants to check

  ProjectData.ClearProjectError(); //clear the err object } 

as you can see, this completely ignores any exceptions and the true version of vb6, your code just explodes without any explanation. needless to say, if someone writes such code or uses vb in this way, I will find you and figure out a way to force you to jail.

0
source

All Articles