Problem with preprocessor directives

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • skiabox
    New Member
    • Oct 2007
    • 6

    #1

    Problem with preprocessor directives

    I have a project written in vb.net and I am trying to convert it to c#.
    I have managed to convert it excepto from one file.
    Here is the old code :

    Code:
    #If _MyType <> "Empty" Then
    
    Namespace My
        ''' <summary>
        ''' Module used to define the properties that are available in the My Namespace for Web projects.
        ''' </summary>
        ''' <remarks></remarks>
        <Global.Microsoft.VisualBasic.HideModuleName()> _
        Module MyWebExtension
            Private s_Computer As New ThreadSafeObjectProvider(Of Global.Microsoft.VisualBasic.Devices.ServerComputer)
            Private s_User As New ThreadSafeObjectProvider(Of Global.Microsoft.VisualBasic.ApplicationServices.WebUser)
            Private s_Log As New ThreadSafeObjectProvider(Of Global.Microsoft.VisualBasic.Logging.AspLog)
            ''' <summary>
            ''' Returns information about the host computer.
            ''' </summary>
            <Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")> _
            Friend ReadOnly Property Computer() As Global.Microsoft.VisualBasic.Devices.ServerComputer
                Get
                    Return s_Computer.GetInstance()
                End Get
            End Property
            ''' <summary>
            ''' Returns information for the current Web user.
            ''' </summary>
            <Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")> _
            Friend ReadOnly Property User() As Global.Microsoft.VisualBasic.ApplicationServices.WebUser
                Get
                    Return s_User.GetInstance()
                End Get
            End Property
            ''' <summary>
            ''' Returns Request object.
            ''' </summary>
            <Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")> _
            <Global.System.ComponentModel.Design.HelpKeyword("My.Request")> _
            Friend ReadOnly Property Request() As Global.System.Web.HttpRequest
                <Global.System.Diagnostics.DebuggerHidden()> _
                Get
                    Dim CurrentContext As Global.System.Web.HttpContext = Global.System.Web.HttpContext.Current
                    If CurrentContext IsNot Nothing Then
                        Return CurrentContext.Request
                    End If
                    Return Nothing
                End Get
            End Property
            ''' <summary>
            ''' Returns Response object.
            ''' </summary>
            <Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")> _
             <Global.System.ComponentModel.Design.HelpKeyword("My.Response")> _
             Friend ReadOnly Property Response() As Global.System.Web.HttpResponse
                <Global.System.Diagnostics.DebuggerHidden()> _
                Get
                    Dim CurrentContext As Global.System.Web.HttpContext = Global.System.Web.HttpContext.Current
                    If CurrentContext IsNot Nothing Then
                        Return CurrentContext.Response
                    End If
                    Return Nothing
                End Get
            End Property
            ''' <summary>
            ''' Returns the Asp log object.
            ''' </summary>
            <Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")> _
            Friend ReadOnly Property Log() As Global.Microsoft.VisualBasic.Logging.AspLog
                Get
                    Return s_Log.GetInstance()
                End Get
            End Property
         End Module
    End Namespace
    
    #End If
    And here is the code that a utility tried with no success :

    Code:
    //INSTANT C# TODO TASK: C# compiler constants cannot be set to explicit values:
    //INSTANT C# NOTE: Formerly VB project-level imports:
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using System.Xml.Linq;
    using System.Diagnostics;
    using System.Collections.Specialized;
    using System.Configuration;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Web;
    using System.Web.Caching;
    using System.Web.SessionState;
    using System.Web.Security;
    using System.Web.Profile;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    namespace UWESA.Web
    {
    #if _MyType != "Empty"
    
    	namespace My
    	{
    		/// <summary>
    		/// Module used to define the properties that are available in the My Namespace for Web projects.
    		/// </summary>
    		/// <remarks></remarks>
    		
    		internal static class MyWebExtension
    		{
    			private static ThreadSafeObjectProvider<Microsoft.VisualBasic.Devices.ServerComputer> s_Computer = new ThreadSafeObjectProvider<Microsoft.VisualBasic.Devices.ServerComputer>();
    			private static ThreadSafeObjectProvider<Microsoft.VisualBasic.ApplicationServices.WebUser> s_User = new ThreadSafeObjectProvider<Microsoft.VisualBasic.ApplicationServices.WebUser>();
    			private static ThreadSafeObjectProvider<Microsoft.VisualBasic.Logging.AspLog> s_Log = new ThreadSafeObjectProvider<Microsoft.VisualBasic.Logging.AspLog>();
    			/// <summary>
    			/// Returns information about the host computer.
    			/// </summary>
    			[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
    			internal static Microsoft.VisualBasic.Devices.ServerComputer Computer
    			{
    				get
    				{
    					return s_Computer.GetInstance();
    				}
    			}
    			/// <summary>
    			/// Returns information for the current Web user.
    			/// </summary>
    			[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
    			internal static Microsoft.VisualBasic.ApplicationServices.WebUser User
    			{
    				get
    				{
    					return s_User.GetInstance();
    				}
    			}
    			/// <summary>
    			/// Returns Request object.
    			/// </summary>
    			[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode"), global::System.ComponentModel.Design.HelpKeyword("My.Request")]
    			internal static global::System.Web.HttpRequest Request
    			{
    				[global::System.Diagnostics.DebuggerHidden()]
    				get
    				{
    					global::System.Web.HttpContext CurrentContext = global::System.Web.HttpContext.Current;
    					if (CurrentContext != null)
    					{
    						return CurrentContext.Request;
    					}
    					return null;
    				}
    			}
    			/// <summary>
    			/// Returns Response object.
    			/// </summary>
    			[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode"), global::System.ComponentModel.Design.HelpKeyword("My.Response")]
    			internal static global::System.Web.HttpResponse Response
    			{
    				[global::System.Diagnostics.DebuggerHidden()]
    				get
    				{
    					global::System.Web.HttpContext CurrentContext = global::System.Web.HttpContext.Current;
    					if (CurrentContext != null)
    					{
    						return CurrentContext.Response;
    					}
    					return null;
    				}
    			}
    			/// <summary>
    			/// Returns the Asp log object.
    			/// </summary>
    			[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
    			internal static Microsoft.VisualBasic.Logging.AspLog Log
    			{
    				get
    				{
    					return s_Log.GetInstance();
    				}
    			}
    		 }
    	}
    
    	#endif
    } //end of root namespace
    Here's the errors I get :
    Error 1 Invalid preprocessor expression D:\UWESA\trunk\ source\uwesa_we b_CS\Properties \MyExtensions\M yWebExtension.c s 26 16 uwesa_web
    Error 2 The type or namespace name 'ThreadSafeObje ctProvider' could not be found (are you missing a using directive or an assembly reference?) D:\UWESA\trunk\ source\uwesa_we b_CS\Properties \MyExtensions\M yWebExtension.c s 37 107 uwesa_web
    Error 3 The type or namespace name 'ThreadSafeObje ctProvider' could not be found (are you missing a using directive or an assembly reference?) D:\UWESA\trunk\ source\uwesa_we b_CS\Properties \MyExtensions\M yWebExtension.c s 38 108 uwesa_web
    Error 4 The type or namespace name 'ThreadSafeObje ctProvider' could not be found (are you missing a using directive or an assembly reference?) D:\UWESA\trunk\ source\uwesa_we b_CS\Properties \MyExtensions\M yWebExtension.c s 39 94 uwesa_web

    I don't know if it is relevant but the vb.net coder has used ajax toolkit.
    Thank you!
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    I have a project written in vb.net and I am trying to convert it to c#.
    I have managed to convert it excepto from one file.
    Here is the old code :

    And here is the code that a utility tried with no success :

    Here's the errors I get :
    Code:
    Error 1 Invalid preprocessor expression D:\UWESA\trunk\source\uwesa_web_CS\Properties\MyEx tensions\MyWebExtension.cs 26 16 uwesa_web
    Error 2 The type or namespace name 'ThreadSafeObjectProvider' could not be found (are you missing a using directive or an assembly reference?) D:\UWESA\trunk\source\uwesa_web_CS\Properties\MyEx tensions\MyWebExtension.cs 37 107 uwesa_web
    Error 3 The type or namespace name 'ThreadSafeObjectProvider' could not be found (are you missing a using directive or an assembly reference?) D:\UWESA\trunk\source\uwesa_web_CS\Properties\MyEx tensions\MyWebExtension.cs 38 108 uwesa_web
    Error 4 The type or namespace name 'ThreadSafeObjectProvider' could not be found (are you missing a using directive or an assembly reference?) D:\UWESA\trunk\source\uwesa_web_CS\Properties\MyEx tensions\MyWebExtension.cs 39 94 uwesa_web
    I don't know if it is relevant but the vb.net coder has used ajax toolkit.
    Thank you!
    'Thank you' for ??? You haven't asked any questions for anyone here to answer... you have only said "I have this condition'

    You do realize the error messages are telling you the exact file and line number where the problem is, right?

    D:\UWESA\trunk\ source\uwesa_we b_CS\Properties \MyEx tensions\MyWebE xtension.cs 37 107 uwesa_web

    Comment

    • skiabox
      New Member
      • Oct 2007
      • 6

      #3
      What I am asking here is how can I properly convert this file to c# since it seems that the utility failed with this file.

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        I wouldn't say the utility failed. It converted everything but 4 lines. It seemed to do well.

        You just need to fix those lines.

        I notice they all failed on a line with this as part of the path
        ...s\MyEx tensions\MyW...

        It seems unlikely that the real path has such a word as "MyEx{space}ten sions"

        I would guess the source code is referencing a file that you maybe don't have.

        The error message is telling you this..
        It could not find and object or namesapce called 'ThreadSafeObje ctProvider'
        that exists at the path provided of
        D:\UWESA\trunk\ source\uwesa_we b_CS\Properties \MyEx tensions\MyWebE xtension.c

        My guess is that you don't have that path at all, do you?
        Either because the path isn't valied with the space or return in the middle of it or because the source came from another PC that has a D: drive and that file you don't have that.

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          You also have four line of C# that are expressly using VB objects
          Code:
                      private static ThreadSafeObjectProvider<Microsoft.VisualBasic.Devices.ServerComputer> s_Computer = new ThreadSafeObjectProvider<Microsoft.VisualBasic.Devices.ServerComputer>();
                      private static ThreadSafeObjectProvider<Microsoft.VisualBasic.ApplicationServices.WebUser> s_User = new ThreadSafeObjectProvider<Microsoft.VisualBasic.ApplicationServices.WebUser>();
                      private static ThreadSafeObjectProvider<Microsoft.VisualBasic.Logging.AspLog> s_Log = new ThreadSafeObjectProvider<Microsoft.VisualBasic.Logging.AspLog>();
                      /// <summary>
                      /// Returns information about the host computer.
                      /// </summary>
                      [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
                      internal static Microsoft.VisualBasic.Devices.ServerComputer Computer
          Have you provided references in your C# code to VIsual Basic? It's perfectly legal to use some VB in your C# application.

          Comment

          • skiabox
            New Member
            • Oct 2007
            • 6

            #6
            I tried to left the vb file in that folder and it does not produces any errors so far but I don't know if it the correct way to go.

            Comment

            • skiabox
              New Member
              • Oct 2007
              • 6

              #7
              The path exists and there is no space.It maybe a problem of this forum's copy/paste functionality.

              Comment

              • tlhintoq
                Recognized Expert Specialist
                • Mar 2008
                • 3532

                #8
                Did you create a reference in your C# project to Microsoft.Visua lBasic?

                Comment

                Working...