locked
Help me with this? RRS feed

  • Question

  • I have been following you how to make a "Home Screen" but i'm getting this error
    Saturday, October 29, 2011 8:10 AM

Answers

  • Hi Kabayan,

    I was looking at your attachment above and I understand that you have included your imagehelper code in the home screen itself.  I suggest that you should add your separate imagehelper code in the "Client-UserCode".  

    1. Go to File View

    2. expand Client node

    3. Rigth click on the UserCode folder

    4. Click Add New Item

    5. Select Class

    6. Name your class as "ImageHelper"

    7. then Copy/Cut your imagehelper code you used above

     

    Hope this will solve your problem

     

    Rkage


    • Edited by RKage Saturday, October 29, 2011 10:53 PM
    • Proposed as answer by RKage Saturday, October 29, 2011 10:54 PM
    • Marked as answer by FilipinoMamba24 Wednesday, November 2, 2011 3:30 AM
    Saturday, October 29, 2011 10:52 PM
  • This is the code we use which seems to avoid the error you get. It returns nothing rather than throwing an error if the image can't be found. You might want to compare this code with the code you are using.

    Public Class MyImageHelper
     
        Public Shared Function GetImageByName(fileName As StringAs Byte()
            Dim assembly As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()
            Dim stream As Stream = assembly.GetManifestResourceStream(fileName)
            Return GetStreamAsByteArray(stream)
        End Function
     
        Private Shared Function GetStreamAsByteArray(ByVal stream As System.IO.StreamAs Byte()
            If stream IsNot Nothing Then
                Dim streamLength As Integer = Convert.ToInt32(stream.Length)
                Dim fileData(streamLength - 1) As Byte
                stream.Read(fileData, 0, streamLength)
                stream.Close()
                Return fileData
            Else
                Return Nothing
            End If
        End Function
     
    End Class

    Simon Jones
    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, please remember to "Mark as Answer". This will help other people find answers to their problems more quickly.
    Saturday, October 29, 2011 11:31 PM
  • Please put at least a short description of what you want help with in the question, rather than just "Help Me With This".

    That doesn't help those searching for a similar issue, & it doesn't help those of us who would like to assist you either.


    Yann - LightSwitch Central

    (plus ça change, plus c'est la même chose!)

    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, remember to "Mark as Answer".

    This will help people find the answers that they're looking for more quickly.

    Sunday, October 30, 2011 10:40 PM
    Moderator

All replies

  • Have you added an image called logo.png in the client project? If not, that could explain why stream is returned as null, and results in the error you see.

    For anyone else reading this thread, here's a link to the article.

    http://blogs.msdn.com/b/lightswitch/archive/2011/09/06/course-manager-sample-part-6-home-screen-andy-kung.aspx

    Tim

     

    Saturday, October 29, 2011 9:02 AM
  • Have you set the "logo.png" file to be an Embedded Resource? They have to be Embedded. Ordinary Resources can't be used with the GetImageByName function.
    Simon Jones
    Saturday, October 29, 2011 9:36 AM
  • yes I have add a logo.png in the Client Project and also Change BuildAction to Embedded Resource
    Saturday, October 29, 2011 2:59 PM
  • Is the logo file directly in the Client Project's Resources folder, in a folder under Resources or in another folder?

    I know this works when the file is directly in the Resources folder and I know that people using C# have to put the path to the file as well as the file name in the call to the GetImageByName function.

    Also, check you have got the name absolutely right with no differences, not even in capitalisation.


    Simon Jones
    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, please remember to "Mark as Answer". This will help other people find answers to their problems more quickly.
    Saturday, October 29, 2011 3:26 PM
  • Hi Kabayan,

    I was looking at your attachment above and I understand that you have included your imagehelper code in the home screen itself.  I suggest that you should add your separate imagehelper code in the "Client-UserCode".  

    1. Go to File View

    2. expand Client node

    3. Rigth click on the UserCode folder

    4. Click Add New Item

    5. Select Class

    6. Name your class as "ImageHelper"

    7. then Copy/Cut your imagehelper code you used above

     

    Hope this will solve your problem

     

    Rkage


    • Edited by RKage Saturday, October 29, 2011 10:53 PM
    • Proposed as answer by RKage Saturday, October 29, 2011 10:54 PM
    • Marked as answer by FilipinoMamba24 Wednesday, November 2, 2011 3:30 AM
    Saturday, October 29, 2011 10:52 PM
  • This is the code we use which seems to avoid the error you get. It returns nothing rather than throwing an error if the image can't be found. You might want to compare this code with the code you are using.

    Public Class MyImageHelper
     
        Public Shared Function GetImageByName(fileName As StringAs Byte()
            Dim assembly As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()
            Dim stream As Stream = assembly.GetManifestResourceStream(fileName)
            Return GetStreamAsByteArray(stream)
        End Function
     
        Private Shared Function GetStreamAsByteArray(ByVal stream As System.IO.StreamAs Byte()
            If stream IsNot Nothing Then
                Dim streamLength As Integer = Convert.ToInt32(stream.Length)
                Dim fileData(streamLength - 1) As Byte
                stream.Read(fileData, 0, streamLength)
                stream.Close()
                Return fileData
            Else
                Return Nothing
            End If
        End Function
     
    End Class

    Simon Jones
    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, please remember to "Mark as Answer". This will help other people find answers to their problems more quickly.
    Saturday, October 29, 2011 11:31 PM
  • Please put at least a short description of what you want help with in the question, rather than just "Help Me With This".

    That doesn't help those searching for a similar issue, & it doesn't help those of us who would like to assist you either.


    Yann - LightSwitch Central

    (plus ça change, plus c'est la même chose!)

    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, remember to "Mark as Answer".

    This will help people find the answers that they're looking for more quickly.

    Sunday, October 30, 2011 10:40 PM
    Moderator
  • Sir kabayan and Sir Simon Jones,

    Kabayan Salamat kaayo and SIr Simon Thank you

    God Bliss and more power.

     

     

     


    Wednesday, November 2, 2011 3:36 AM