Solved

conversion from VB.Net 2005 to C#

Posted on 2009-04-05
3
1,573 Views
Last Modified: 2013-12-17
We're converting a barely-started ClickOnce-deployed project from VB to C#. So far it just has a few forms, one of which is a splash screen. As a VB form, it used the My namespace extensively (see code). My.Settings are also used on almost every form in our VB projects as well.

After Googling for a few hours, we tried adding the Microsoft.VisualBasic namespace to the project and added a Using statement; no joy. The errors we receive include:
"The name 'My' does not exist in the current context".

We don't care about anything except getting this out the door ASAP. Either we need a replacement procedure for accessing classes which are offered in the My namespace from VB, or we need workarounds in C#.

QUESTIONS:
1. Are we to understand that 'My' is gone now, in C#? If so, what's the replacement?
2. How to we fix it?

NOTE: A simple explanation will get more credit than a pasted link.

Thanks
private void SplashScreen1_Load(object sender, System.EventArgs e)

        {

            //Application title

            if (!string.IsNullOrEmpty(My.Application.Info.Title)) 

            {

                ApplicationTitle.Text = My.Application.Info.Title;

            }

            else 

            {

                //If the application title is missing, use the application name, without the extension

               ApplicationTitle.Text = System.IO.Path.GetFileNameWithoutExtension(My.Application.Info.AssemblyName);

            }

           this.Opacity = 0.9;

           this.Version.Text = My.Application.Info.Version.Major + "." + My.Application.Info.Version.Minor + "." + My.Application.Info.Version.Build + "." + My.Application.Info.Version.MinorRevision;

           Version.Text = System.String.Format(Version.Text, My.Application.Info.Version.Major, My.Application.Info.Version.Minor, My.Application.Info.Version.Build, My.Application.Info.Version.Revision);

           if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed) 

           {

               System.Deployment.Application.ApplicationDeployment ad = System.Deployment.Application.ApplicationDeployment.CurrentDeployment;

               Version.Text = ad.CurrentVersion.ToString;

           }

        }

Open in new window

0
Comment
Question by:sfalk3n
  • 2
3 Comments
 
LVL 7

Expert Comment

by:alexpercsi
ID: 24072768
The "My" namespace does not exist in C#. In VB it is mainly a shortcut object, giving easy access to certain functionality that developers commonly use. You will have to refactor your code not to use it.

In your specific context, try replacing "My.Application" with "Application" and see if that helps.

One thing is for certain, all the items that were accessible in VB through the My object are surely accessible one way or another in C#.
0
 
LVL 22

Expert Comment

by:pivar
ID: 24072773
Hi,

AFAIK, the My object is VB.net only. You have to use different sources to get the info.

In the case of above functionality I believe you may find them here:

System.Reflection.Assembly.GetEntryAssembly().GetName().Name

System.Reflection.Assembly.GetEntryAssembly().GetName().Version


/peter
0
 
LVL 22

Accepted Solution

by:
pivar earned 500 total points
ID: 24072789
That is in

System.Reflection.Assembly.GetEntryAssembly().GetName().Version

you may find

Version.Major
Version.MajorRevision
Version.Minor
Version.MinorRevision
Version.Build
Version.Revision
Version.ToString() (Text)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now