Solved

conversion from VB.Net 2005 to C#

Posted on 2009-04-05
3
1,594 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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