Windows Phone 8应用程序不包含InitializeComponent的定义

时间:2014-07-06 06:21:19

标签: c# xaml windows-phone-8 visual-studio-2015

我刚刚下载了14个CTP版本的Visual Studio,并为Windows Phone创建了一个空白应用程序。我试图打开MainPage.xaml,设计师会显示以下错误:

enter image description here

对于那些看不到图像的人:

System.Exception
Package failed updates, dependency or conflict validation.

Windows cannot install package App.a5cd6ef3c.a895b.a4508.a96fd.af1634c30bb13 because this package depends on another package that could not be found. This package requires minimum version 0.0.0.0 of framework Microsoft.VCLibs.140.00.Debug published by any publisher to install. Provide the framework along with this package.
   at Microsoft.Expression.HostUtility.Platform.AppContainerProcessDomainFactory.CreateDesignerProcess(String applicationPath, String clientPort, Uri hostUri, IDictionary environmentVariables, Int32& processId, Object& processData)
   at Microsoft.Expression.DesignHost.Isolation.Primitives.ProcessDomainFactory.ProcessIsolationDomain..ctor(ProcessDomainFactory factory, IIsolationBoundary boundary, AppDomainSetup appDomainInfo, FrameworkName targetFramework, String identifier, String baseDirectory)
   at Microsoft.Expression.DesignHost.Isolation.Primitives.ProcessDomainFactory.CreateIsolationDomain(IIsolationBoundary boundary)
   at Microsoft.Expression.HostUtility.Platform.AppContainerProcessDomainFactory.CreateIsolationDomain(IIsolationBoundary boundary)
   at Microsoft.Expression.DesignHost.Isolation.Primitives.IsolationBoundary.Initialize()
   at Microsoft.Expression.DesignHost.Isolation.Primitives.IsolationBoundary.CreateInstance[T](Type type)
   at Microsoft.Expression.DesignHost.Isolation.IsolatedObjectFactory.Initialize()
   at Microsoft.VisualStudio.ExpressionHost.Services.VSIsolationService.CreateObjectFactory(IIsolationTarget isolationTarget, IObjectCatalog catalog)
   at Microsoft.Expression.DesignHost.Isolation.IsolationService.CreateLease(IIsolationTarget isolationTarget)
   at Microsoft.Expression.DesignHost.Isolation.IsolationService.CreateLease(IIsolationTarget isolationTarget)
   at Microsoft.Expression.DesignHost.Isolation.IsolationService.CreateLease(IIsolationTarget isolationTarget)
   at Microsoft.Expression.DesignHost.IsolatedDesignerService.CreateLease(IIsolationTarget isolationTarget, CancellationToken cancelToken, DesignerServiceEntry& entry)
   at Microsoft.Expression.DesignHost.IsolatedDesignerService.IsolatedDesignerView.CreateDesignerViewInfo(CancellationToken cancelToken)
   at Microsoft.Expression.DesignHost.Isolation.IsolatedTaskScheduler.InvokeWithCulture[T](CultureInfo culture, Func`2 func, CancellationToken cancelToken)
   at Microsoft.Expression.DesignHost.Isolation.IsolatedTaskScheduler.<>c__DisplayClass5`1.<StartTask>b__7()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()

我输入App1.xaml.csMainPage.xaml.cs我已经看到 App MainPage 分别没有{的定义{1}}。

该项目处于由Visual Studio创建的状态,我没有改变任何内容!

为什么会发生这种情况,我该如何解决?

6 个答案:

答案 0 :(得分:5)

今天也开始发生在我身上;要重现此问题,我只需打开Visual Studio 2013 Update 4,创建一个空白的Windows Phone 8.1并双击MainPage.xaml。

我通过执行以下操作解决了(我在网上看到的内容的混合):

  • 退出所有Visual Studio实例
  • 删除%localappdata%\ Microsoft \ VisualStudio \ 12.0 \ Designer \ ShadowCache
  • 上的所有内容
  • 使用管理员权限打开命令提示符并执行以下命令:

    pushd %VS110COMNTOOLS%
    icacls ..\IDE /grant *S-1-15-2-1:(OI)(F)
    icacls ..\IDE /grant *S-1-15-2-1:(CI)(F)
    icacls ..\IDE\PrivateAssemblies /grant *S-1-15-2-1:(OI)(F)
    icacls ..\IDE\PrivateAssemblies /grant *S-1-15-2-1:(CI)(F)
    icacls ..\IDE\PublicAssemblies /grant *S-1-15-2-1:(OI)(F)
    icacls ..\IDE\PublicAssemblies /grant *S-1-15-2-1:(CI)(F)
    

最后,重启。适用于Windows 8.1 64位。

答案 1 :(得分:5)

确保XAML上的类名与代码隐藏中的类名匹配。我在重构时遇到过这种情况。

XAML开幕标记:

<UserControl
    x:Class="Namespace.Foo"
    ... />

代码背后:

public sealed partial class Bar : UserControl
{
    public Bar()
    {
        // This will become the error specified (does not contain definition)
        this.InitializeComponent(); 
    }
    ...
}

所以Namespace.Foo需要在这里使用Namespace.Bar来摆脱错误。如果使用Page而不是UserControl,则应该具有相同的行为。

答案 2 :(得分:1)

检查页面中的x:class属性

答案 3 :(得分:0)

  1. “工具” - &gt;&#34;扩展程序和更新&#34; - &gt;安装或更新&#34; nuget包管理器&#34;等等;
  2. 尝试以管理员身份打开
  3. 似乎fat32中的磁盘会导致错误
  4. 如果您在SDK之前安装Silvertlight,则可能会导致错误

答案 4 :(得分:0)

今天遇到同样的问题,通过杀死所有实例并再次打开来修复它。

答案 5 :(得分:0)

它对我不起作用。刚创建了具有管理员类型的新本地帐户(Window 8.1,VS 2013 update 4)。通过新的本地帐户登录。打开并看到它已经解决了。