Results 1 to 9 of 9

Thread: Converting this 2008 code to 2010.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    6

    Converting this 2008 code to 2010.

    What would this 2008 VB.net code be in 2010 without error?
    "System.IO.File.WriteAllLines("prefs\prefs.ini", Form1.optionsData.ToArray(GetType(System.String)))"
    And this,
    "clsRequest.Credentials = New System.Net.NetworkCredential(GetPreferenceValue("uname"), GetPreferenceValue("pass"))"

    Errors:

    Error 2 Overload resolution failed because no accessible 'New' can be called without a narrowing conversion:
    'Public Sub New(userName As String, password As System.Security.SecureString)': Argument matching parameter 'userName' narrows from 'Object' to 'String'.
    'Public Sub New(userName As String, password As System.Security.SecureString)': Argument matching parameter 'password' narrows from 'Object' to 'System.Security.SecureString'.
    'Public Sub New(userName As String, password As String)': Argument matching parameter 'userName' narrows from 'Object' to 'String'.
    'Public Sub New(userName As String, password As String)': Argument matching parameter 'password' narrows from 'Object' to 'String'. C:\Users\PC\Documents\Downloads\Form1.vb 823 38 FFViewerV2


    Error 1 Overload resolution failed because no accessible 'WriteAllLines' can be called without a narrowing conversion:
    'Public Shared Sub WriteAllLines(path As String, contents As System.Collections.Generic.IEnumerable(Of String))': Argument matching parameter 'contents' narrows from 'System.Array' to 'System.Collections.Generic.IEnumerable(Of String)'.
    'Public Shared Sub WriteAllLines(path As String, contents() As String)': Argument matching parameter 'contents' narrows from 'System.Array' to '1-dimensional array of String'. C:\Users\PC\Documents\Downloads\Form1.vb 270 13 FFViewerV2


    Error 4 Overload resolution failed because no accessible 'WriteAllLines' can be called without a narrowing conversion:
    'Public Shared Sub WriteAllLines(path As String, contents As System.Collections.Generic.IEnumerable(Of String))': Argument matching parameter 'contents' narrows from 'System.Array' to 'System.Collections.Generic.IEnumerable(Of String)'.
    'Public Shared Sub WriteAllLines(path As String, contents() As String)': Argument matching parameter 'contents' narrows from 'System.Array' to '1-dimensional array of String'. C:\Users\PC\Documents\Downloads\Options.vb 44 13 FFViewerV2
    Last edited by Our Enemies; Jul 9th, 2012 at 08:36 PM.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Converting this 2008 code to 2010.

    The same thing. 2010 can target every framework that 2008 could, and code from 2008 should work without any change in 2010. Since you are asking, I would assume that you are having problems with those lines. What are the errors you are getting?
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    6

    Re: Converting this 2008 code to 2010.

    The program worked in 2008 lol. The errors I am getting for it are

    Error 2 Overload resolution failed because no accessible 'New' can be called without a narrowing conversion:
    'Public Sub New(userName As String, password As System.Security.SecureString)': Argument matching parameter 'userName' narrows from 'Object' to 'String'.
    'Public Sub New(userName As String, password As System.Security.SecureString)': Argument matching parameter 'password' narrows from 'Object' to 'System.Security.SecureString'.
    'Public Sub New(userName As String, password As String)': Argument matching parameter 'userName' narrows from 'Object' to 'String'.
    'Public Sub New(userName As String, password As String)': Argument matching parameter 'password' narrows from 'Object' to 'String'. C:\Users\PC\Documents\Downloads\Form1.vb 823 38 FFViewerV2

    Error 4 Overload resolution failed because no accessible 'WriteAllLines' can be called without a narrowing conversion:
    'Public Shared Sub WriteAllLines(path As String, contents As System.Collections.Generic.IEnumerable(Of String))': Argument matching parameter 'contents' narrows from 'System.Array' to 'System.Collections.Generic.IEnumerable(Of String)'.
    'Public Shared Sub WriteAllLines(path As String, contents() As String)': Argument matching parameter 'contents' narrows from 'System.Array' to '1-dimensional array of String'. C:\Users\PC\Documents\Downloads\Options.vb 44 13 FFViewerV2

    Error 1 Overload resolution failed because no accessible 'WriteAllLines' can be called without a narrowing conversion:
    'Public Shared Sub WriteAllLines(path As String, contents As System.Collections.Generic.IEnumerable(Of String))': Argument matching parameter 'contents' narrows from 'System.Array' to 'System.Collections.Generic.IEnumerable(Of String)'.
    'Public Shared Sub WriteAllLines(path As String, contents() As String)': Argument matching parameter 'contents' narrows from 'System.Array' to '1-dimensional array of String'. C:\Users\PC\Documents\Downloads\Form1.vb 270 13 FFViewerV2

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    6

    Re: Converting this 2008 code to 2010.

    It wont let me post?

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Converting this 2008 code to 2010.

    Yeah, there's some delay until you have something like 10 posts, or so. It's just there to weed out spambots.

    As for the issue, I would say that the 2008 code was probably written with Option Strict OFF, while the 2010 code has Option Strict ON. Technically, you could probably make all the problems go away by turning Option Strict OFF again, but that would be a bad solution, because you'd be allowing implicit conversions, which are not a good idea. Therefore, what you should do would be to fix the errors. For example:

    GetPreferenceValue("uname")

    must be returning something of type Object. I don't recognize the method. If it is something you wrote, then you probably should change it to returning something of type String. Alternatively, you can just change it to:

    GetPreferenceValue("uname").ToString

    which will probably work fine.

    The same general solution is needed for the other line, but I'm not sure which variation you are trying to match, and what optionsData is currently returning. It may be as simple as removing the .ToArray, but that depends on what it actually is.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    6

    Re: Converting this 2008 code to 2010.

    Could you Teamview or skype with me? Because it is hard to explain.

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    6

    Re: Converting this 2008 code to 2010.

    The to string fixed the first line.
    By doing this "clsRequest.Credentials = New System.Net.NetworkCredential(GetPreferenceValue("uname").ToString, GetPreferenceValue("pass").ToString)"
    But the last 2 wont work.

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Converting this 2008 code to 2010.

    Quote Originally Posted by Our Enemies View Post
    Could you Teamview or skype with me? Because it is hard to explain.
    I don't do that.

    What does form1.Optiondata return? What type?
    My usual boring signature: Nothing

  9. #9
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Converting this 2008 code to 2010.

    As Shaggy said, what is happening is that you are encountering Option Strict. This should have been on from the beginning because it's clear that you don't see what is happening. Going forward, you need to be aware of the return types of functions. The compiler isn't going to go easy on you anymore. If something needs a string array, then you need to give it a string array. If the function is returning an Object that actually is a string array then you need to do some casting (Google if you don't know how to cast in VB.NET).

    These errors are a little bit different than what you would normally encounter with Option Strict. The problem you are having is that because your functions are only returning Object types, the parameters you are passing are matching multiple overloads of the same function. The compiler does not know what one you actually want to call, therefore, you need to tell it.

    I highly recommend that you do not turn Option Strict off.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width