Solved

conversion from VB.Net 2005 to C#

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

810 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