Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix copy to clipboard option (+ UX feedback) #457

Closed
InteXX opened this issue Dec 9, 2019 · 10 comments
Closed

Fix copy to clipboard option (+ UX feedback) #457

InteXX opened this issue Dec 9, 2019 · 10 comments
Assignees
Labels
UX feedback More subjective, feedback related to specific use case

Comments

@InteXX
Copy link

InteXX commented Dec 9, 2019

Steps to reproduce

  1. Attempt to convert from C# -> VB

     using System.Drawing;
     using System.Windows.Forms;
    
     namespace SpaceInvaders
     {
       class Enemies
       {
         private readonly int columns;
         private readonly int height;
         private readonly int width;
         private readonly int space;
         private readonly int rows;
         private int x;
         private int y;
    
         public Enemies()
         {
           columns = 10;
           height = 40;
           width = 40;
           space = 10;
           rows = 5;
           x = 150;
           y = 0;
         }
    
         private void CreateControl(Form p)
         {
           PictureBox pb = new PictureBox
           {
             Location = new Point(x, y),
             Size = new Size(width, height),
             BackgroundImage = Properties.Resources.Invader,
             BackgroundImageLayout = ImageLayout.Stretch,
             Name = "Alien"
           };
           p.Controls.Add(pb);
         }
    
         public void CreateSprites(Form p)
         {
           for (int i = 0; i < rows; i++)
           {
             for (int j = 0; j < columns; j++)
             {
               CreateControl(p);
               x += width + space;
             }
             y += height + space;
             x = 150;
           }
         }
       }
     }
    

Error message shown

Failure processing VB\Enemies.cs
System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.VisualBasic.Syntax.CompilationUnitSyntax' to type 'Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode'.
at ICSharpCode.CodeConverter.VB.CSharpConverter.d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ICSharpCode.CodeConverter.VB.CSToVBConversion.d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ICSharpCode.CodeConverter.Shared.ProjectConversion.d__19.MoveNext()

Code conversion failed with 1 error

Please report issues at https://github.com/icsharpcode/CodeConverter/issues

Details

  • Product in use: VS extension
  • Version in use: 7.3.0
  • Did you see it working in a previous version? No
@GrahamTheCoder
Copy link
Member

Thanks for the bug report, from the error, it looks like you've perhaps missed the option to set the conversion direction.
Please try:

  1. Going to https://codeconverter.icsharpcode.net/
  2. Select "c# to VB.net
  3. Paste in your code
  4. Press the convert button

Let me know if that works for you. We might be able to make it more obvious or provide a better error message if that's the case.

@InteXX
Copy link
Author

InteXX commented Dec 9, 2019

Thanks, but I'm using the Visual Studio extension and right-clicking on a .cs file in the VB project.

@GrahamTheCoder
Copy link
Member

Interesting. Sounds like the commands may be mixed up in code - I'll check tomorrow!
In the meantime, you might find that one of the other menu items is working - e.g. right click on csproj or select all text in file and right click on selection

@GrahamTheCoder GrahamTheCoder self-assigned this Dec 9, 2019
@InteXX
Copy link
Author

InteXX commented Dec 9, 2019

FYI I got it to work just now by right-clicking a .cs file in a CS project. It's when I attempt to convert a .cs file in a VB project that it errs.

@InteXX
Copy link
Author

InteXX commented Dec 9, 2019

As usual, a user error uncovers a bug ;-)

@GrahamTheCoder
Copy link
Member

Oh wait I just reread that. A CS file in a VB project? Makes sense why it wouldn't work yeah. Presumably you only put it there right before conversion?
Would #245 make sense for your use case?

@InteXX
Copy link
Author

InteXX commented Dec 10, 2019

Presumably you only put it there right before conversion?

Yes, that's correct. Now that I know the proper workflow I won't be doing that again. Close or leave open this ticket at your discretion.

Would #245 make sense for your use case?

Close, but not quite.

@InteXX
Copy link
Author

InteXX commented Dec 10, 2019

FYI I get a MessageBox error after converting while Copy result to clipboard is enabled:

An error has occured during conversion: System.Threading.ThreadStateException: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made.
at System.Windows.OleServicesContext.SetDispatcherThread()
at System.Windows.OleServicesContext.get_CurrentOleServicesContext()
at System.Windows.Clipboard.CriticalSetDataObject(Object data, Boolean copy)
at System.Windows.Clipboard.SetDataInternal(String format, Object data)
at System.Windows.Clipboard.SetText(String text, TextDataFormat format)
at System.Windows.Clipboard.SetText(String text)
at CodeConverter.VsExtension.CodeConversion.d__14`1.MoveNext() in D:\GitWorkspace\CodeConverter\Vsix\CodeConversion.cs:line 69
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at CodeConverter.VsExtension.ConvertCSToVBCommand.d__24.MoveNext() in D:\GitWorkspace\CodeConverter\Vsix\ConvertCSToVBCommand.cs:line 186

The conversion was successful, however.

This time it's all in the CS project. I didn't try it in the VB project, but I imagine it wouldn't even get that far due to the previous error (whose output is shown in the Output window).

@GrahamTheCoder
Copy link
Member

Ah yes, I'll leave this ticket open to track the error message box, should be an easy fix.

Was the original workflow you tried your ideal one, or just how you thought the tool might work?
Any other context might help improve things. For example, where did the Cs file come from, was it previously in a csproj locally, or copied from somewhere online?
Theoretically the best way to convert is always in the project the file comes from since it'll have any references or types from other files available. But obviously that's not always possible or convenient. I'm hoping to guide people towards that ideal but allow them other sensible options where it's not appropriate.

@InteXX
Copy link
Author

InteXX commented Dec 10, 2019

Was the original workflow you tried your ideal one, or just how you thought the tool might work?

The latter.

where did the Cs file come from, was it previously in a csproj locally, or copied from somewhere online?

The former.

Any other context

Hm, not that I can think of.

the best way to convert is always in the project the file comes from since it'll have any references or types from other files available

Ah, I see. I wasn't aware that anything external to the file being processed was evaluated. I guess I was thinking of it in the context of yours or Telerik's online converter—standalone.

@GrahamTheCoder GrahamTheCoder changed the title C# -> VB Conversion Fails Fix copy to clipboard option (+ UX feedback) Dec 13, 2019
@GrahamTheCoder GrahamTheCoder added the UX feedback More subjective, feedback related to specific use case label Dec 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
UX feedback More subjective, feedback related to specific use case
Projects
None yet
Development

No branches or pull requests

2 participants