如何调试/修复错误"无法加载参考程序集以执行"?

时间:2016-11-17 22:18:51

标签: c# xaml uwp

无法加载参考程序集以执行

这是我调试/编译项目时获得的唯一信息。该项目编译和运行,我可以使用我添加的功能没有问题。 错误发生在Page.Datacontext上,我在那里定义了在该页面上使用的viewmodel,对于我拥有的两个页面,它是相同的。

这是错误

enter image description here

这是错误的地方

enter image description here

它也发生在我的另一个项目中,我尝试调试/寻找帮助,但我无法弄清楚如何解决它。我的程序集中似乎有64 / 32bit冲突的问题。所以我从另一个项目开始,看看我是否可以修复它,它可以工作很长一段时间。我不明白这个错误是如何在我的第二个项目中出现的。我只是尝试做一些xaml绑定,我复制了一些代码位,没有工作,所以我把它拿出然后错误来了。该项目仍然建设和工作," Buld成功"但错误仍然存​​在。

当我测试更多时,如果我将viewmodel更改为MainPageViewModel,我就不会收到错误。我正在使用模板10汉堡包

<Page 
x:Class="Gainz.Views.ExercisePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Behaviors="using:Template10.Behaviors"
xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:controls="using:Template10.Controls"
xmlns:local="using:Gainz.Views"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:data="using:Gainz.Models"
xmlns:vm="using:Gainz.ViewModels" 
mc:Ignorable="d">

<Page.DataContext>
    <vm:ExercisePageViewModel x:Name="ViewModel" />
</Page.DataContext>

<Page.Resources>
    <DataTemplate x:Key="Exercise" x:DataType="data:Exercise">
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
            <!--   <Image Name="image" Source="{x:Bind Image}" HorizontalAlignment="Center" Width="150" /> -->
            <StackPanel Margin="20,20,0,0">
                <TextBlock Text="{x:Bind ExerciseName }" HorizontalAlignment="Left" FontSize="18" />
                <TextBlock Text="{x:Bind Category}" HorizontalAlignment="Left" FontSize="14" />
            </StackPanel>
        </StackPanel>
    </DataTemplate>
</Page.Resources>

<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <RelativePanel>

        <controls:PageHeader x:Name="pageHeader" RelativePanel.AlignLeftWithPanel="True"
                         RelativePanel.AlignRightWithPanel="True"
                         RelativePanel.AlignTopWithPanel="True" Text="Exercises">

            <!--  secondary commands  -->
            <controls:PageHeader.SecondaryCommands>
                <AppBarButton Click="{x:Bind ViewModel.GotoSettings}" Label="Settings" />
                <AppBarButton Click="{x:Bind ViewModel.GotoPrivacy}" Label="Privacy" />
                <AppBarButton Click="{x:Bind ViewModel.GotoAbout}" Label="About" />
            </controls:PageHeader.SecondaryCommands>
        </controls:PageHeader>
    </RelativePanel>
    <RelativePanel>
        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Width="600">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="100" />
            </Grid.RowDefinitions>
            <ListView Name="ex" ItemsSource="{x:Bind ViewModel.Exercises}" 
                ItemClick="{x:Bind ViewModel.ListView_ItemClick}"
              IsItemClickEnabled="True" 
              ItemTemplate="{StaticResource Exercise}">
            </ListView>
            </Grid>
    </RelativePanel>
</StackPanel>

using Template10.Mvvm;
using System;
using System.ComponentModel;
using System.Net.Http;
using System.Collections.ObjectModel;
using Gainz.Models;
using Windows.UI.Xaml.Controls;
using System.Runtime.CompilerServices;
using Newtonsoft.Json;

namespace Gainz.ViewModels
{
    public class ExercisePageViewModel : ViewModelBase, INotifyPropertyChanged
    {

        public ObservableCollection<Exercise> Exercises { get; set; } = new ObservableCollection<Exercise>();

        public new event PropertyChangedEventHandler PropertyChanged;

        public ExercisePageViewModel()
        {
            LoadExercises();
        }

        private async void LoadExercises()
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(@"http://localhost:33048/api/");

                var json = await client.GetStringAsync("Exercises");

                Exercise[] exercises = JsonConvert.DeserializeObject<Exercise[]>(json);

                Exercises.Clear();
                foreach (var excercise in exercises)
                {
                    Exercises.Add(excercise);
                }
            }
        }

        private string name;
        public string Name
        {
            get { return name; }
            set
            {
                if (value != this.name)
                {
                    name = value;
                    NotifyPropertyChanged("Name");
                }
            }
        }

        private string description;
        public string Description
        {
            get { return description; }
            set
            {
                if (value != this.description)
                {
                    description = value;
                    NotifyPropertyChanged("Description");
                }
            }
        }

        private string category;

        public string Category
        {
            get { return category; }
            set
            {
                if (value != category)
                {
                    category = value;
                    NotifyPropertyChanged("Category");
                }
            }
        }


        public void ListView_ItemClick(object sender, ItemClickEventArgs e)
        {

        }


        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }



        public void GotoDetailsPage() =>
          NavigationService.Navigate(typeof(Views.DetailPage));

        public void GotoSettings() =>
            NavigationService.Navigate(typeof(Views.SettingsPage), 0);

        public void GotoPrivacy() =>
            NavigationService.Navigate(typeof(Views.SettingsPage), 1);

        public void GotoAbout() =>
            NavigationService.Navigate(typeof(Views.SettingsPage), 2);
    }
}

0 个答案:

没有答案