WinRT ObservableCollection.RemoveAt() results in COMExcetion HRESULT E_FAIL - c#

I have an ObservableCollection that a ListBox is databound to. I can add items to the ObservableCollection without issue, and the UI updates, but if I try to call either Remove or RemoveAt to allow the user to delete entries I end up with this:
'10Done.WindowsPhone.exe' (CoreCLR: .): Loaded
'C:\windows\system32\en-US\mscorlib.debug.resources.dll'. Module was
built without symbols. A first chance exception of type
'System.Runtime.InteropServices.COMException' occurred in
mscorlib.ni.dll An exception of type
'System.Runtime.InteropServices.COMException' occurred in
mscorlib.ni.dll but was not handled in user code Additional
information: Error HRESULT E_FAIL has been returned from a call to a
COM component.
Can I not remove items from a collection that is databound?

Related

What could possibly cause COMExceptions while dragging file over the Desktop?

It doesn't crash, all the exceptions I mention here can only be seen in Output window of Visual Studio. Here is the implementation of Dragging:
WPF:
<StackPanel Orientation="Vertical"
MouseDown="DragShortcut"
x:Name="Shortcut">
<Image Source="{Binding Icon}"/>
<Label Content="{Binding ShortcutLabel}"/>
</StackPanel>
cs code:
private void DragShortcut(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton != MouseButtonState.Pressed)
return;
var dataObject = new DataObject(DataFormats.FileDrop, new[] { Options.DragDropOptions.ShortcutPath });
DragDrop.DoDragDrop(Shortcut, dataObject, DragDropEffects.Copy);
}
Everything seems to work as expected, but every time I drag something over my Desktop or Explorer window I receive the following messages in the Output window of my Visual Studio:
...
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in PresentationCore.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in PresentationCore.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in PresentationCore.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in PresentationCore.dll
A first chance exception of type 'System.NotImplementedException' occurred in PresentationCore.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in PresentationCore.dll
...
When Visual Studio is set to stop on that kind of exceptions, I can see the following Exceptions:
System.Runtime.InteropServices.COMException was unhandled
Message: An exception of type 'System.Runtime.InteropServices.COMException' occurred in PresentationCore.dll and wasn't handled before a managed/native boundary
Additional information: Invalid FORMATETC-Structure (Exception HRESULT: 0x80040064 (DV_E_FORMATETC))
and
System.NotImplementedException was unhandled
Message: An exception of type 'System.NotImplementedException' occurred in PresentationCore.dll and wasn't handled before a managed/native boundary
Additional information: The method or operation is not implemented.
It doesn't lead to crash or anything, it's just uncomfortable for me as a developer to have such a thing happening in background. Does anyone have an Idea what could it be?
EDIT:
This problem looks a lot like mine, but seems to have another cause and solution.
This is entirely normal. Whatever window of another process you drag over will make that process poke the object you drag to see if it supports a particular format or can convert the object to another format. Done with COM calls under the hood. If the answer is "yes" then you see the cursor change to indicate that you can drop.
The IDataObject interface implementation in WPF says "no" by throwing an exception. The normal way in which COM failure codes are generated in a .NET program. That exception gets converted by the CLR into a COM error code, an HRESULT, to tell the process that it isn't going to work. Note how the Exeption class has the HResult property, that's what the process sees.
The debugger dutifully displays the "first chance" exception notification if you asked for it. Right-click the Output window, "Exception Messages" option, turned on by default. Nothing actually goes wrong, the exception is caught and handled gracefully. Feature, not a bug.

Helix toolkit WPF CameraController Rotation Mode crash

control.viewPort.CameraController.CameraRotationMode = CameraRotationMode.Turnball;
Throws helpful error
"An exception of type 'System.NullReferenceException' occurred in
your.exe but was not handled in user code"
RotateGesture works, also adding children, but not changes in RotationMode - why?

Having trouble debugging a System.Runtime.InteropServices.COMException on Application.Run

I have an Excel function that I'm calling from C# as follows:
string result = xlApp.Run("'ExcelBook.xlsm'!mainFromBatch",
"http://someSite/TestFile.xlsm",
false,
"T:\\somePath");
When run, this raises an error:
An exception of type 'System.Runtime.InteropServices.COMException' occurred
in BatchConverter.exe but was not handled in user code
Additional information: Exception from HRESULT: 0x800ADF09
If there is a handler for this exception, the program may be safely continued.
The function header for mainFromBatch is:
Function mainFromBatch(sourceBkPath As String, Flag As Boolean, _
Optional outputPathFromConfig As String) As String
When I put a breakpoint at this function header in the VBA code of ExcelBook.xlsm, the C# code raises the error, but the Excel breakpoint is reached and Excel pauses there, as though no error had occurred and it's ready to execute the rest of the code.
I'm able to use C# to call other functions from this workbook without a problem.
I tried Googling the HRESULT code but didn't find anything.
Any idea what's going on here?

I have a error in make a new MainWindow in wpf

I have a error in my wpf project. When I want make a new from MainWindow in The following code:
public App()
{
System.Windows.Forms.Application.EnableVisualStyles();
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
if (MyServer.IsAdministrator())
{
if (MyServer.IsRun())
Process.GetCurrentProcess().Kill();
else
{
MainWindow ObjMain = new MainWindow();
ObjMain.Show();
}
}
else
{
new CheckRunAsAdministrator().ShowDialog();
Process.GetCurrentProcess().Kill();
}
}
I see:
An unhandled exception of type 'System.InvalidOperationException' occurred in PresentationCore.dll
Additional information: The calling thread must be STA, because many UI components require this.
But after this error I remove codes in App() and in App.xaml wrote
But I see another problem. Please see the below.
A first chance exception of type 'System.NotImplementedException'
occurred in PresentationFramework.dll
Additional information: The method or operation is not implemented.
and after that:
An unhandled exception of type
'System.Windows.Markup.XamlParseException' occurred in
PresentationFramework.dll
Additional information: The method or operation is not implemented.
what's the problem?

KeyNotFoundException: SQLCE Database Exception

I am using a dataSet in C#. I have done a direct count for the number of items in
the SQL CE database, so I know how many items that I have in the database. There are no deletions in the the database.
I get the following unexplained exception(s) :
A first chance exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll
A first chance exception of type 'System.Collections.Generic.KeyNotFoundException' occurred in mscorlib.dll KeyNotFoundException
This manifests where the communication locks with the SQL CE database.
Does anyone know what causes this and how this can be fixed?
I have searched online and am having no luck to any solutions for this :-(
// List to be created
List<TableDat> result = null;
lock (_sqlcn)
{
// Assumes that connection is a valid SqlConnection object.
SqlCeDataAdapter adapter = new SqlCeDataAdapter(orderSQL, _sqlcn);
try
{
// DataSet that will be returned.
System.Data.DataSet ds = new System.Data.DataSet();
int count = adapter.Fill(ds, currentIndex, PageSize, "Logs");
//Iterate through the table and in the List
foreach (System.Data.DataRow myDataRow in ds.Tables["Logs"].Rows)
{
if (result == null)
{
result = new List<TableDat>();
}
result.Add(
new TableDat(
(int)myDataRow[Resources.ID],
(DateTime)myDataRow[Resources.TimeStamp],
(int)myDataRow[Resources.EVENTLOG_SID],
(int)myDataRow[Resources.EVENTLOG_EID])
);
}
// Set the dataSet object to NULL : No longer needed as the list
// has been populated
ds = null;
}
The biggest problem I see is that this stops the SQL CE database working. Soz, I cannot make out what I should do in the exception handling here as I get nothing in my list which means that the caller has no details for the list??
This just manifests itself. I am looking for a solution which can handle the exception and also to know why my database is behaving as such :-(
Stack Trace looks like:
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.IO.IOException' occurred in System.dll
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.IO.IOException' occurred in System.dll
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.IO.IOException' occurred in System.dll
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.IO.IOException' occurred in System.dll
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.IO.IOException' occurred in System.dll
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.IO.IOException' occurred in System.dll
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll
A first chance exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.Collections.Generic.KeyNotFoundException' occurred in mscorlib.dll
KeyNotFoundException
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
Usually you don't really need to worry about first chance exceptions. They are usually anticipated and handled by the lower level code inside the dll.
There's a decent write-up on first chance exceptions here.
You can also disable these messages in Visual Studio. (For VS 2005... not sure on 2008).

Categories

Resources