Solved

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

Posted on 2007-12-04
4
490 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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