question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

#region preprocessor directives not converted

See original GitHub issue

Sorry, my friend, this is very interesting project to me, because I write in rare lang VB.NET, but any call your converter induce error below. This is input C# code for call this issue ( from wordwide C# example “contoso university”).


#define Final // or Intro

#if Intro
#region snippet_Intro
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;

namespace ContosoUniversity.Models
{
    public class Course
    {
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int CourseID { get; set; }
        public string Title { get; set; }
        public int Credits { get; set; }

        public ICollection<Enrollment> Enrollments { get; set; }
    }
}
#endregion

#elif Final
#region snippet_Final
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace ContosoUniversity.Models
{
    public class Course
    {
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        [Display(Name = "Number")]
        public int CourseID { get; set; }

        [StringLength(50, MinimumLength = 3)]
        public string Title { get; set; }

        [Range(0, 5)]
        public int Credits { get; set; }

        public int DepartmentID { get; set; }

        public Department Department { get; set; }
        public ICollection<Enrollment> Enrollments { get; set; }
        public ICollection<CourseAssignment> CourseAssignments { get; set; }
    }
}
#endregion
#endif


---------------------------
Microsoft Visual Studio
---------------------------
Convert C# to VB:

Selected C# code seems to have errors or to be incomplete:



----- Exception 1 of 1 -----

System.InvalidOperationException: Nullable object must have a value.
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at ICSharpCode.CodeConverter.VB.CSharpConverter.NodesVisitor.ConvertAndSplitAttributes(SyntaxList`1 attributeLists, SyntaxList`1& attributes, SyntaxList`1& returnAttributes)
   at ICSharpCode.CodeConverter.VB.CSharpConverter.NodesVisitor.VisitPropertyDeclaration(PropertyDeclarationSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.PropertyDeclarationSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
   at ICSharpCode.CodeConverter.VB.CSharpConverter.NodesVisitor.<VisitClassDeclaration>b__22_0(MemberDeclarationSyntax m)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at ICSharpCode.CodeConverter.VB.CSharpConverter.NodesVisitor.VisitClassDeclaration(ClassDeclarationSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
   at ICSharpCode.CodeConverter.VB.CSharpConverter.NodesVisitor.<VisitNamespaceDeclaration>b__20_0(MemberDeclarationSyntax m)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at Microsoft.CodeAnalysis.SyntaxList`1.CreateNode(IEnumerable`1 nodes)
   at ICSharpCode.CodeConverter.VB.CSharpConverter.NodesVisitor.VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.NamespaceDeclarationSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
   at ICSharpCode.CodeConverter.VB.CSharpConverter.NodesVisitor.<VisitCompilationUnit>b__14_1(MemberDeclarationSyntax m)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at Microsoft.CodeAnalysis.SyntaxList`1.CreateNode(IEnumerable`1 nodes)
   at ICSharpCode.CodeConverter.VB.CSharpConverter.NodesVisitor.VisitCompilationUnit(CompilationUnitSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
   at ICSharpCode.CodeConverter.VB.CSharpConverter.Convert(CSharpSyntaxNode input, SemanticModel semanticModel, Document targetDocument)
   at ICSharpCode.CodeConverter.VB.CSharpConverter.ConvertText(String text, MetadataReference[] references)


---------------------------
OK   
---------------------------

Also I start your project in source code and see a code line number with error. Please see below.

Error message:
----- Exception 1 of 1 -----

System.InvalidOperationException: Nullable object must have a value.
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at System.Nullable`1.get_Value()
   at ICSharpCode.CodeConverter.VB.CSharpConverter.NodesVisitor.ConvertAndSplitAttributes(SyntaxList`1 attributeLists, SyntaxList`1& attributes, SyntaxList`1& returnAttributes) in F:\Projects\CodeConverter-master\ICSharpCode.CodeConverter\VB\NodesVisitor.cs:line 523
   at ICSharpCode.CodeConverter.VB.CSharpConverter.NodesVisitor.VisitPropertyDeclaration(PropertyDeclarationSyntax node) in F:\Projects\CodeConverter-master\ICSharpCode.CodeConverter\VB\NodesVisitor.cs:line 431
   at Microsoft.CodeAnalysis.CSharp.Syntax.PropertyDeclarationSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
   at ICSharpCode.CodeConverter.VB.CSharpConverter.NodesVisitor.<VisitClassDeclaration>b__22_0(MemberDeclarationSyntax m) in F:\Projects\CodeConverter-master\ICSharpCode.CodeConverter\VB\NodesVisitor.cs:line 206
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at ICSharpCode.CodeConverter.VB.CSharpConverter.NodesVisitor.VisitClassDeclaration(ClassDeclarationSyntax node) in F:\Projects\CodeConverter-master\ICSharpCode.CodeConverter\VB\NodesVisitor.cs:line 206
   at Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
   at ICSharpCode.CodeConverter.VB.CSharpConverter.NodesVisitor.<VisitNamespaceDeclaration>b__20_0(MemberDeclarationSyntax m) in F:\Projects\CodeConverter-master\ICSharpCode.CodeConverter\VB\NodesVisitor.cs:line 180
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at Microsoft.CodeAnalysis.SyntaxList`1.CreateNode(IEnumerable`1 nodes)
   at Microsoft.CodeAnalysis.SyntaxList`1..ctor(IEnumerable`1 nodes)
   at Microsoft.CodeAnalysis.VisualBasic.SyntaxFactory.List[TNode](IEnumerable`1 nodes)
   at ICSharpCode.CodeConverter.VB.CSharpConverter.NodesVisitor.VisitNamespaceDeclaration(NamespaceDeclarationSyntax node) in F:\Projects\CodeConverter-master\ICSharpCode.CodeConverter\VB\NodesVisitor.cs:line 182
   at Microsoft.CodeAnalysis.CSharp.Syntax.NamespaceDeclarationSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
   at ICSharpCode.CodeConverter.VB.CSharpConverter.NodesVisitor.<VisitCompilationUnit>b__14_1(MemberDeclarationSyntax m) in F:\Projects\CodeConverter-master\ICSharpCode.CodeConverter\VB\NodesVisitor.cs:line 118
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at Microsoft.CodeAnalysis.SyntaxList`1.CreateNode(IEnumerable`1 nodes)
   at Microsoft.CodeAnalysis.SyntaxList`1..ctor(IEnumerable`1 nodes)
   at Microsoft.CodeAnalysis.VisualBasic.SyntaxFactory.List[TNode](IEnumerable`1 nodes)
   at ICSharpCode.CodeConverter.VB.CSharpConverter.NodesVisitor.VisitCompilationUnit(CompilationUnitSyntax node) in F:\Projects\CodeConverter-master\ICSharpCode.CodeConverter\VB\NodesVisitor.cs:line 118
   at Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
   at ICSharpCode.CodeConverter.VB.CSharpConverter.Convert(CSharpSyntaxNode input, SemanticModel semanticModel, Document targetDocument) in F:\Projects\CodeConverter-master\ICSharpCode.CodeConverter\VB\CSharpConverter.cs:line 33
   at ICSharpCode.CodeConverter.VB.CSharpConverter.ConvertText(String text, MetadataReference[] references) in F:\Projects\CodeConverter-master\ICSharpCode.CodeConverter\VB\CSharpConverter.cs:line 46

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
rlktradewrightcommented, Sep 7, 2020

@kathleenwest

Thanks for that, though it’s the opposite direction I’m concerned with VB to C#.

But you’re right: I should just comment out all the #Region and #End Region directives in the VB and then use a single regular expression search and replace to convert them in the C#. Since I can do that for an entire solution with one edit, it’s really not a problem. Still, it would nice not to have to do this…

1reaction
GrahamTheCodercommented, Feb 14, 2021

@kathleenwest oh dear, congratulations on the upgrade! ☺

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unity Preprocessor Directive Error?
I have another, older project, that I can use #regions, and #if statements in just fine, not really sure what changed or how...
Read more >
Preprocessor Directives in AL - Business Central
The different types of preprocessor directives in AL; conditional, regions, and pragmas and preprocessorSymbols setting.
Read more >
#if preprocessor directive incorrectly handles enclosed C# ...
I'm pretty sure this is by design. Once the compiler sees the #if !DEBUG it's going to be in an inactive region. Once...
Read more >
Preprocessing directives
Region directives group lines of source code but have no other effect on compilation. The entire group can be collapsed and hidden, or...
Read more >
C# - Preprocessor Directives
C Preprocessor Directives - The preprocessor directives give instruction to the compiler to preprocess the information before actual compilation starts.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found