Category Archives: dotNET

System.IO.Compression vs. file compression

A good clarification for me. One of the great and under-rated features of .NET 2.0 is the System.IO.Compression namespace which allows stream compression. But it’s important to understand that this is not file compression. For example, if you want to zip up multiple files, this is not the class for you. I will definitely use these classes where it makes sense, but I will continue to use the XCeed components for more full functioned zipping in .NET.

Don’t Forget: www.acehaid.org

Free online training for ASP.NET/VB.NET, sign up by Wednesday!!

From Brad McCabe’s blog

Free VB 2005 and ASP.NET Training

With the holiday’s coming lots of people have some extra time on their hands, with this in mind MSDN and Microsoft Learning got to together to give you something to do, free training!

We were trying to figure out what course to give away and decided to let you pick.  That’s right pick one of 6 courses about Visual Basic 2005 or 9 courses about ASP.NET 2.0.  In addition, after you have completed your free online course you will receive 30% off the price of the next one.

You have to hurry, the free code is only good until January 4th, 2006.  You don’t have to take your free class by then, but you have to sign up and select your class before that day.  You have 90 days from the time you sign up to do the course, but with spare time this holiday season why not do it now?

Visit http://msdn.microsoft.com/vstudio/learning/elearning_promo/ for all of the details and to get the free training code to sign up.



Don’t Forget: www.acehaid.org

VS2005 compiler has encountered a problem, do you want to report it?

This seems to happen occasionally when I type into the code while debugging. So I say Cancel, i.e. no, and the question keeps coming up over and over. So if I say “ok” I know I’m in trouble when I get the screen about “large sections of the file may be include”. This always ends in a hang. (No there are no 3rd party add-ins installed). And then I just have to give in and open up task manager and trash it. Or wait for it to finally time out, but then I get the error “The Vbc taks failed unexpectedly”. Well, 10 of those errors, in fact. What a pain. Oh well. I’m sure the fact that I’ve got this wierd application that I am moving from VS2003 to Vs2005 has something to do with it.

I can’t tell exactly what the pattern is, but it is certainly not a random act of nastiness.

Don’t Forget: www.acehaid.org

ClickOnce and Application Data Directories

The application that I am porting to VS2005 has off-line capabilities. In VS2003, after looking at a lot of options, I chose to store the data in the App folder of the All Users area in c:\directory and settings. One reason for this is that it is possible that a laptop will be passed off from one user to another and they need a common area that they can access. The other reason is that occasionally we might need to get at that data manually if there is a problem. This is the main reason why isolated storage was not an option.

I was able to get to this folder with

System.IO.Directory.GetParent(System.Windows.Forms.Application.CommonAppDataPath)

Not so in ClickOnce.

ClickOnce installs apps into a user’s local storage – (Directory and settings/user/local settings/apps). This means that on shared computers, there may be multiple copies of the application. I don’t like that and will see if there is a way around it since I am manually generating manifest files anyway, but I can live with it.

It also means that the above method returns the data directory defined by ClickOnce, which is inside of this install (rather, in the same parent folder). Not just that, but there will be a different one for each update of the application. This is bad bad bad (for my application).

You can read more about this here in the docs, online.

Even though the LocalSettings  folder is a safe folder as far as CAS is concerned, I don’t like the idea of hardcoding that file path (or making it a resource). But at this point, I think it’s going to be the solution. Bah!

Don’t Forget: www.acehaid.org

Talking about ADO.NET on ACADEMICDOTNET.com

Earlier this month, Matt Cassell interviewed me (with great questions) for his podcast show, www.AcademicdotNET.com that is aimed at highschool programmers.

Matt is himself in high school, but at 15, has still been programming a lot longer than many of us!

My interview was #4. The first was Ted Neward, and he is about to push up #5, with Regional Director Barry Gervin.

It was a lot of fun to do the interview (and he even taught me how to use skype). What impressed me was that he had very specific questions so that he could be sure that the discussion was at the proper level for his target audience. I think that anyone at any age who is new to programming and new to .NET will find these podcasts very helpful.

Don’t Forget: www.acehaid.org

Using Blocks are new to VB’ers, what are the rules?

Using blocks are new to us VB developers. I get the basic concept – it’s cleaner than try/catch/finally blocks when all you are doing is disposing an object and it’s super great when dealing with unmanaged resources and good ol’ SqlConnections.

But the intricacies of using it are a little less obvious. Luckily, this code construct has been around in C# (and I will guess C++??) so we can learn from those folks.

I was trying to find a better way to deal with a file stream and memory stream today. Porting some code over from vs2003 to vs2005, the compiler was moaning about the following code block (I am only writing it loosely here…) where I am passing in a file name, opening up the file into a streamReader and then doing something to the streamreader and then closing both objects at the end. Maybe it wasn’t written perfectly to begin with, but the compiler issue was a new one.

dim fs as new FileStream(myfilename,FileMode.Open)
dim sr as new StreamReader

Try
   myStreamReader=new StreamReader(fs)

  … do some stuff

Catch exS as IOException
 … do something
Catch ex as Exception
 .. do something
Finally
   If  Not fs is nothing then
      fs .Close
  EndIf
  If Not sr is Nothing then
     sr.Close
  End If
End Try

So when I ported this to VS2005, the compiler was not happy about accessing the streamReader in the Finally block because it was possible that no value would be assigned and I’d get a null ref exception (on the bold red line.)

I knew that I could get rid of those Close methods with a using block but was not sure if nesting them was a) possible b) good code or c) something that would bite me in the rear down the road.

Once I figured out what I was dealing with: “nested using blocks” I quickly found this blog post by Scott Hanselman, who specifically says in the comments of this post that he is thumbs up with “nested using blocks (but ONLY if theare are pure nestings without any other code following the inner block.”

So, considering the source, I’m confident that I’m doing good by doing well (or however that goes) with nested using blocks (with out extra code after the inner block). 🙂

Using fs as New FilesStream(myfilepath,FileMode.Open)
  Using sr as new streamReader(fs)
     Try

       … still need exception handling around the other code

     catch ….
    Finally
    End Try
  End Using
End Using

Don’t Forget: www.acehaid.org

Underscore-named variables and CLS Compliance in VB

When I moved to .NET from VB6, I loved the ability to name variables beginning with an underscore. Now that I am porting some .NET 1.1 code to .NET 2.0, I am seeing that this in non-CLS compliant.

However, because the handful of variables that use the underscore are in a class that has many subclasses and some of these variables are used in the subclasses (shared, protected) AND because this class is not something that anyone else will ever use outside of my application, I have made an executive decision NOT to fix the variables but to set the CLSCompliant attribute from the Assembly information to False.



Don’t Forget: www.acehaid.org