Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why people use ProjectData

Tags:

c#

Recently I looked at some coding at the web. I found some people use Microsoft.VisualBasic.CompilerServices.ProjectData.ProjectData class in catch block.

 catch (Exception exception1)
        {
            //ProjectData.SetProjectError(exception1);
            Console.WriteLine(exception1.ToString());
            Console.WriteLine();
            Console.WriteLine(sSQL);
            //ProjectData.ClearProjectError();
        }

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

I am curious what reason people use it. Would you explain it to me?

like image 851
Y Chan Avatar asked Mar 26 '13 20:03

Y Chan


2 Answers

My experience has been that this type of code use 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 technique can safely be replaced with proper exception handling that you would be used to seeing in other .NET solutions/projects.

like image 157
DragonZero Avatar answered Oct 01 '22 04:10

DragonZero


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

I'm porting a VB project to Mono, and found out that the VB compiler injects these calls ProjectData.SetProjectError(exception) and ProjectData.ClearProjectError() in any catch block, and try to find a way to prevent the compiler from doing so because Mono doesn't implement the ProjectData module. And found your question while doing my research!

like image 27
Ashraf Sabry Avatar answered Oct 01 '22 03:10

Ashraf Sabry