标签: invalidoperationexception

为什么'this.ContentTemplate.FindName'会在自己的模板上抛出InvalidOperationException?

好的...这让我很难过.我在UserControl中覆盖了OnContentTemplateChanged.我正在检查传入newContentTemplate的值实际上是否等于this.ContentTemplate(它确实)当我调用它时...

var textBox = this.ContentTemplate.FindName("EditTextBox", this);
Run Code Online (Sandbox Code Playgroud)

...它抛出以下异常......

"此操作仅对应用此模板的元素有效."

根据另一个相关问题的评论者,他说你应该传入内容主持人来控制,而不是控件本身,所以我试过这个......

var cp = FindVisualChild<ContentPresenter>(this);

var textBox = this.ContentTemplate.FindName("EditTextBox", cp);
Run Code Online (Sandbox Code Playgroud)

其中FindVisualChild只是MSDN示例中使用的辅助函数(见下文),用于查找关联的内容演示者.找到"cp"时,它也会抛出同样的错误.我很难过!

这是辅助函数供参考......

private childItem FindVisualChild<childItem>(DependencyObject obj)
    where childItem : DependencyObject
{
    for(int i = 0 ; i < VisualTreeHelper.GetChildrenCount(obj) ; i++)
    {
        DependencyObject child = VisualTreeHelper.GetChild(obj, i);
        if(child != null && child is childItem)
            return (childItem)child;
        else
        {
            childItem childOfChild = FindVisualChild<childItem>(child);
            if(childOfChild != null)
                return childOfChild;
        }
    }
    return null;
}
Run Code Online (Sandbox Code Playgroud)

中号

wpf invalidoperationexception contenttemplateselector

15
推荐指数
1
解决办法
8295
查看次数

查询结果不能多​​次枚举?

我正在使用LINQ to SQL在Sql server 2008中获取FullTextSearch存储过程的搜索结果.我将过程从服务器资源管理器拖到设计器,并使用适当的返回类型和参数创建了方法.现在问题是,我需要获取调用此方法的结果的Count,因此使用我的存储库方法(将调用Sproc方法并将结果作为IQueryable返回),我进行以下调用.

var result = repository.FullTextSearch(searchText);
        int resultsCount = result.Count();
        var ret = result.Skip((pageNumber - 1) * PageSize).Take(PageSize).ToList();
Run Code Online (Sandbox Code Playgroud)

每次我尝试运行它时,此代码都会生成一个InvalidOperationException,异常说(是的,你猜对了!)"查询结果不能多​​次枚举."

为Sproc生成的方法返回ISingleResult,它应该是OK AFAIK.我需要在我的视图上支持分页,所以我需要知道总页数,如果我能得到所有项目的计数,那么(再次AFAIK)是可能的.

伙计,我在这里想念的是什么?

invalidoperationexception linq-to-sql

14
推荐指数
3
解决办法
3万
查看次数

Windows应用程序已停止工作::事件名称CLR20r3

我使用Visual Studio.Net 2008 Team System和Infragistics Net Advantage Tools 2010.3开发了一个应用程序,并为我的应用程序创建了一个Setup Exe文件,并安装在客户机上,它们同时具有Windows7 32位和WindowsXP Service Pack 2.(我也尝试过)设置属性TargetPlatform x86和x64两种方式)

但是,当我在开发机器中安装并运行此应用程序(exe)文件时,它已正确安装并运行.仅在客户端的计算机上安装正确但未运行,双击exe文件时出错.

在此输入图像描述

完整错误如下:

描述:停止工作

问题签名:问题事件名称:CLR20r3问题签名01:al-deihani.exe问题签名02:1.0.0.0问题签名03:4dac0949问题签名04:Al-Deihani问题签名05:1.0.0.0问题签名06:4dac0949问题签名07:47问题签名08:c6问题签名09:System.InvalidOperationException操作系统版本:6.1.7600.2.0.0.256.1区域设置ID:1033

在线阅读我们的隐私声明:http: //go.microsoft.com/fwlink/?linkid = 104288&clcid = 0x400

如果没有在线隐私声明,请离线阅读我们的隐私声明:C:\ Windows\system32\en-US\erofflps.txt

.net vb.net invalidoperationexception

12
推荐指数
1
解决办法
12万
查看次数

队列ForEach循环抛出InvalidOperationException

我以前没有Queues<T>任何真正的学位,所以我可能会遗漏一些明显的东西.我试图迭代Queue<EnemyUserControl>这样(每一帧):

foreach (var e in qEnemy)
{
     //enemy AI code
}
Run Code Online (Sandbox Code Playgroud)

当敌人死亡时,敌方用户控制会引发我订阅的事件并执行此操作(队列中的第一个敌人被设计删除):

void Enemy_Killed(object sender, EventArgs e)
{      
     qEnemy.Dequeue();

     //Added TrimExcess to check if the error was caused by NULL values in the Queue (it wasn't :))
     qEnemy.TrimExcess();
}
Run Code Online (Sandbox Code Playgroud)

然而,出列方法被调用后,我得到InvalidOperationExceptionforeach循环.当我使用时Peek,没有错误,所以它必须对Queue本身的更改做一些事情,因为Dequeue删除了对象.我最初的猜测是,它正在抱怨我正在修改一个由Enumerator迭代的集合,但是这个集合是在循环之外执行的吗?

可能导致此问题的任何想法?

谢谢

.net c# queue silverlight invalidoperationexception

12
推荐指数
3
解决办法
3万
查看次数

什么是父母可冻结?这个错误是什么意思?

我收到这个错误:

不能使用属于与其父Freezable不同的线程的DependencyObject

那有什么意思?是英文的吗?父母被冻结了,还是只是可以冻结?任何使父母不可冻结的方法,如果它让错误消失了?

发生了什么:

我在WPF应用程序中有两个opengl winforms控件,到目前为止,一切都在顺利进行(我认为).现在,我添加了一个更新,以便当一个winform控件更新图像时,另一个也应该.这实际上曾经工作过,现在我收到了这个错误.逐步执行代码会导致崩溃发生在随机位置,这使我相信它是一个垃圾收集错误(即,另一个线程中的某些更新正在创建收集垃圾的东西,并且该收集在随机时间发生).

异常是在主run方法中捕获的,它是一个InvalidOperationException.

我在这里抓住稻草.我从哪里开始?

编辑:看起来引起问题的电话是这样的:

        if (imagePanel.InvokeRequired)
        {
            imagePanel.Invoke(new System.Windows.Forms.MethodInvoker(delegate{
                imagePanel.ClearImages();
            }));
        }
        else
        {
            imagePanel.ClearImages();
        }
Run Code Online (Sandbox Code Playgroud)

我还在跟踪它; 如果该系列行被注释掉,崩溃仍然发生,并且线程状态具有"刚刚结束"的线程(因此垃圾收集假设).

wpf invalidoperationexception dependencyobject freezable

11
推荐指数
1
解决办法
5457
查看次数

如何将逻辑添加到现有依赖项属性回调?

我正在尝试将一个PropertyChangedCallback添加到UIElement.RenderTransformOriginProperty.当我尝试覆盖PropertyMetadata时抛出异常.

我搜索过MSDN和谷歌,我能想到的就是这个.在该帖子的某些时候建议使用DependencyPropertyDescriptor.AddValueChanged,但这不会解决我的问题,因为这不是每个实例的回调.

我不明白这个例外意味着什么.有谁知道我做错了什么?

public class foo : FrameworkElement
{
    private static void Origin_Changed( DependencyObject d,
                                        DependencyPropertyChangedEventArgs e)
    { }

    static foo()
    {
        PropertyMetadata OriginalMetaData =
            UIElement.RenderTransformOriginProperty.GetMetadata(
                typeof(FrameworkElement));



/*An exception is thrown when this line is executed:
 "Cannot change property metadata after it has been associated with a property"*/
        OriginalMetaData.PropertyChangedCallback +=
            new PropertyChangedCallback(Origin_Changed);



        UIElement.RenderTransformOriginProperty.OverrideMetadata(
            typeof(foo), OriginalMetaData);
    }
}
Run Code Online (Sandbox Code Playgroud)

.net c# dependency-properties exception invalidoperationexception

11
推荐指数
1
解决办法
5710
查看次数

为什么ControlCollection不会抛出InvalidOperationException?

按照这个问题Foreach循环处理控件跳过迭代它告诉我,迭代是允许通过更改集合:

例如,以下内容:

List<Control> items = new List<Control>
{
    new TextBox {Text = "A", Top = 10},
    new TextBox {Text = "B", Top = 20},
    new TextBox {Text = "C", Top = 30},
    new TextBox {Text = "D", Top = 40},
};

foreach (var item in items)
{
    items.Remove(item);
}
Run Code Online (Sandbox Code Playgroud)

InvalidOperationException:Collection已被修改; 枚举操作可能无法执行.

但是,在.Net表单中,您可以执行以下操作:

this.Controls.Add(new TextBox {Text = "A", Top = 10});
this.Controls.Add(new TextBox {Text = "B", Top = 30});
this.Controls.Add(new TextBox {Text = "C", Top = 50});
this.Controls.Add(new …
Run Code Online (Sandbox Code Playgroud)

.net c# foreach invalidoperationexception winforms

11
推荐指数
1
解决办法
217
查看次数

WSDL导出扩展中的周期性异常

我有一个已经运行了一个多月的SOAP服务.在过去的两周里,我们遇到了服务随机开始生成异常的情况.每次,它们似乎与导出扩展相关,并且错误总是沿着以下行:

调用WSDL导出扩展时抛出异常:System.ServiceModel.Description.DataContractSerializerOperationBehavior

使用"System.ArgumentException:命名节点来自不同的文档上下文." 似乎每次都是根本原因.

让我感到烦恼的是,这项服务在一个半月内没有改变,所以我很困惑我们突然间突然得到了争论错误.这是否表明存在潜在问题(内存泄漏或类似问题)?

我对运行的机器的访问权限非常有限,但可以根据需要尝试获取任何支持信息.这是wsdl回归的完整例外:

    An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
    System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension: System.ServiceModel.Description.DataContractSerializerOperationBehavior
     Endpoint: [endpoint name here... hidden for security] ----> System.ArgumentException: The named node is from a different document context.
       at System.Xml.XmlAttributeCollection.Append(XmlAttribute node)
       at System.ServiceModel.Description.SoapHelper.CreateSoapFaultBinding(String name, WsdlEndpointConversionContext endpointContext, FaultBinding wsdlFaultBinding, Boolean isEncoded)
       at System.ServiceModel.Description.MessageContractExporter.MessageBindingExporter.ExportMessageBinding(OperationDescription operation, Type messageContractExporterType)
       at System.ServiceModel.Description.WsdlExporter.CallExtension(WsdlEndpointConversionContext endpointContext, IWsdlExportExtension extension)
       --- End of inner ExceptionDetail stack trace ---
       at System.ServiceModel.Description.ServiceMetadataBehavior.MetadataExtensionInitializer.GenerateMetadata()
       at …
Run Code Online (Sandbox Code Playgroud)

c# wsdl web-services exception invalidoperationexception

10
推荐指数
2
解决办法
2025
查看次数

InvalidOperationException与ArgumentException

我知道摘要和说明.

但是如果ARGUMENT处于无效状态怎么办?

我认为ArgumentException更合适,因为InvalidOperationException文档说该方法被调用的对象必须处于无效状态.这有意义吗?

c# invalidoperationexception argumentexception

10
推荐指数
1
解决办法
2211
查看次数

为什么XmlSerializer会抛出InvalidOperationException?

    public void Save() {
          XmlSerializer Serializer = new XmlSerializer(typeof(DatabaseInformation));
          /*
          A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
          A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
          A first chance exception of type 'System.InvalidOperationException' occurred in System.Xml.dll
          */

          // ....
     }
Run Code Online (Sandbox Code Playgroud)

如果您需要,这是全班:

public class DatabaseInformation
{
    /* Create new database */
    public DatabaseInformation(string name) {
        mName = name;
        NeedsSaving = true;
        mFieldsInfo = new List<DatabaseField>();
    }

    /* Read from file */
    public static DatabaseInformation DeserializeFromFile(string xml_file_path)
    { …
Run Code Online (Sandbox Code Playgroud)

.net c# exception invalidoperationexception

9
推荐指数
2
解决办法
3万
查看次数