Solved

conversion from VB.Net 2005 to C#

Posted on 2009-04-05
3
1,616 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

635 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