I have recently switched from a c# team to a vb.net team. One of the things I have not been able to find an answer to is the differences in compile error / options. Let me explain.
In C# i will, using default settings, get a compile time error when trying to pass in an invalid type to a templated class like below. Here I create an Animal with a string type and afterwards I pass in a datetime which results in an compile error.
IAnimal<string> animal = new Animal<string>();
animal.SetTrainer(DateTime.Now);
I know I will get the same compile time error in vb.net with "Option Strict". There is, however, a lot of legacy (VB) code in the same file that will not compile with "Option Strict". What options do I have. Im thinking this:
Thanks in advance
Double click your Project -> My Project.
Goto Compile and look for Warningconfiguration
Now you can change some settings.
don't make them errors but warnings.
That won't make compile time errors but you can at least see some warnings.
Another solution would be to make your class a partial class and move your code to a new file. You can set Option Strict / Option Explicit on a per file basis.
Switch to "Option Strict" and fix all errors. Will take some time and may break working code.
Yes, do that. It will help you remain sanity.
Most errors that will pop up are probably simple casting issues, which are easy to fix (a CInt
here, a ToString()
there...).
You don't have to fix your whole solution or project at once, since you can enable Option Strict On
at file level. Make it a good habbit to fix every file as you have to touch it.
This will not always be possibly, but you can also just move code that heavily relies on Option Strict On
(e.g. COM
stuff) to another file without breaking changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With