option strict

P

Poldie

How do I turn it on? I'm using vb 2005 in visual studio 2005 sp1.

In my web.config I have:

<compilation debug="true" strict="true" />

In my Tools/Options/Projects and solutions/vb defaults I have option
strict on.

In my .vb file I have:

Dim NiceBug As Boolean = "Hello world"

which happily compiles. Not so happy at runtime though.

I'd appreciate some advice as to how I get option strict enabled in my
projects without having to add it to every file manually.

And what exactly do the options I've described above actually affect?
 
J

Juan T. Llibre

re:
!> I'd appreciate some advice as to how I get option strict enabled in my
!> projects without having to add it to every file manually.

change the default value of Option Strict for VB.NET, follow these steps:

Locate WebApplication.vbproj, inside:
drive:\VStudioInstallDir\Common7\IDE\ProjectTemplates\VisualBasic\Web\1033\­WebApplicationProject.zip

Extract it, modify the Option Strict line so it's On, save the file
and add it back to the zip file, overwriting the original file.

Notice there's other files in the same zip file where the option must be set, too.

Also, do the same for any file in:
drive:\VStudioInstallDir\Common7\IDE\ProjectTemplates\VisualBasic\Web
which has Option Strict = Off

I agree that the IDE is buggy regarding the setting of this option,
but there's a viable workaround, as detailed in this post.

btw, if you want to change the Option Strict option for other types of projects
( Windows app, Windows Service, etc. ), you'll need to do the same for *their* templates.
 
P

Poldie

re:
!> I'd appreciate some advice as to how I get option strict enabled in my
!> projects without having to add it to every file manually.

change the default value of Option Strict for VB.NET, follow these steps:

Locate WebApplication.vbproj, inside:
drive:\VStudioInstallDir\Common7\IDE\ProjectTemplates\VisualBasic\Web\1033\­WebApplicationProject.zip

Extract it, modify the Option Strict line so it's On, save the file
and add it back to the zip file, overwriting the original file.

Notice there's other files in the same zip file where the option must be set, too.

Also, do the same for any file in:
drive:\VStudioInstallDir\Common7\IDE\ProjectTemplates\VisualBasic\Web
which has Option Strict = Off

I agree that the IDE is buggy regarding the setting of this option,
but there's a viable workaround, as detailed in this post.

btw, if you want to change the Option Strict option for other types of projects
( Windows app, Windows Service, etc. ), you'll need to do the same for *their* templates.

I'll give that a go, although it sounds like something which might
come into effect when I next create a new project rather than change
my existing one.

As I explained above, I've already changed my entry in web.config and
in the menu, so if your solution works, where is it changing the
setting, and can I not set it myself manually?

Cheers,
Poldie.
 
M

Mark Rae

As I explained above, I've already changed my entry in web.config and
in the menu, so if your solution works, where is it changing the
setting, and can I not set it myself manually?

Have you tried Tools, Options, Projects and Solutions, VB Defaults?

No idea if this will modify existing projects, though, as I never go
anywhere near VB.NET...
 
P

Poldie

Have you tried Tools, Options, Projects and Solutions, VB Defaults?
No idea if this will modify existing projects, though, as I never go
anywhere near VB.NET...

Yeah, I believe I explained that in my first post. I also tried in
web.config. Neither had any effect - only adding a line of text to
each file manually.
 
J

Juan T. Llibre

re:
!> Have you tried Tools, Options, Projects and Solutions, VB Defaults?
!> No idea if this will modify existing projects, though, as I never go anywhere near VB.NET...

It doesn't even change the setting for *new* projects, Mark.

re:
!> where is it changing the setting, and can I not set it myself manually?

There's no way to change the setting at design time, for new projects,
because the change is needed in the project *template*.

Devenv.exe creates a new project based on the existing templates,
and the default for that is option "strict= false".

Changing the option, in the template's web.config, is the only solution.

Btw, the directory location in my earlier post is either incorrect or was changed by SP1.

Instead of :
drive:\VStudioInstallDir\Common7\IDE\ProjectTemplates\VisualBasic\Web\1033\­WebApplicationProject.zip

The correct path is :
Drive:\VStudioInstallDir\Common7\IDE\ProjectTemplates\Web\VisualBasic\1033\WebApplication.zip

Extract web.config from that zip file, change <compilation debug="false" strict="false"
explicit="true" />
to <compilation debug="false" strict="true" explicit="true" />

and zip it up again, updating WebApplication.zip
That will automatically create/compile projects with that strict="true" configured.

And, btw, that's not behavior "by design". It's a bug.
 
M

Mark Rae

re:
!> Have you tried Tools, Options, Projects and Solutions, VB Defaults?
!> No idea if this will modify existing projects, though, as I never go
anywhere near VB.NET...

It doesn't even change the setting for *new* projects, Mark.

Really...? Then what on earth does that setting do...?
And, btw, that's not behavior "by design". It's a bug.

Thank God I use C#... :)
 
P

Poldie

re:
!> Have you tried Tools, Options, Projects and Solutions, VB Defaults?
!> No idea if this will modify existing projects, though, as I never go anywhere near VB.NET...

It doesn't even change the setting for *new* projects, Mark.

re:
!> where is it changing the setting, and can I not set it myself manually?

There's no way to change the setting at design time, for new projects,
because the change is needed in the project *template*.

Devenv.exe creates a new project based on the existing templates,
and the default for that is option "strict= false".

Changing the option, in the template's web.config, is the only solution.

Btw, the directory location in my earlier post is either incorrect or was changed by SP1.

Instead of :
drive:\VStudioInstallDir\Common7\IDE\ProjectTemplates\VisualBasic\Web\1033\­WebApplicationProject.zip

The correct path is :
Drive:\VStudioInstallDir\Common7\IDE\ProjectTemplates\Web\VisualBasic\1033\WebApplication.zip

Extract web.config from that zip file, change <compilation debug="false" strict="false"
explicit="true" />
to <compilation debug="false" strict="true" explicit="true" />

and zip it up again, updating WebApplication.zip
That will automatically create/compile projects with that strict="true" configured.

Ok pay attention! I've I explained earlier, I've already set my
web.config file, manually, with the appropriate text:

<compilation debug="true" strict="true" />

It's not having any effect. Therefore fiddling in zip files is going
to have the same effect next time I create a new project - no effect
whatsoever. The only thing which makes a difference is setting the
option at the top of each page. I appreciate that this isn't a
problem in c#, but this doesn't help me as I'm not developing in c#.
 
M

Mark Rae

Ok pay attention!

Oh dear... :)
It's not having any effect.

That's right - it won't have any effect - Juan has just explained to you why
that is...
Therefore fiddling in zip files is going to have the same effect next time
I create
a new project - no effect whatsoever.

No - "fiddling" in zip files is going to solve your problem for you because
you will be changing the templates from which new projects and pages are
created...

You need to actually do as Juan has suggested...
The only thing which makes a difference is setting the option at the top
of each
page

Which you will no longer have to do if you modify the template from which
the new pages are created...
 
J

Juan T. Llibre

re:
!> Ok pay attention! I've I explained earlier, I've already set my
!> web.config file, manually, with the appropriate text:

!> <compilation debug="true" strict="true" />

No. *You* pay attention. I've already explained it's a *bug*.
It's been fixed in VS 2005 SP1.

re:
!> It's not having any effect.

This isn't an ASP.NET bug. It's a VS 2005 bug.

Nothing you do, as far as ASP.NET configuration goes,
will affect the way VS 2005 compiles source files.

What you *can* do, and works, is install VS 2005 SP1.

*Then*, when you change Tools/Options/Projects and Solutions/VB Defaults to
option strict on, and you change the web.config to strict="true", and you add to a .vb file :

Dim NiceBug As Boolean = "Hello world"

....you will see that the VS 2005 IDE flags it as an error,
and suggests you change the line to : Dim NiceBug As Boolean = CBool("Hello world")

Never mind that the suggested change is bonkers, though. :)
At least it flags the error as an error which will not compile correctly.





re:
!> Have you tried Tools, Options, Projects and Solutions, VB Defaults?
!> No idea if this will modify existing projects, though, as I never go anywhere near VB.NET...

It doesn't even change the setting for *new* projects, Mark.

re:
!> where is it changing the setting, and can I not set it myself manually?

There's no way to change the setting at design time, for new projects,
because the change is needed in the project *template*.

Devenv.exe creates a new project based on the existing templates,
and the default for that is option "strict= false".

Changing the option, in the template's web.config, is the only solution.

Btw, the directory location in my earlier post is either incorrect or was changed by SP1.

Instead of :
drive:\VStudioInstallDir\Common7\IDE\ProjectTemplates\VisualBasic\Web\1033\­WebApplicationProject.zip

The correct path is :
Drive:\VStudioInstallDir\Common7\IDE\ProjectTemplates\Web\VisualBasic\1033\WebApplication.zip

Extract web.config from that zip file, change <compilation debug="false" strict="false"
explicit="true" />
to <compilation debug="false" strict="true" explicit="true" />

and zip it up again, updating WebApplication.zip
That will automatically create/compile projects with that strict="true" configured.

Ok pay attention! I've I explained earlier, I've already set my
web.config file, manually, with the appropriate text:

<compilation debug="true" strict="true" />

It's not having any effect. Therefore fiddling in zip files is going
to have the same effect next time I create a new project - no effect
whatsoever. The only thing which makes a difference is setting the
option at the top of each page. I appreciate that this isn't a
problem in c#, but this doesn't help me as I'm not developing in c#.
 
P

Poldie

re:
!> Ok pay attention! I've I explained earlier, I've already set my
!> web.config file, manually, with the appropriate text:

!> <compilation debug="true" strict="true" />

No. *You* pay attention. I've already explained it's a *bug*.
It's been fixed in VS 2005 SP1.

I've got SP1. At least, I installed it. Of course, Microsoft being
Microsoft, they don't bother to put "SP1" on the Help screen so I can
confirm this. I definitely sat around for over an hour waiting for
the service pack to do somthing, a few months ago. Perhaps it failed
silently though. Wouldn't surprise me.
This isn't an ASP.NET bug. It's a VS 2005 bug.

I can believe this.
Nothing you do, as far as ASP.NET configuration goes,
will affect the way VS 2005 compiles source files.

What you *can* do, and works, is install VS 2005 SP1.

*Then*, when you change Tools/Options/Projects and Solutions/VB Defaults to
option strict on, and you change the web.config to strict="true", and you add to a .vb file :

Dim NiceBug As Boolean = "Hello world"

...you will see that the VS 2005 IDE flags it as an error,
and suggests you change the line to : Dim NiceBug As Boolean = CBool("Hello world")

Well, no, it won't.
Never mind that the suggested change is bonkers, though. :)
At least it flags the error as an error which will not compile correctly.

That'll do me! I'm going to fiddle with the zip files in just a few
moments (after I've confirmed SP1 installed properly on my machine)
and see what happens. I guess I'll have to create a new project and
create new pages and cut and paste my code into them to take advantage
of the newly enabled status of `option strict`, right?
 
P

Poldie

Note: SP1 was installed on my system. So why isn't the `projects and
solutions` or web.config option having any effect?

I'll try the `fiddling with zip files` "solution" now, even though
you're saying I shouldn't have to, and see if that helps. If it does,
what is it changing, exactly? If it doesn't just add the text to the
top of my source files for me when I create them, and it doesn't set a
value in web.config, then what does it do?

Thanks for the help, by the way!
 
J

Juan T. Llibre

re:
!> Of course, Microsoft being Microsoft, they don't bother to
!> put "SP1" on the Help screen so I can confirm this.

Look in "Help", "About Microsoft Visual Studio".

It's not evident ( it's cutoff ), but if you click the "Copy Info" button,
and paste it into a text file, you'll see this :

"Microsoft Visual Studio 2005 - ENU Service Pack 1 (KB926601)"

That tells you SP1 installed successfully.

If you don't see that... you don't have SP1 installed.
 
J

Juan T. Llibre

re:
!> Note: SP1 was installed on my system.

OK...

!> So why isn't the `projects and solutions` or web.config option having any effect?

Maybe because SP1 doesn't work with "web projects" any more ?

Try creating a new "web site" ( either "HTTP" or "File system" -based ),
change Tools/Options/Projects and Solutions/VB Defaults to option strict on,
and change web.config to strict="true", and when you add to a .vb file :

Dim NiceBug As Boolean = "Hello world"

....you will see that the VS 2005 IDE flags it as an error,
and suggests you change the line to : Dim NiceBug As Boolean = CBool("Hello world")
 
P

Poldie

re:
!> Note: SP1 was installed on my system.

OK...

!> So why isn't the `projects and solutions` or web.config option having any effect?

Maybe because SP1 doesn't work with "web projects" any more ?

Try creating a new "web site" ( either "HTTP" or "File system" -based ),
change Tools/Options/Projects and Solutions/VB Defaults to option strict on,
and change web.config to strict="true", and when you add to a .vb file :

Dim NiceBug As Boolean = "Hello world"

...you will see that the VS 2005 IDE flags it as an error,
and suggests you change the line to : Dim NiceBug As Boolean = CBool("Hello world")


I do have SP1 installed.

I created a brand new web application and dragged the files from my
old `web site` into it, and after some fiddling and confusion and
surfing I think I'm up and running again. I have a solution file now,
and a .designer.vb file for each page of my app. (I'm not quite sure
what the point of the .designer.vb file is as the `design` of the page
is in the .aspx file.) I notice that I no longer have an `app_code`
and `app_data` folder, but as my app is working I won't worry about
that.

I also have option strict on. (In fact, now I can't turn it off, but
I'll worry about that when I need to!)

Microsoft certainly seems to have angered and confused a lot of people
with all this `in 2003, not in 2005, in an add-on, finally in a SP but
uninstall stuff in the right order or else!` business but perhaps
they've got there in the end. I wonder if they'll remove the `web
site` style in the next release?

Thanks for the help.
 
M

Mark Rae

I wonder if they'll remove the `web site` style in the next release?

It wouldn't bother me one bit if they did, but apparently it's here to
stay...

There was a thread about this a few months ago...
 
J

Juan T. Llibre

re:
!> I created a brand new web application and dragged the files from my
!> old `web site` into it, and after some fiddling and confusion and
!> surfing I think I'm up and running again. I also have option strict on.

That's good to know.

re:
!> I'm not quite sure what the point of the .designer.vb file
!> is as the `design` of the page is in the .aspx file.

The .designer files contain the field declarations for the controls in the .aspx page.
It's auto-generated, so you don't have to write the declarations manually.

re:
!> Thanks for the help.

You're quite welcome. I'm glad to know you're up and running again.
 
P

Poldie

re:
!> I created a brand new web application and dragged the files from my
!> old `web site` into it, and after some fiddling and confusion and
!> surfing I think I'm up and running again. I also have option strict on.

That's good to know.

re:
!> I'm not quite sure what the point of the .designer.vb file
!> is as the `design` of the page is in the .aspx file.

The .designer files contain the field declarations for the controls in the .aspx page.
It's auto-generated, so you don't have to write the declarations manually.

But I wasn't writing any declarations before, in the web site model,
when I just had an .aspx and .aspx.vb for each page!

Another quirk was that when I dragged my files from my web site folder
the the solution explorer in the web application project, one of them
wasn't processed properly and I had to make a few changes. They were
pretty simple changes but it was confusing for me because this is my
first asp.net project. It's been a confusing few weeks, really, with
me trying to get to grips with the web development model in general,
asp.net 2.0 sp1 and the fact that most of the books and sites out
there are for some earlier (or later, in a few cases) versions of
asp.net. I'm getting there, but I've got a mountain of books and
printouts to get through!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top