什么是System.Windows.ni.dll?

Ric*_*ins 7 windows-phone visual-studio-2012 windows-phone-8

我正在开发一个使用ScheduledTaskAgent来更新Live Tile的WP8应用程序.这真是一个非常简单的应用程序.问题是,虽然我直接将代码从WP7项目复制到WP8项目,但它不会启动ScheduledTask.不仅如此,如果我正在调试并且我尝试启动计划任务以进行测试,则会出现错误.

System.Windows.ni.dll中发生'System.InvalidOperationException'

不仅如此,它并没有给我任何堆栈来查看,并说源不可用,我可以在反汇编窗口中查看反汇编,这对我来说没有任何意义.因此,IMO不是一个非常有用的错误.

我尝试在计划任务的构造函数中放置一个断点,它永远不会在那里.如果我注释掉测试的启动,没有错误.但是,当然,将应用程序放在我的手机中,它从未启动过,让它一夜之间.

这是我的代码:

var taskName = "TileUpdater";
            var oldTask = ScheduledActionService.Find(taskName) as PeriodicTask;
            if (oldTask != null)
            {
                ScheduledActionService.Remove(taskName);
            }
            if (useLiveTile)
            {
                //GenerateTileInfo();
                PeriodicTask task = new PeriodicTask(taskName);
                task.Description = AppResources.BackgroundTaskDescription;
                oldTask = ScheduledActionService.Find(taskName) as PeriodicTask;
                if (oldTask == null)
                {
                    ScheduledActionService.Add(task);
                }
#if DEBUG
                ScheduledActionService.LaunchForTest(taskName, TimeSpan.FromSeconds(10));
#endif
            }
Run Code Online (Sandbox Code Playgroud)

该代码在WP7版本中运行良好.:/

这是在我的WMAppManifest.xml文件中:

    <ExtendedTask Name="BackgroundTask">
        <BackgroundServiceAgent Specifier="ScheduledTaskAgent"
                                Name="xxxScheduledTask"
                                Source="xxxScheduledTask"
                                Type="xxxScheduledTask.SecheduledAgent" />
    </ExtendedTask>
Run Code Online (Sandbox Code Playgroud)

在我的计划任务中,我唯一要做的就是调用一个生成磁贴信息的过程,更新磁贴,暂时,我重新运行启动测试,所以我可以看看它是否可以再次更新,虽然我已将此注释掉了 - 我将其取消注释以粘贴到此处,但这已被注释掉了.这是我的OnInvoke方法:

    GenerateTileInfo();

    #if DEBUG
        ScheduledActionService.LaunchForTest(task.ToString(), TimeSpan.FromSeconds(60));
    #endif

    NotifyComplete();
Run Code Online (Sandbox Code Playgroud)

GenerateInfo方法不会做任何会导致问题的方法,但当然,它永远不会到达那里.我测试了我生成的tile信息并实现它,将该代码放在MainPage.xaml.cs中并立即调用它,看它是否有效,并且我调用的代码工作正常.因此,如果我打开应用程序,则会更新磁贴.现在我需要让后台任务工作.

任何人都可以提供任何帮助非常感谢.另一个线索是,昨晚我收到一个错误,涉及无法找到pdb文件 - 我认为它是Microsoft.Phone.pdb,但不管它是什么,它也提到了System.Windows.ni.dll文件,但现在我没有得到那个pdb问题,只是这个InvalidOperationException.昨晚调试符号(我不知道这意味着什么)没有加载.今天他们是.我不知道我做了什么来解决它.对于我所知道的一切,本可以重启一下.

此外,我尝试创建一个新项目并将我的代码复制到一个新项目,认为我可能有一个损坏的项目文件,但我现在得到的错误与我今天早些时候得到的相同,这促使我创建新的项目.

再次,任何帮助表示赞赏.谢谢.

(编辑 - 美国东部时间上午11点34分在此点下面添加新评论)=============================== ==================================================

我尝试了另一个实验.我创建了一个新项目,并从http://www.jeffblankenburg.com/2011/11/25/31-days-of-mango-day-25-background-agents/复制/粘贴代码,看看我是否可以调试该应用程序.我确实必须对Jeff Blankenburg编写的代码进行一些小的更改,因为他声明当您添加计划任务项目时,它会自动将以下代码添加到WMAppManifest.xml文件中,但它没有.我是手动完成的.

我还在粘贴到ScheduledAgent.cs的代码中将StandardTileData类型更改为FlipTileData(因为这是WP8项目中的默认值).

除此之外,杰夫在他的文章中没有提到的唯一一件事就是添加必要的使用指令.

鉴于这个实验的结果,我想我可能会看到我的Visual Studio安装被破坏了.你同意吗?我在想卸载/重新安装VS2012和手机sdk就是这里的顺序,但由于需要很长时间,我想得到另一个意见.谢谢.

更新(1/4/2012)========================================== =====================

卸载VS,经过注册表,然后重新安装VS2012,并手机SDK.这是我现在得到的 - 至少现在它将显示堆栈跟踪:

[本机到托管转换] System.Windows.ni.dll!MS.Internal.JoltHelper.OnUnhandledException(object sender,System.UnhandledExceptionEventArgs args)[托管到本机转换] mscorlib.ni.dll!System.Reflection.RuntimeAssembly.nLoad( System.Reflection.AssemblyName fileName,string codeBase,System.Security.Policy.Evidence assemblySecurity,System.Reflection.RuntimeAssembly locationHint,ref System.Threading.StackCrawlMark stackMark,System.IntPtr pPrivHostBinder,bool throwOnFileNotFound,bool forIntrospection,bool suppressSecurityChecks)mscorlib. ni.dll!System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(System.Reflection.AssemblyName assemblyRef,System.Security.Policy.Evidence assemblySecurity,System.Reflection.RuntimeAssembly reqAssembly,ref System.Threading.StackCrawlMark stackMark,System.IntPtr pPrivHostBinder,bool throwOnFileNotFound ,bool forIntrospection,bool suppressSecurityChecks)mscorlib.ni.dll!System.Reflection.RuntimeAssembly.InternalLoad(string assemb lyString,System.Security.Policy.Evidence assemblySecurity,ref System.Threading.StackCrawlMark stackMark,System.IntPtr pPrivHostBinder,bool forIntrospection)mscorlib.ni.dll!System.Reflection.RuntimeAssembly.InternalLoad(string assemblyString,System.Security.Policy.证据assemblySecurity,ref System.Threading.StackCrawlMark stackMark,bool forIntrospection)mscorlib.ni.dll!System.Reflection.Assembly.Load(string assemblyString)Microsoft.Phone.ni.dll!Microsoft.Phone.BackgroundAgentActivator.LoadEntryPointAssembly(string assemblyName) Microsoft.Phone.ni.dll!Microsoft.Phone.BackgroundAgentActivator.LoadAgent(string assemblyName,string typeName)Microsoft.Phone.ni.dll!Microsoft.Phone.BackgroundAgentActivator.Microsoft.Phone.IBackgroundAgentActivator.CreateBackgroundAgent(string assembly,string typeinfo) Microsoft.Phone.ni.dll!Microsoft.Phone.BackgroundAgentDispatcher.AgentRequest.Invoke()Microsoft.Phone.ni.dll!Microsoft.Phone.BackgroundAgentDispatcher.InvocationThread()mscorlib.ni.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state)mscorlib.ni.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext,System.Threading.ContextCallback callback,object state,bool preserveSyncCtx)mscorlib .ni.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext,System.Threading.ContextCallback callback,object state,bool preserveSyncCtx)mscorlib.ni.dll!System.Threading.ExecutionContext.Run(System.Threading) .ExecutionContext executionContext,System.Threading.ContextCallback callback,object state)mscorlib.ni.dll!System.Threading.ThreadHelper.ThreadStart()[Native to Managed Transition]

还考虑到我使用的是低内存仿真器,并且忘记了低内存设备中不允许使用后台代理,但我使用的仿真器(或设备)没有任何区别.

Ric*_*ins 4

经过这么长时间的斗争,我已经解决了这个问题。在将代码从一个项目复制到另一个项目时,我忘记在主项目中添加对 ScheduledTask 项目的引用。

在处理示例代码的过程中,我还学到了一些其他东西,试图让它在我的项目之外工作。首先,当您添加 ScheduledTask 项目时,它似乎没有将必要的元数据添加到 WMAppManifest.xml 文件中,因此您需要手动添加。另一件事是,在处理后台代理时,错误消息可能非常含糊,并且可能没有说明问题的真正含义。

从现在开始,当我在处理计划任务时看到像我在这里看到的错误(我看到了几个非常神秘的错误,看起来都一样,但不完全一样)时,这将提示我确保我'已经获得了对第二个项目的引用,并确保必要的信息位于 WMAppManifext.xml 中(包括拼写 - 如果拼写错误,它不会带有下划线)。