构造函数中的System.Reflection.TargetInvocationException

时间:2015-11-02 07:33:02

标签: c# visual-studio

我一直在

  

System.Reflection.TargetInvocationException

和PresentationFramework.dll,附加信息调用目标抛出了异常。

有人可以帮帮我吗?

的信息: 调用堆栈

  

PresentationFramework.dll!System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader xamlReader,System.Xaml.IXamlObjectWriterFactory writerFactory,bool skipJournaledProperties,object rootObject,System.Xaml.XamlObjectWriterSettings settings,System.Uri baseUri)Unknown

    namespace PMD.Analysis.AnalysisViewModel
        {
            using PMD.Measurement.MeasurementModel;
            using System.Windows.Data;
            using PMD.Analysis.AnalysisModel;
            using System;
            using System.Collections.Generic;
            using PMD.Measurement.MeasurementViewModel;
            public class AnalysisViewModel : ViewModel
            {

        /// <summary>
        /// New analysis command.
        /// </summary>
        private ICommand newAnalysis = null;
        public PMD.Analysis.AnalysisViewModel.NewAnalysisViewModel m_NewAnalysisViewModel;
        Measurement measurement = new Measurement();
        private ICollectionView measurements = null;
        /// <summary>
        /// Measurement's search by title field.
        /// </summary>
        private string searchTitle;
        /// <summary>
        /// Measurement's search by title field.
        /// </summary>
        private string searchTester;
        /// <summary>
        /// Measurement's search by vehicle VIN field.
        /// </summary>
        private string searchVehicleVIN;

        public MeasurementModel MeasurementModel
        {
            get;
            set;
        }


        public enum SelectedState
        {
            // No Masurements.
            Inactive,
            // Masurements.
            Active,
            // Waiting for Masurements.
            WaitingAnswer
        };


        public SelectedState CurrentSelectedState { get; set; }

        public Analysis Analysis
        {
            get;
            set;
        }

        public AnalysisViewModel()
        {

            Analysis = new Analysis();
            measurements = new ListCollectionView(MeasurementModel.Measurements);
            measurements.Filter = new Predicate<object>(SearchCallbackAnalysis);
        }

        ~AnalysisViewModel()
        {

        }

        /// <summary>
        /// List of measurements that will be displayed in analysis view.
        /// </summary>
        public ICollectionView Measurements
        {
            get { return measurements; }

            set { measurements = value; }
        }

        /// <summary>
        /// Gets or sets new analysis command.
        /// </summary>
        public ICommand NewAnalysis
        {
            get
            {
                if (newAnalysis == null)
                    newAnalysis = new NewAnalysisCommand(this);
                return newAnalysis;
            }
        }


        public bool SearchCallbackAnalysis(object item)
        {
            bool isItemShowed = true;
            if ((searchTitle != "") && (searchTitle != null))
                isItemShowed &= (((Measurement)item).Title == searchTitle);
            if ((searchVehicleVIN != "") && (searchVehicleVIN != null))
                isItemShowed &= (((Measurement)item).Vehicle.VehicleVIN == searchVehicleVIN);
            if ((SearchTester != "") && (SearchTester != null))
                isItemShowed &= (((Measurement)item).Tester == SearchTester);
            return isItemShowed;
        }



        /// <summary>
        /// Gets or sets measurement's search by title field.
        /// </summary>
        public string SearchTitle
        {
            get
            {
                return searchTitle;
            }

            set
            {

                searchTitle = value;
                Measurements.Refresh();
            }
        }

        /// <summary>
        /// Gets or sets measurement's search by tester name field.
        /// </summary>
        public string SearchTester
        {
            get
            {
                return searchTester;
            }

            set
            {

                searchTester = value;
                Measurements.Refresh();
            }
        }

        /// <summary>
        /// Gets or sets measurement's search by vehicle VIN field.
        /// </summary>
        public string SearchVehicleVIN
        {
            get
            {
                return searchVehicleVIN;
            }
            set
            {    
                searchVehicleVIN = value;
                Measurements.Refresh();
            }
        }      
    }//end AnalysisViewModel

}//end namespace AnalysisViewModel

如果我在构造函数中注释这行代码:

measurements.Filter = new Predicate<object>(SearchCallbackAnalysis); 

一切正常但我需要这一行才能在列表中搜索。

其他信息:

xamlReader  Cannot obtain value of local or argument 'xamlReader' as it is not available at this instruction pointer, possibly because it has been optimized away.  System.Xaml.XamlReader

writerFactory   Cannot obtain value of local or argument 'writerFactory' as it is not available at this instruction pointer, possibly because it has been optimized away.   System.Xaml.IXamlObjectWriterFactory

skipJournaledProperties Cannot obtain value of local or argument 'skipJournaledProperties' as it is not available at this instruction pointer, possibly because it has been optimized away. bool

rootObject  Cannot obtain value of local or argument 'rootObject' as it is not available at this instruction pointer, possibly because it has been optimized away.  object

settings    Cannot obtain value of local or argument 'settings' as it is not available at this instruction pointer, possibly because it has been optimized away.    System.Xaml.XamlObjectWriterSettings

baseUri Cannot obtain value of local or argument 'baseUri' as it is not available at this instruction pointer, possibly because it has been optimized away. System.Uri

1 个答案:

答案 0 :(得分:0)

我试过了:

public ICollectionView Measurements
        {
            get { return measurements; }

            set { measurements = value; 
measurements.Filter = new Predicate<object>(SearchCallbackAnalysis);
}
        }

现在一切正常。谢谢你试着帮助我。