Solved

Upgrading code from Vb.NET 2003 to 2008 , Narrowing Conversion?

Posted on 2007-12-04
4
476 Views
Last Modified: 2013-11-26
I'm upgrading my vb.net code from 2003 to 2008. I'm getting a narrowing conversion error on the 4th line. Any ideas?

Dim fs As FileStream

                Dim sr As StreamReader

                Try

                    fs = New System.IO.FileStream(flXML, System.IO.FileMode.Open, System.IO.FileShare.ReadWrite, FileShare.Read)
 

                    sr = New System.IO.StreamReader(fs)
 
 

                    DSet.ReadXml(sr)

                    sr.Close()

                    fs.Close()

Open in new window

0
Comment
Question by:JPERKS1985
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20404948
What is 'flXML' defined as?

Bob
0
 
LVL 1

Author Comment

by:JPERKS1985
ID: 20404958
flXML is just string type, it has the file path to the xml document.
0
 
LVL 18

Expert Comment

by:jcoehoorn
ID: 20404969
A narrowing conversion is when you convert from one data type to another, and the source datatype is larger than the destination type.  Like converting a 64-bit number to a 32-bit number.  This should typically produce a compiler warning, but should generally work.   It will produce an error at compile time if you've told the compiler to report warnings as errors or at runtime if you try to convert a value that won't fit in the smaller type (say, the source variable has a number larger than will fit in your 32bit destination, but less than the max 64bit value).  

What is flXML, and where did it come from?  Looking at the various overloads (my system only has .Net 2.0, so there may be some new options in 3.5) it's likely either a String, IntPtr, or SafeFileHandle.  I'm guessing an IntPtr, since that would be susceptible to the conversion problem.
0
 
LVL 7

Accepted Solution

by:
photowhiz earned 500 total points
ID: 20405005
The third param to new FileStream is a FileAccess, not a FileShare.

Also, you should use Imports System.IO
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now