Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WinMobile
I was building an app to show a picture then play a sound when tapped in WP7. I get the "If the access level of a method in a class library has changed, recompile any assemblies that reference the library." error when I compile, pointing at Main. Well Actually at "Attempt to access the method failed: System.IO.Directory.GetFiles(System.String). This may be due to porting it to WP7 whole from WinCE, but I am not sure.
 
This app is dirt simple (see code below), so I am having a hard time figuring out what has the wrong permissions. Have I made some fundamental error (I mean besides not making functions instead of copy-pasting functionality) ? Google is unhelpful, and Microsoft is AMAZINGLY unhelpful.
 
I apologize now for the length of code, but since I'm not sure what I am looking for I don't know how to reduce it to the "target" code.
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.IO;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Media.Imaging;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework;
 
namespace KanaFlash_WP7
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
       
        public MainPage()
        {
            InitializeComponent();  //Start up

            //read files with .png into files array
            string[] files = System.IO.Directory.GetFiles("*.png"); 
 
            //select a random file from files array and put it in soundfiles
            Random random = new Random();
            int randomNumber = random.Next(0, files.Length);
            string picturefilename = files[randomNumber];
 
            //display selected file
            BitmapImage bt = new BitmapImage();
            bt.UriSource = new Uri(picturefilename, UriKind.Absolute);
            image1.Source = bt;
 
            //Now for the matching sound file

            string soundfilename = System.IO.Path.GetFileNameWithoutExtension(picturefilename);
            soundfilename = soundfilename.ToLower();
            soundfilename = soundfilename.Replace("_", "");
            btnEnglish.Content = soundfilename;
            soundfilename = soundfilename + ".wav";
        }
        bool silencer = false;
       // string[] files = Directory.GetFiles(@"\Storage Card\Program Files\KanaFlash\Kana\", "*.png");

        string[] files = System.IO.Directory.GetFiles("*.png");
        private void image1_ImageFailed(object sender, GestureEventArgs e)
        {
            
        }
 
        public void PlayNewFile(string media)
        {   
            var stream = TitleContainer.OpenStream(media);
            var effect = SoundEffect.FromStream(stream);
            effect.Play();
        }
 
public void GestureListener_Tap(object sender, GestureEventArgs e)
{
    //select a random file from files array and put it in soundfiles
    Random random = new Random();
    int randomNumber = random.Next(0, files.Length);
    string picturefilename = files[randomNumber];
 
    //display selected file
    BitmapImage bt = new BitmapImage();
    bt.UriSource = new Uri(picturefilename, UriKind.Absolute);
    image1.Source = bt;
 
    //Now for the matching sound file

    string soundfilename = System.IO.Path.GetFileNameWithoutExtension(picturefilename);
    soundfilename = soundfilename.ToLower();
    soundfilename = soundfilename.Replace("_", "");
    btnEnglish.Content = soundfilename;
    soundfilename = soundfilename + ".wav";
    if (silencer == false)
    {
        if (System.IO.File.Exists(soundfilename))
        {
            //old method for WinCE:
            //SoundPlayer sound_player = new SoundPlayer(@"\Storage Card\Program Files\KanaFlash\WAV\" + soundfilename);
            //sound_player.Play();

            //new method for WP7:
            PlayNewFile((soundfilename));    //Needs to be WAV File

        }
    }
}
 
        public void btnEnglish_Click(object sender, RoutedEventArgs e)
        {
            //Toggle sound/no sound
            if (silencer == true)
            {
                silencer = false;
            }
            else silencer = true;
        }
 
     //   private void btnExit_Click(object sender, RoutedEventArgs e)
     //   {
     //      Application.Exit();
     //      turns out MS doesn't want you to cleanly exit!  Idiots. 
    //    }
    }
}
Posted 12-Jun-12 8:59am
Edited 14-Jun-12 8:40am
v3
Comments
Steve Maier at 12-Jun-12 15:18pm
   
Formatted code.
Wes Aday at 14-Jun-12 14:55pm
   
http://forums.create.msdn.com/forums/p/75122/457217.aspx
Member 8475208 at 14-Jun-12 16:51pm
   
I tried substituting GetFileNames as shown here:
 
public string[] filenames = IsolatedStorageFile.GetFileNames("file:///C:/Users/unhappydeveloper/Documents/Visual Studio 2010/Projects/KanaFlash WP7/KanaFlash WP7/*.png");
 
I get a "Error 1 An object reference is required for the non-static field, method, or property 'System.IO.IsolatedStorage.IsolatedStorageFile.GetFileNames(string)' C:\Users\lcopley\documents\visual studio 2010\Projects\KanaFlash WP7\KanaFlash WP7\MainPage.xaml.cs 50 37 KanaFlash WP7
"
 
Sorry about the formatting; I'm new at this.
Wes Aday at 14-Jun-12 23:49pm
   
See http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefile.aspx for an example of how to use the IsolatedStorage class. I think that will solve your error.
Member 8475208 at 15-Jun-12 0:23am
   
Wes, apparently I have an excess of stupid, or MS' documentation is more impenetrable than usual. The "example of how to use the IsolatedStorage class" you referenced assumes I am creating the directories, sub-directories and the files. I want to read and display a set of images I provide. How does this help me?
Wes Aday at 15-Jun-12 7:33am
   
Try
IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Assembly, null, null);
foreach (string file in GetAllFiles("*.png", isoStore))
{
Console.WriteLine(directory);
}
Member 8475208 at 15-Jun-12 16:30pm
   
IDE tells me GetStore doesn't exist in System.IO.IsolatedStorage.IsolatedStorageFile.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Now I have little experience working with WP7 platform, but the
 bool silencer = false;
Seems out of place, (but that might not be your issue).
  Permalink  
Comments
Member 8475208 at 13-Jun-12 13:34pm
   
Out of place? I'm not sure what you mean. Could you elaborate?
Frank Reidar Haugen at 13-Jun-12 17:13pm
   
I think I must have been half asleep because I can't remember what made me say it, it made sense then, but now it don't :-S

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 853
1 OriginalGriff 410
2 CPallini 275
3 George Jonsson 226
4 Richard Deeming 145
0 OriginalGriff 5,450
1 CPallini 4,500
2 Sergey Alexandrovich Kryukov 4,482
3 George Jonsson 3,057
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 14 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100