Solved

conversion from VB.Net 2005 to C#

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

20 Experts available now in Live!

Get 1:1 Help Now