none
VB.NET Project Compile Problem in VS.NET 2017 RRS feed

  • Question

  • Hi,

    My project was always good in Visual Studio .NET 2010 and 2012 Professional.

    Since last week that I completely removed 2010 and 2012 and migrated to 2017 one of my VB.NET Projects in .NET Framework 4.0 WILL NOT COMPILE !!!

    I get a new error:

    BC36595 Method cannot contain both a 'On Error Resume Next' statement and a definition of a variable that is used in a lambada or query expression.

    Nothing seems wrong to me except that at the end of Sub which starts with On Error Resume Next this code is written:

    Dim Threads As New Thread(New ParameterizedThreadStart(AddressOf MyThread))
    Threads.Start()

    This is for sure a new error in VS.NET 2017, please, please, please don't advise me to cease using On Error Resume Next.

    I already know it should not be used, but for that part I have a reason to use and not to use Try/Catch.

    So please someone just help me bypass this error, disable VS.NET 2017 Professional to not to show just this error.

    It must have a way, I believe.

    Thanks everyone :)

    Friday, May 26, 2017 9:32 PM

All replies

  • Hi OSVBNET,

    Welcome to the MSDN forum.

    Refer to your description, your issue is about the VB development. Since our forum is to discuss the VS IDE, I will help you move this thread to the appropriate forum: Visual Studio Languages  >  Visual Basic to seek for a more professional support, thank you for your understanding.

    Best regards,

    Sara


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 29, 2017 2:01 AM
  • Let's see the code and please use the code button.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, May 29, 2017 2:14 AM
    Moderator
  • This error is listed in the documentation of older Visual Studio, therefore it does not seem to be added recently. Perhaps you made some changes after switching to new Visual Studio.

    Monday, May 29, 2017 5:24 AM
  • No you must not use a Try and Catch to put your head in the sand like an Ostrich to avoid handling errors. It is as bad as using On Error Resume Next. 

    But this kind of code still goes, in VS2017

    Be aware mostly it is good code trying to let your boss fired (and of course you following him/her)

     
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim CustomerSaldo = 100
            Dim CustomerReliability = 0
            Dim PaybackMoney = 10000
            On Error Resume Next
            PaybackMoney = CustomerSaldo \ CustomerReliability * 100
            DoBankSendingMoney(PaybackMoney)
        End Sub
        Private Sub DoBankSendingMoney(Money As Integer)
            'a method to send money to they customer
        End Sub
    End Class


    Success
    Cor


    Monday, May 29, 2017 8:09 AM
  • Thanks all, as I as suspect the error is from calling Thread:

    Private Sub SendButtonX_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendButtonX.Click
        On Error Resume Next
        '...code
        Dim Threads As New Thread(New ParameterizedThreadStart(AddressOf MyThread))
        Threads.Start()
    End Sub

    On Error Resume Next cannot be used when Thread is called like above.

    I don't want to change the code, how can I suppress the error by VS and compile? Do I have to get back to VS.NET 2010 ?!


    • Edited by OSVBNET Monday, May 29, 2017 10:29 AM
    Monday, May 29, 2017 10:28 AM
  • Thanks all, as I as suspect the error is from calling Thread:

    Private Sub SendButtonX_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendButtonX.Click
        On Error Resume Next
        '...code
        Dim Threads As New Thread(New ParameterizedThreadStart(AddressOf MyThread))
        Threads.Start()
    End Sub

    On Error Resume Next cannot be used when Thread is called like above.

    I don't want to change the code, how can I suppress the error by VS and compile? Do I have to get back to VS.NET 2010 ?!


    Why do you write so much nonsense. Did you try where you changed your code. \

    Be aware this is awfull bad fore those who find it.

    Imports System.Threading
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim newThread As New Thread(AddressOf DoBankSendingMoney)
            Dim CustomerSaldo = 100
            Dim CustomerReliability = 0
            Dim PaybackMoney = 10000
            On Error Resume Next
            PaybackMoney = CustomerSaldo \ CustomerReliability * 100
            newThread.Start()
        End Sub
        Private Sub DoBankSendingMoney(Money As Object)
            Dim x = CInt(Money)
            'a method to send money to they customer
        End Sub
    End Class
    Be aware this is awfull bad fore those who find it.

    But it runs.


    Success
    Cor

    Monday, May 29, 2017 10:54 AM
  • I could never figure out why anyone would use On Error resume next, at least until the code has been tested over and over, stressed and retested. Better to try to avoid the possibility of an error then to try to cover it up.
    Tuesday, May 30, 2017 12:42 AM
  • Hi,

    Thanks but this one also does not work:

    Private Sub SendButtonX_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendButtonX.Click
    'Thread
    Dim Threads As New Thread(New ParameterizedThreadStart(AddressOf MyThread))
    On Error Resume Next
    Threads.Start()
    End Sub

    Tuesday, May 30, 2017 7:20 PM
  • Hi OSVBNET,

    Can you share your target framework here, you can find it from Project---properties---Application---target framework.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, June 1, 2017 2:49 AM
    Moderator
  • .NET Framework 4.0 Full

    I'm really confused, how a code is compiling on all previous version of Visual Studio but now is NOT.

    Please give me a way to suppress error and compile without switching to VS.NET 2010?



    • Edited by OSVBNET Friday, June 2, 2017 1:49 PM
    Friday, June 2, 2017 1:41 PM
  • How should we do that, the code you show works for everybody here in Visual Studio 2017, we even made samples for you. 

    The only thing you go on telling is that it does not work for you. 

    Did you copy for instance my sample. It is only 20 lines of copy, I think it is not to much to create a project to test it, to run it and then see what happens. 

    Then we can maybe help you if that fails. 


    Success
    Cor

    Friday, June 2, 2017 2:09 PM
  • Have you tried handling the exception in the thread MyThread rather than by the calling code?

    The only way to catch and suppress the exception is to wrap you code in a Try/Catch but as it should doubt the reason for the exception will be known in the caller as it should be.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, June 2, 2017 4:46 PM
    Moderator
  • I just re-installed a clean copy of my Windows 10 x64 Enterprise + Latest Drivers + VS.NET 2010 Pro SP1 and VS.NET 2017 Pro!

    Now, still have the same problem, code compiles on VS.NET 2010 but not on VS.NET 2017!

    Can I make a small sample project for you to test?

    Monday, June 5, 2017 3:04 PM
  • I just re-installed a clean copy of my Windows 10 x64 Enterprise + Latest Drivers + VS.NET 2010 Pro SP1 and VS.NET 2017 Pro!

    Now, still have the same problem, code compiles on VS.NET 2010 but not on VS.NET 2017!

    Can I make a small sample project for you to test?

    Yes, and simply show it. I did it already for you. Did you test that by the way?

    Success
    Cor

    Monday, June 5, 2017 5:20 PM
  • Jesus, it was very easy to reproduce the error, however I made a sample project, very easy.

    1. Once run with VS.NET 2010 > Build > Clean > Rebuild

    2. Then run with VS.NET 2017 > Build > Clean > Rebuild

    2010 compiles very well, 2017 returns ERROR and cannot compile:

    Error BC36595 : Method cannot contain both a 'On Error Resume Next' statement and a definition of a variable that is used in a lambda or query expression.

    I cannot believe my code is WRONG when it was correctly compiling in VS.NET 2010, 2012, 2013, 2015.

    And now does not compile in 2017 and my code is wrong?

    I already switched back to VS.NET 2010, and I hope this bug is fixed soon.

    http://www.tamkish.com/BugSample.rar

    PLEASE :: Vote for my BUG Report if you can repro it here:

    https://connect.microsoft.com/VisualStudio/feedback/details/3135586

    • Edited by OSVBNET Friday, June 9, 2017 11:15 AM
    Friday, June 9, 2017 11:02 AM

  • 2010 compiles very well, 2017 returns ERROR and cannot compile:

    Error BC36595 : Method cannot contain both a 'On Error Resume Next' statement and a definition of a variable that is used in a lambda or query expression.

    I cannot believe my code is WRONG when it was correctly compiling in VS.NET 2010, 2012, 2013, 2015.

    And now does not compile in 2017 and my code is wrong?

    Yep. Your code is wrong.

    You are working with Option Strict turned off, so you are asking the compiler to fix your broken code for you, and up till now you've been 'lucky'.

    Turn Option Strict On, and fix the real error:

    Error    BC36663    Option Strict On does not allow narrowing in implicit type conversions between method 'Private Sub SendThread()' and delegate 'Delegate Sub ParameterizedThreadStart(obj As Object)'. 

    Then your code should compile and run.

    BTW:  the sample you included is for VB2010, which you say has no bugs. Won't that make it hard for people to find the bugs?...


    • Edited by S P C Friday, June 9, 2017 11:59 AM
    Friday, June 9, 2017 11:58 AM
  • A vote here is a vote for helpful, no Microsoft developers are watching this forum. 

    Therefore click in Visual Studio 2017 on Help -> Send feed back and report 

    Or visit the website

    http://connect.microsoft.com

    Be aware, probably most persons who visit this thread and are knowledged in VB for Net will tell that your code is very buggy. 


    Success
    Cor

    Friday, June 9, 2017 12:11 PM
  • Hi,

    My project was always good in Visual Studio .NET 2010 and 2012 Professional.

    Since last week that I completely removed 2010 and 2012 and migrated to 2017 one of my VB.NET Projects in .NET Framework 4.0 WILL NOT COMPILE !!!

    I get a new error:

    BC36595 Method cannot contain both a 'On Error Resume Next' statement and a definition of a variable that is used in a lambada or query expression.

    Nothing seems wrong to me except that at the end of Sub which starts with On Error Resume Next this code is written:

    Dim Threads As New Thread(New ParameterizedThreadStart(AddressOf MyThread))
    Threads.Start()

    This is for sure a new error in VS.NET 2017, please, please, please don't advise me to cease using On Error Resume Next.

    I already know it should not be used, but for that part I have a reason to use and not to use Try/Catch.

    So please someone just help me bypass this error, disable VS.NET 2017 Professional to not to show just this error.

    It must have a way, I believe.

    Thanks everyone :)

    Hi

    Not following this thread, but, what possible reason could you have for trying to bury errors? It would make things a lot more straightforward for you if you deal with errors in a 'graceful' way by (perhaps) trapping errors and show a MessageBox with error message - at least until you have eliminated the errors.

    For example, looking at the code posted by Cor which I am assuming is your code from another thread, one thing worth mentioning would be the very high probability of a Divide by Zero error occurring and which you have decided it is best to ignore totally by the Resume Next statement above that line. This is not a real fix as the problem is then passed on by paying back 1000 to the customer - I can only hope I buy something from you in the future.


    Regards Les, Livingston, Scotland

    Friday, June 9, 2017 1:13 PM
  • @Les,

    The OP of this thread is a funny person, he or she wrote. 

    I already know it should not be used, but for that part I have a reason to use and not to use Try/Catch.

    Seems to be very secret and still he/she ask help in this forum. It is of course for all of us very worrying because probably nobody of us know what it can be and become afraid that they always did it wrong. 

    And you know, most of us are active here to learn new things. 


    Success
    Cor

    Friday, June 9, 2017 2:33 PM
  • Thanks everyone and also thank you Cor for your input josh!

    Can someone please let me know what is the corrected code?

    Since it's just a few lines of code, it should not be hard to paste the right one here?!

    Thanks for the advise.

    Peace.


    • Edited by OSVBNET Friday, June 9, 2017 2:50 PM
    Friday, June 9, 2017 2:49 PM
  • @Les,

    The OP of this thread is a funny person, he or she wrote. 

    I already know it should not be used, but for that part I have a reason to use and not to use Try/Catch.

    Seems to be very secret and still he/she ask help in this forum. It is of course for all of us very worrying because probably nobody of us know what it can be and become afraid that they always did it wrong. 

    And you know, most of us are active here to learn new things. 


    Success
    Cor

    Well since you guys are so perplexed maybe I will tell you my old projects all have on error resume next in most every sub especially events that dont have another handler in the calling sub.

    To this day I have not bothered removing them as it still works.

    Also, does try catch have resume next?

    Seems last I tried I could not find it but maybe you guys or gals know?

    There are times when I just want to resume next after divide by zero because the rest of the code continues with zero there. So again another change another debug I dont want to do. It runs I dont want to change it now unless there is a problem or I am working on it already.

    Other times its much easier one line and does the job.

    :)


    Friday, June 9, 2017 3:31 PM
  • Thanks Tommy, usually people cannot accept the others do something else than what they think is right...
    Friday, June 9, 2017 3:47 PM
  • Also, does try catch have resume next?

    No - intentionally not.

    The concept behind structured exception handling is that you can catch different types of exceptions and handle each differently. For example:

        Private Sub SomeMethod()
    
            Try
                ' Code that does something...
    
            Catch ex As IO.IOException
                ' Handle this one way: Maybe fail your program
                ' because it probably can't continue.
    
            Catch ex As Exception
                ' Maybe you decide that if it's not an IO
                ' exception, you just log it.
            End Try
    
        End Sub

    You might think that's pointless if it won't "resume next" but it's not. You can structure your code to manage it.

    For instance, if you're in a loop and an exception is thrown - lights out. The loop ends.

    However, if in the loop you send (whatever it does) to a function and maybe in that function you have the exception handling. If it fails it returns null so on the way back in, you test the return value and continue on.

    The loop didn't throw an exception, per se; the function did and you handled that exception there.


    "A problem well stated is a problem half solved.” - Charles F. Kettering


    Friday, June 9, 2017 4:04 PM
  • I know that you wrote you cannot accept a way that others think which is right, but then at least a reply to Tommy.

    I think that it is better to avoid that something is stolen than a long run behind a thief and get things back. Yea we can have others opinions but that is just my way of thinking. 

    So for your divide by zero I prefer

            Dim a = 1
            Dim b = 0
            Dim c = 0
            If b <> 0 Then
                c = a \ b
            Else
                'do what you should do to take a proper action even if that is ignore. 
                'but at last write then here why you do that. 
            End If

    And if it is impossible to do that a Try Catch and handle then if possible the reason why it throws an exception. 

    I know there are cases where that is impossible and one where it is not even possible to catch an error (also no resume on next), which is with a try of a write inside an hidden folder. Even then I would do

            Try
                The IO handling which can be more than one line
            Catch ex As Exception
                'The method gives an exception which is not catched by the OS 
            End Try

    However, I know there are persons who have their gold outside before their door and are complaining then that it is stolen and want to punish the thief. Whatever, do it but please don't let the society pay for prosecuting the thief.


    Success
    Cor



    Friday, June 9, 2017 4:10 PM
  • Thanks Tommy, usually people cannot accept the others do something else than what they think is right...

    Well we get lots of things here and many times just don't understand it and want to know the details. Every question is a puzzle and many are left half answered for the puzzle players.

    Also try to give the "latest" info etc.

    Friday, June 9, 2017 4:20 PM
  • Cor,

    I see. 

    Plus in my world many times its something like:

       Dim tolerance as double = 0.000001

       If x > -tolerance andalso < tolerance then

       end if

    Or tolerance = f(x) and on and on.

    Still, one day someone calls and says when I do this it does that...


    Friday, June 9, 2017 4:32 PM
  • Oh, duh, thanks Frank too!

    Friday, June 9, 2017 4:35 PM
  • Thanks everyone and also thank you Cor for your input josh!

    Can someone please let me know what is the corrected code?

    Since it's just a few lines of code, it should not be hard to paste the right one here?!

    Thanks for the advise.

    Peace.


    OS,

    Well I will make a guess. It seems you cant use on error with this thread code?? So remove it? Then what happens? Or did I miss that part? Make any other changes Option Strict shows.

             Try
    
                '...code
                Dim Threads As New Thread(New ParameterizedThreadStart(AddressOf MyThread))
                Threads.Start()
    
            Catch ex As Exception
                'show error msg or something
            End Try

    PS Oh I see I got mixed up that's what Cor showed you. Sorry, I thought it was something else.



    Friday, June 9, 2017 4:56 PM