2013-12-23 3 views
0

내 응용 프로그램에 PeriodicTask를 사용하는 것을 시도하고 있지만,이 예외로 OnInvoke() 메서드를 호출하기 전에 실패를 실행하는 경우FileNotFoundException이 PeriodicTask

System.IO.FileNotFoundException

파일을로드 할 수 없습니다 또는 'LockscreenAgent, Culture = neutral, PublicKeyToken = null'또는 해당 종속성 중 하나의 어셈블리. 시스템이 지정된 파일을 찾을 수 없습니다.

(App.xaml.cs를)

pblic App(){ 
     (... default code ...) 
     InitializeAgent(); 
    } 

    private const string PeriodicTaskName = "LockscreenAgent"; 
    private PeriodicTask _periodicTask; 

    private async void InitializeAgent() 
    { 
     //Checks if we need to ask user's permission to set the lockscreen 
     if (!LockScreenManager.IsProvidedByCurrentApplication) 
     { 
      // If you're not the provider, this call will prompt the user for permission. 
      // Calling RequestAccessAsync from a background agent is not allowed. 
      await LockScreenManager.RequestAccessAsync(); 
     } 
     // User gave us permission, let's start the background agent! 
     if (!LockScreenManager.IsProvidedByCurrentApplication) return;    
     // Start the agent 
     StartPeriodicAgent(); 
    } 

    private void StartPeriodicAgent() 
    { 
     // is old task running, remove it 
     _periodicTask = ScheduledActionService.Find(PeriodicTaskName) as PeriodicTask; 
     if (_periodicTask != null) 
     { 
      try 
      { 
       ScheduledActionService.Remove(PeriodicTaskName); 
      } 
      catch (Exception) 
      { 
      } 
     } 
     // create a new task 
     _periodicTask = new PeriodicTask(PeriodicTaskName) 
     { 
      Description = "This is LockscreenPreview image provider app.", 
      ExpirationTime = DateTime.Now.AddDays(14) 
     }; 
     try 
     { 
      // add this to scheduled action service 
      ScheduledActionService.Add(_periodicTask); 
      // debug, so run in every 30 secs 
     #if DEBUG 
      ScheduledActionService.LaunchForTest(PeriodicTaskName, TimeSpan.FromSeconds(30)); 
      Debug.WriteLine("Periodic task is started: " + PeriodicTaskName); 
     #endif 
     } 
     catch (InvalidOperationException exception) 
     { 
      if (exception.Message.Contains("BNS Error: The action is disabled")) 
      { 
       // load error text from localized strings 
       MessageBox.Show("Background agents for this application have been disabled by the user."); 
      } 
      if (
       exception.Message.Contains(
        "BNS Error: The maximum number of ScheduledActions of this type have already been added.")) 
      { 
       // No user action required. The system prompts the user when the hard limit of periodic tasks has been reached. 
      } 
     } 
     catch (SchedulerServiceException) 
     { 
      // No user action required. 
     } 
    } 

(WMAppManifest :

여기 (! 그것을 만들기 전에도 실패하기 때문에 나는 ScheduledAgent의 코드를 생략하고있어) 내 코드입니다. xaml)

<Tasks> 
    <DefaultTask Name="_default" NavigationPage="MainPage.xaml" /> 
    <ExtendedTask Name="BackgroundTask"> 
    <BackgroundServiceAgent Specifier="ScheduledTaskAgent" Name="LSAgent" Source="LockscreenAgent" Type="LockscreenAgent.ScheduledAgent" /> 
    </ExtendedTask> 
</Tasks> 
<Tokens> 
    ... 
</Tokens> 
<Extensions> 
    <Extension ExtensionName="LockScreen_Background" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" /> 
</Extensions> 

아무 것도 없습니까?

답변

1

LockscreenAgent.dll이 휴대 전화에 배포 된 것처럼 앱 디렉토리에 존재하지 않는다고 생각합니다. 솔루션에서 포어 그라운드를 포함하는 프로젝트에 백그라운드 에이전트가 포함 된 프로젝트에 대한 참조가 있습니까? 그렇다면 해당 참조의 속성에서 로컬 복사가 true로 설정되어 있는지 확인하십시오. 또한 DLL의 경로가 올바른지 확인하십시오.

0

내 경우주기 프로젝트 프로젝트의 이름을 변경했습니다. Bin/Debug 폴더의 결과로 어셈블리에는 이전 이름이 있습니다. 그 이유는 정기적 인 작업 프로젝트 속성에서 어셈블리 이름과 기본 네임 스페이스를 변경하는 것을 잊었 기 때문입니다. 이 작업을 수행했을 때 어셈블리 이름이 정확했으며 System.IO.FileNotFoundException이 사라졌습니다.

See image

관련 문제