I have a error in make a new MainWindow in wpf - c#

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?

Related

How to solve "An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.Windows.Forms.dll"?

I am still a beginner to programming. I used to add a sliding menu to my program using c# bunifu framework. Once I clicked on a button on my sliding menu to open an another form with the help of creating an object I always receive this error,
An unhandled exception of type 'System.ComponentModel.Win32Exception'
occurred in System.Windows.Forms.dll
Here is the code,
private void engineReg_btn_Click(object sender, EventArgs e)
{
DEOEngineReg DEOER3 = new DEOEngineReg();
DEOER3.Show(); //Error refers here
}
Thanks.

Xamarin.UWP Runtime error in Release mode

I get an error when running my Xamarin.Forms.UWP app in Release Mode.
onecore\com\combase\inc\comcataloghelpers.hpp(64)\combase.dll!00007FFD5E991DAA: (caller: 00007FFD5E990205) ReturnHr(1) tid(6adc) 80040154 Klasse nicht registriert
onecore\com\combase\inc\comcataloghelpers.hpp(64)\combase.dll!00007FFD5E991DAA: (caller: 00007FFD5E990205) ReturnHr(2) tid(2ac4) 80040154 Klasse nicht registriert
onecore\com\combase\inc\comcataloghelpers.hpp(64)\combase.dll!00007FFD5E991DAA: (caller: 00007FFD5E990205) ReturnHr(3) tid(39ec) 80040154 Klasse nicht registriert
onecore\com\combase\inc\comcataloghelpers.hpp(64)\combase.dll!00007FFD5E991DAA: (caller: 00007FFD5E990205) ReturnHr(4) tid(27a4) 80040154 Klasse nicht registriert
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.Reflection.Core.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.Reflection.Core.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.Reflection.Core.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.Reflection.Core.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.Reflection.Core.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.Reflection.Core.dll
Exception thrown: 'System.PlatformNotSupportedException' in System.Private.CoreLib.dll
Exception thrown: 'System.PlatformNotSupportedException' in System.Private.Interop.dll
Unhandled exception at 0x00007FFD43DB83B9 (Windows.UI.Xaml.dll) in Lama.Forms.UWP.exe: 0xC000027B: Anwendungsinterne Ausnahme (parameters: 0x000001FF87EB6FA0, 0x0000000000000002).
This happens inside the automatic generated code-section inside App.xaml.cs
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
Xamarin.Forms.Forms.Init(e);
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
Inside this line:
rootFrame.Navigate(typeof(MainPage), e.Arguments);
This only happens if I run the app in Release mode, if I do in Debug, there is no error happening.
In Release Mode, you have do load Assemblies on your own:
// You'll need to add using System.Reflection;
List<Assembly> assembliesToInclude = new List<Assembly>();
// Now, add in all the assemblies your app uses
assembliesToInclude.Add(typeof (ClassInOtherAssembly).GetTypeInfo().Assembly);
// Also do this for all your other 3rd party libraries
Xamarin.Forms.Forms.Init(e, assembliesToInclude);
// replaces Xamarin.Forms.Forms.Init(e);
So add every 3rd party class you use 1 line assembliesToInclude.Add(typeof (ClassInOtherAssembly).GetTypeInfo().Assembly);
I fixed it by unchecking "Compile with .NET Native tool chain" inside my UWP project. But I am not sure if this is only a temporary fix

Operation completed successfully when using resource

My winforms project is throwing this error:
"Exception thrown: 'System.ComponentModel.Win32Exception' in
System.Drawing.dll
Additional information: The operation completed successfully"
at this line:
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
The line is inside the auto generated code for the designer, so I'm not sure why it's throwing an error. I didn't edit it in any way, please help.
EDIT:
this is not a duplicate, the other question is quite vague on the actual code.
EDIT #2:
The error is now popping up at the designer of resources.resx, with the message
Parameter not valid
it now appears at this auto-generated code:
internal static System.Drawing.Bitmap WoodTex
{
get {
object obj = ResourceManager.GetObject("WoodTex", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
resourceCulture appears to be null, is this a different error entirely?

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.

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