-
Apr 3rd, 2024, 11:13 AM
#1
Thread Starter
Member
[RESOLVED] Suddden errors when trying to build
Hi,
I have a visual basic application that I've been working on for a while now, it has been published and working fine but I wanted to make a couple of changes to it and all of a sudden I'm getting some errors when trying to run it in VS 2022.
I'm ot errors wherever I used the Try and Catch method, I had used
Code:
Catch ex as Exception
but I started to get errors so had to put "System" in front of it to clear those errors.
Code:
Catch ex as system.Exception
I'm also getting an error when I use

Which I've used without any issues in all my projects and this one.
I've probably made a mistake with something somewhere as these errors have all appeared out of the blue and I don't know how to fix them.
My project uses .NET Framework 4.8
Any help would be greatly appreciated.
Last edited by gadjet; Apr 3rd, 2024 at 11:14 AM.
Reason: typo
-
Apr 3rd, 2024, 12:26 PM
#2
Re: Suddden errors when trying to build
The screenshot has an option "Show Potential Fixes", did you try clicking that? If so it would have either suggested the full class name, or adding an Imports statement to the top of the source file.
https://learn.microsoft.com/en-us/do...space-and-type is probably worth a read.
-
Apr 3rd, 2024, 12:51 PM
#3
Re: Suddden errors when trying to build
Yeah, those recommendations are going to be right, in this case. The first one is just a missing Imports statement. The second one is probably slightly more complicated, as it is likely that there are two objects called Application, and the compiler is just choosing the wrong one. An Imports statement might fix it, or fully decorating the object.
My usual boring signature: Nothing
 
-
Apr 3rd, 2024, 01:50 PM
#4
Thread Starter
Member
Re: Suddden errors when trying to build
 Originally Posted by Shaggy Hiker
Yeah, those recommendations are going to be right, in this case. The first one is just a missing Imports statement. The second one is probably slightly more complicated, as it is likely that there are two objects called Application, and the compiler is just choosing the wrong one. An Imports statement might fix it, or fully decorating the object.
I thought it would be an imports issue but I haven't made any changes to any Imports that's why I'm struggling to figure it out, is there any particular Imports it could be?
-
Apr 3rd, 2024, 03:19 PM
#5
Re: Suddden errors when trying to build
As the reasonably humid one said, you should have a lightbulb appear if you click on (or maybe hover over) the error. If it's just an imports issue, then the first option offered will be to import the right thing.
My usual boring signature: Nothing
 
-
Apr 3rd, 2024, 03:24 PM
#6
Thread Starter
Member
Re: Suddden errors when trying to build
 Originally Posted by Shaggy Hiker
As the reasonably humid one said, you should have a lightbulb appear if you click on (or maybe hover over) the error. If it's just an imports issue, then the first option offered will be to import the right thing.
No sorry, the lightbulb didn't offer any solutions
-
Apr 3rd, 2024, 03:29 PM
#7
Re: Suddden errors when trying to build
Well, if Exception is an issue, and System.Exception is not, then either Imports System would be the imports, or something else is going on. What that other thing is would most likely be that you are using a library that ALSO has an object called Exception, such that the compiler can't decide which version of Exception to use. In that case, just writing System.Exception tells the compiler exactly which object to use. Usually, you can leave off that explicit direction, because the compiler will know. However, if there is any question, then you have to be clear, and there is no cost to doing so, aside from being a bit more typing.
My usual boring signature: Nothing
 
-
Apr 3rd, 2024, 03:37 PM
#8
Thread Starter
Member
Re: Suddden errors when trying to build
 Originally Posted by Shaggy Hiker
Well, if Exception is an issue, and System.Exception is not, then either Imports System would be the imports, or something else is going on. What that other thing is would most likely be that you are using a library that ALSO has an object called Exception, such that the compiler can't decide which version of Exception to use. In that case, just writing System.Exception tells the compiler exactly which object to use. Usually, you can leave off that explicit direction, because the compiler will know. However, if there is any question, then you have to be clear, and there is no cost to doing so, aside from being a bit more typing.
Yes, I agree and that's how I fixed the exception issues by adding "System" in front but I still have the application errors but I haven't added anything new as far as applications go since the last time it worked, it does mention outlook in the error, I think this is causing the issue but I was using outlook in the previous version without this problem.
It looks like the compiler thinks when I use "Application" it's the outlook application but it's not it should be the application I've written, is there a way to test it by specifying the application?
-
Apr 4th, 2024, 01:57 AM
#9
Thread Starter
Member
Re: Suddden errors when trying to build
*** FIXED IT ***
I commented out "Imports Microsoft.Office.Interop.Outlook"
The thing is, I never added it !!
These were my Imports
Imports System.DirectoryServices.AccountManagement
Imports System.IO
Imports System
Imports System.IO.Compression
Imports System.Reflection
Imports System.Runtime.CompilerServices
Imports System.Runtime.Versioning
Imports System.Threading
Imports System.Windows.Forms.VisualStyles
Imports Microsoft.Office.Interop.Outlook
Imports Microsoft.VisualBasic.ApplicationServices
Imports Outlook = Microsoft.Office.Interop.Outlook
Last edited by gadjet; Apr 4th, 2024 at 02:05 AM.
Reason: Update information
-
Apr 11th, 2024, 11:53 AM
#10
Lively Member
Re: [RESOLVED] Suddden errors when trying to build
Perhaps you entered something without the Outlook alias before it, so VS added Microsoft.Office.Interop.Outlook to your Imports so you would not get an error. VS2022 does a lot of helpful things like that, but they aren't always helpful.
I've made it a habit to check my imports statements whenever I get sudden errors... it seems like a lot of the time I will have something automatically added after I mistyped or accidentally accepted the suggested autofill.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|