473,322 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 :

Expand|Select|Wrap|Line Numbers
  1. #If _MyType <> "Empty" Then
  2.  
  3. Namespace My
  4.     ''' <summary>
  5.     ''' Module used to define the properties that are available in the My Namespace for Web projects.
  6.     ''' </summary>
  7.     ''' <remarks></remarks>
  8.     <Global.Microsoft.VisualBasic.HideModuleName()> _
  9.     Module MyWebExtension
  10.         Private s_Computer As New ThreadSafeObjectProvider(Of Global.Microsoft.VisualBasic.Devices.ServerComputer)
  11.         Private s_User As New ThreadSafeObjectProvider(Of Global.Microsoft.VisualBasic.ApplicationServices.WebUser)
  12.         Private s_Log As New ThreadSafeObjectProvider(Of Global.Microsoft.VisualBasic.Logging.AspLog)
  13.         ''' <summary>
  14.         ''' Returns information about the host computer.
  15.         ''' </summary>
  16.         <Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")> _
  17.         Friend ReadOnly Property Computer() As Global.Microsoft.VisualBasic.Devices.ServerComputer
  18.             Get
  19.                 Return s_Computer.GetInstance()
  20.             End Get
  21.         End Property
  22.         ''' <summary>
  23.         ''' Returns information for the current Web user.
  24.         ''' </summary>
  25.         <Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")> _
  26.         Friend ReadOnly Property User() As Global.Microsoft.VisualBasic.ApplicationServices.WebUser
  27.             Get
  28.                 Return s_User.GetInstance()
  29.             End Get
  30.         End Property
  31.         ''' <summary>
  32.         ''' Returns Request object.
  33.         ''' </summary>
  34.         <Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")> _
  35.         <Global.System.ComponentModel.Design.HelpKeyword("My.Request")> _
  36.         Friend ReadOnly Property Request() As Global.System.Web.HttpRequest
  37.             <Global.System.Diagnostics.DebuggerHidden()> _
  38.             Get
  39.                 Dim CurrentContext As Global.System.Web.HttpContext = Global.System.Web.HttpContext.Current
  40.                 If CurrentContext IsNot Nothing Then
  41.                     Return CurrentContext.Request
  42.                 End If
  43.                 Return Nothing
  44.             End Get
  45.         End Property
  46.         ''' <summary>
  47.         ''' Returns Response object.
  48.         ''' </summary>
  49.         <Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")> _
  50.          <Global.System.ComponentModel.Design.HelpKeyword("My.Response")> _
  51.          Friend ReadOnly Property Response() As Global.System.Web.HttpResponse
  52.             <Global.System.Diagnostics.DebuggerHidden()> _
  53.             Get
  54.                 Dim CurrentContext As Global.System.Web.HttpContext = Global.System.Web.HttpContext.Current
  55.                 If CurrentContext IsNot Nothing Then
  56.                     Return CurrentContext.Response
  57.                 End If
  58.                 Return Nothing
  59.             End Get
  60.         End Property
  61.         ''' <summary>
  62.         ''' Returns the Asp log object.
  63.         ''' </summary>
  64.         <Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")> _
  65.         Friend ReadOnly Property Log() As Global.Microsoft.VisualBasic.Logging.AspLog
  66.             Get
  67.                 Return s_Log.GetInstance()
  68.             End Get
  69.         End Property
  70.      End Module
  71. End Namespace
  72.  
  73. #End If
  74.  
And here is the code that a utility tried with no success :

Expand|Select|Wrap|Line Numbers
  1. //INSTANT C# TODO TASK: C# compiler constants cannot be set to explicit values:
  2. //INSTANT C# NOTE: Formerly VB project-level imports:
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Linq;
  8. using System.Xml.Linq;
  9. using System.Diagnostics;
  10. using System.Collections.Specialized;
  11. using System.Configuration;
  12. using System.Text;
  13. using System.Text.RegularExpressions;
  14. using System.Web;
  15. using System.Web.Caching;
  16. using System.Web.SessionState;
  17. using System.Web.Security;
  18. using System.Web.Profile;
  19. using System.Web.UI;
  20. using System.Web.UI.WebControls;
  21. using System.Web.UI.WebControls.WebParts;
  22. using System.Web.UI.HtmlControls;
  23.  
  24. namespace UWESA.Web
  25. {
  26. #if _MyType != "Empty"
  27.  
  28.     namespace My
  29.     {
  30.         /// <summary>
  31.         /// Module used to define the properties that are available in the My Namespace for Web projects.
  32.         /// </summary>
  33.         /// <remarks></remarks>
  34.  
  35.         internal static class MyWebExtension
  36.         {
  37.             private static ThreadSafeObjectProvider<Microsoft.VisualBasic.Devices.ServerComputer> s_Computer = new ThreadSafeObjectProvider<Microsoft.VisualBasic.Devices.ServerComputer>();
  38.             private static ThreadSafeObjectProvider<Microsoft.VisualBasic.ApplicationServices.WebUser> s_User = new ThreadSafeObjectProvider<Microsoft.VisualBasic.ApplicationServices.WebUser>();
  39.             private static ThreadSafeObjectProvider<Microsoft.VisualBasic.Logging.AspLog> s_Log = new ThreadSafeObjectProvider<Microsoft.VisualBasic.Logging.AspLog>();
  40.             /// <summary>
  41.             /// Returns information about the host computer.
  42.             /// </summary>
  43.             [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
  44.             internal static Microsoft.VisualBasic.Devices.ServerComputer Computer
  45.             {
  46.                 get
  47.                 {
  48.                     return s_Computer.GetInstance();
  49.                 }
  50.             }
  51.             /// <summary>
  52.             /// Returns information for the current Web user.
  53.             /// </summary>
  54.             [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
  55.             internal static Microsoft.VisualBasic.ApplicationServices.WebUser User
  56.             {
  57.                 get
  58.                 {
  59.                     return s_User.GetInstance();
  60.                 }
  61.             }
  62.             /// <summary>
  63.             /// Returns Request object.
  64.             /// </summary>
  65.             [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode"), global::System.ComponentModel.Design.HelpKeyword("My.Request")]
  66.             internal static global::System.Web.HttpRequest Request
  67.             {
  68.                 [global::System.Diagnostics.DebuggerHidden()]
  69.                 get
  70.                 {
  71.                     global::System.Web.HttpContext CurrentContext = global::System.Web.HttpContext.Current;
  72.                     if (CurrentContext != null)
  73.                     {
  74.                         return CurrentContext.Request;
  75.                     }
  76.                     return null;
  77.                 }
  78.             }
  79.             /// <summary>
  80.             /// Returns Response object.
  81.             /// </summary>
  82.             [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode"), global::System.ComponentModel.Design.HelpKeyword("My.Response")]
  83.             internal static global::System.Web.HttpResponse Response
  84.             {
  85.                 [global::System.Diagnostics.DebuggerHidden()]
  86.                 get
  87.                 {
  88.                     global::System.Web.HttpContext CurrentContext = global::System.Web.HttpContext.Current;
  89.                     if (CurrentContext != null)
  90.                     {
  91.                         return CurrentContext.Response;
  92.                     }
  93.                     return null;
  94.                 }
  95.             }
  96.             /// <summary>
  97.             /// Returns the Asp log object.
  98.             /// </summary>
  99.             [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
  100.             internal static Microsoft.VisualBasic.Logging.AspLog Log
  101.             {
  102.                 get
  103.                 {
  104.                     return s_Log.GetInstance();
  105.                 }
  106.             }
  107.          }
  108.     }
  109.  
  110.     #endif
  111. } //end of root namespace
  112.  
Here's the errors I get :
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!
Apr 10 '10 #1
7 4025
tlhintoq
3,525 Expert 2GB
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 :
Expand|Select|Wrap|Line Numbers
  1. Error 1 Invalid preprocessor expression D:\UWESA\trunk\source\uwesa_web_CS\Properties\MyEx tensions\MyWebExtension.cs 26 16 uwesa_web
  2. 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
  3. 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
  4. 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_web_CS\Properties\MyEx tensions\MyWebExtension.cs 37 107 uwesa_web
Apr 11 '10 #2
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.
Apr 11 '10 #3
tlhintoq
3,525 Expert 2GB
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}tensions"

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 'ThreadSafeObjectProvider'
that exists at the path provided of
D:\UWESA\trunk\source\uwesa_web_CS\Properties\MyEx tensions\MyWebExtension.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.
Apr 11 '10 #4
tlhintoq
3,525 Expert 2GB
You also have four line of C# that are expressly using VB objects
Expand|Select|Wrap|Line Numbers
  1.             private static ThreadSafeObjectProvider<Microsoft.VisualBasic.Devices.ServerComputer> s_Computer = new ThreadSafeObjectProvider<Microsoft.VisualBasic.Devices.ServerComputer>();
  2.             private static ThreadSafeObjectProvider<Microsoft.VisualBasic.ApplicationServices.WebUser> s_User = new ThreadSafeObjectProvider<Microsoft.VisualBasic.ApplicationServices.WebUser>();
  3.             private static ThreadSafeObjectProvider<Microsoft.VisualBasic.Logging.AspLog> s_Log = new ThreadSafeObjectProvider<Microsoft.VisualBasic.Logging.AspLog>();
  4.             /// <summary>
  5.             /// Returns information about the host computer.
  6.             /// </summary>
  7.             [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
  8.             internal static Microsoft.VisualBasic.Devices.ServerComputer Computer
  9.  
Have you provided references in your C# code to VIsual Basic? It's perfectly legal to use some VB in your C# application.
Apr 11 '10 #5
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.
Apr 11 '10 #6
The path exists and there is no space.It maybe a problem of this forum's copy/paste functionality.
Apr 11 '10 #7
tlhintoq
3,525 Expert 2GB
Did you create a reference in your C# project to Microsoft.VisualBasic?
Apr 11 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Trying_Harder | last post by:
Is it possible to redefine a macro with global scope after undefining it in a function? If yes, could someone explain how? /If/ my question above isn't very clear you can refer to the...
4
by: Jim Ford | last post by:
I have a single C file with the following code: int f2() { /* Blah-blah */ } int f1() { /* Blah-blah */
13
by: seemanta dutta | last post by:
Greetings C gurus, I have used preprocessor directives since a very long time. But whenever I see some professional piece of C code, the linux kernel for example, I get literally confused by the...
5
by: Water Cooler v2 | last post by:
Sorry if this is a foolish question, but here it is. I see things like #ifndef STDC ...blah #endif #ifdef WIN32
2
by: Christopher Ireland | last post by:
Hello, I'm looking for a C# Preprocessor (shareware with source, if possible) which has the functionality of preprocessors which already exist in other languages, e.g. ...
6
by: Urs Thuermann | last post by:
Does a tool exist to apply C preprocessor expansion to a C source only partially, i.e. replace only some directives? I want to replace some #if's by their expansions, e.g. all #ifdef SOME_SYMBOL,...
21
by: Bogdan | last post by:
Can anyone recommend a program for indentation of C preprocessor directives. My file looks like this: #ifdef a #define b #else #define c #endif int main() {
31
by: Sam of California | last post by:
Is it accurate to say that "the preprocessor is just a pass in the parsing of the source file"? I responded to that comment by saying that the preprocessor is not just a pass. It processes...
9
by: Bob | last post by:
Hi, Is it possible to change the references in a project by using preprocessor directives? Thanks, Bob
14
by: lagman | last post by:
All, I'm looking for a tool that is able to take my code base (which is full of preprocessor directives) and spit out source code that is "clean" of any preprocessor directives based on the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.