这个错误是什么:System.Runtime.InteropServices.COMException?

3
我一直收到这个错误信息:
System.Runtime.InteropServices.COMException 在“C:\Users\---\documents\visual studio 2010\Projects\TBrowser\TBrowser\TBrowserWindow.xaml”上被抛出:从调用 COM 组件返回了错误 HRESULT E_FAIL。
但是我的 .xaml 文件中没有 COM 组件。它一直弹出并且说错误的位置是第一行第一列,而我只有一个 Window,什么也没有:
<Window x:Class="TBrowser.TBrowserWindow"
        xmlns:my="clr-namespace:TBrowser"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Height="800" Width="900" Icon="/TBrowser;component/Images/Icons/Icon.ico" MinHeight="143" MinWidth="358" Background="White" Loaded="Window_Loaded" Name="TBWindow1">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Themes/Generic.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>

    <DockPanel x:Name="Layout">
        <StatusBar Height="24" Name="TBStatusBar1" Background="WhiteSmoke" BorderBrush="Black" BorderThickness="0,1,0,0" VerticalContentAlignment="Bottom" DockPanel.Dock="Bottom">
            <StatusBarItem Width="300" HorizontalAlignment="Left" Padding="1" />
            <StatusBarItem HorizontalAlignment="Right" Padding="0" Margin="1" VerticalContentAlignment="Stretch">
                <ProgressBar Width="146" Height="18" HorizontalAlignment="Left" Margin="1" Name="TBProgessBar1"></ProgressBar>
            </StatusBarItem>
        </StatusBar>

        <my:TBOutputPannel x:Name="TBOutputPannel1" DockPanel.Dock="Bottom" MinHeight="48" MaxHeight="200" Visibility="Collapsed" />

        <my:TBControlBar Height="48" VerticalAlignment="Top" x:Name="TBControlBar1" DockPanel.Dock="Top">
            <my:TBControlBar.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Menubar" IsCheckable="True" IsChecked="True" />
                    <MenuItem Header="Favsbar" IsCheckable="True" IsChecked="True" />
                    <MenuItem Header="Statusbar" IsCheckable="True" IsChecked="True" />
                </ContextMenu>
            </my:TBControlBar.ContextMenu>
        </my:TBControlBar>
        <Grid DockPanel.Dock="Bottom">
            <my:TBTabControl x:Name="TBTabControl1">
                <my:TBAddTabItem Height="28" HorizontalAlignment="Left" IsSelected="False" Margin="0" x:Name="TBAddTabItem" VerticalAlignment="Top" Width="28"></my:TBAddTabItem>
            </my:TBTabControl>
            <Menu Height="24" Name="TBMenu1" VerticalAlignment="Top" Margin="0,29,0,0" Background="WhiteSmoke">
                <MenuItem Header="File">
                    <MenuItem Header="New tab" InputGestureText="Ctrl+T" Click="MenuItem_Click">
                        <MenuItem.Icon>
                            <Image Source="/TBrowser;component/Images/Images/TBNewTabIcon1.png" />
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="Duplicate tab" InputGestureText="Ctrl+K" Click="MenuItem_Click_1" />
                    <MenuItem Header="New window" InputGestureText="Ctrl+N" />
                    <MenuItem Header="New session" />
                    <MenuItem Command="ApplicationCommands.Open" Header="Open" />
                    <MenuItem Header="Edit with Notepad" />
                    <MenuItem Command="ApplicationCommands.Save" Header="Save" IsEnabled="False" />
                    <MenuItem Command="ApplicationCommands.SaveAs" Header="Save As..." InputGestureText="Ctrl+S" />
                    <MenuItem Header="Close tab" InputGestureText="Ctrl+W" />
                    <Separator />
                    <MenuItem Header="Page setup" />
                    <MenuItem Command="ApplicationCommands.Print" Header="Print" InputGestureText="Ctrl+P" />
                    <MenuItem Command="ApplicationCommands.PrintPreview" Header="Print preview" />
                    <MenuItem />
                </MenuItem>
            </Menu>
            <ToolBar Height="24" Margin="0,52,0,0" Name="TBFavsbar1" VerticalAlignment="Top" Style="{StaticResource TBFavsbar}">
                <my:TBFavsItem isAdder="True" IconSource="/TBrowser;component/Images/Images/TBAddFavs1.png" Margin="2,1,0,0" />
                <Separator Margin="2,1,0,0" />
            </ToolBar>
        </Grid>
    </DockPanel>

    <Window.TaskbarItemInfo>
        <TaskbarItemInfo x:Name="Display" />
    </Window.TaskbarItemInfo>
</Window>

我甚至还一直遇到这个错误:
System.NullReferenceException was unhandled by user code
  Message=Object reference not set to an instance of an object.
  Source=TBrowser
  StackTrace:
       at TBrowser.TBrowserWindow.TBMenubar1ShowButton_Checked(Object sender, RoutedEventArgs e) in C:\Users\---\documents\visual studio 2010\Projects\TBrowser\TBrowser\TBrowserWindow.xaml.cs:line 137
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
       at System.Windows.Controls.MenuItem.OnChecked(RoutedEventArgs e)
       at System.Windows.Controls.MenuItem.OnIsCheckedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
       at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
       at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
       at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
       at System.Windows.Baml2006.WpfKnownMemberInvoker.SetValue(Object instance, Object value)
       at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(XamlMember member, Object obj, Object value)
       at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)

我正在使用以下内容:

private void TBMenubar1ShowButton_Checked(object sender, RoutedEventArgs e)
{
    TBMenu1.Visibility = System.Windows.Visibility.Visible;
    TBrowser.Properties.Settings.Default.Menubar = System.Windows.Visibility.Visible;
}

我不明白正在发生什么事情。

我猜你在Visual Studio中运行这个项目之前就遇到了这个错误。VS大量使用COM。这个错误非常不具体,但通常是由于VS安装问题或注册表损坏引起的。 - Hans Passant
不,我正在使用Visual C# Express 2010。 - thakyZ
1个回答

4

我认为这是由于将64位INT发送到一个期望32位INT的应用程序所致,要解决此问题(如果是这个问题),请按照以下步骤进行。

右键单击项目(在“解决方案资源管理器”中)-> 属性,生成选项卡,平台目标设置为x86。然后进行清理-构建并试一下。

平台目标


我找不到它。我使用的是Visual C# Express 2010,但我在Build选项卡或BuildEvents选项卡中找不到它。 - thakyZ
@Thaky,我已经添加了一张图片,但是我不确定它是否会看起来相同,因为我正在运行不同版本的VS2010 ;) - craig1231
Visual Studio Express 版本(例如 Visual C# Express)不支持针对特定 CPU 类型的优化。这仅在完整版 Visual Studio 产品中受支持。- 这可能就是为什么它不起作用的原因 :( - craig1231
有趣...我正在尝试设置一个DirectoryEntry Active Dir对象["pwdLastSet"],根据我从SO上读到的信息,它应该是int64类型的,但当我尝试将其设置为int64零值时,我得到了这个确切的COM消息!背景:https://dev59.com/A2HVa4cB1Zd3GeqPkz5u - DukeDidntNukeEm
我解决了我的问题,感谢 @craig1231,Convert.ToInt32让我将属性设置为0! - DukeDidntNukeEm
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接