Operation completed successfully when using resource - c#

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?

Related

Invalid object name 'dbo.EdmMetadata'

I keep getting this error on initial load of my application. I have searched high and low and the only thing I found to do was the code below in my context.
Database.SetInitializer<Context>(null);
I have this set in the OnModelCreating method but it is still throwing the error below:
System.Data.SqlClient.SqlException: Invalid object name
'dbo.EdmMetadata'.
System.Data.Entity.Core.EntityCommandExecutionException: An error
occurred while executing the command definition. See the inner
exception for details.
You should add this code in constructor of your Context class.

FindToolWindow Exception

I am implementing a ShowToolWindow() function in a visual studio extension project that displays a toolwindow on click of a button.
The following code works:
private void ShowToolWindow()
{
IVsUIShell vsUIShell = (IVsUIShell)Package.GetGlobalService(typeof(SVsUIShell));
IVsWindowFrame frame;
Guid WindowGuid = new Guid("48d81433-5d5c-4d4c-a174-d8e620c0e0a8");
vsUIShell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, ref WindowGuid, out frame);
frame.Show();
}
However, the following code does not work
private void ShowToolWindow1()
{
this.package = new ToolWindowPackage()/*Package that provides the window*/;
var window = (MyToolWindow)this.package.FindToolWindow(typeof(MyToolWindow), 0, true); /*This line throws an exception*/
IVsWindowFrame frame = window.Frame;
frame.show();
}
In this case the FindToolWindow throws the following exception
Activated Event Time Duration Thread
Exception: Exception thrown: 'System.Exception' in Microsoft.VisualStudio.Shell.15.0.dll ("The service 'Microsoft.VisualStudio.Shell.Interop.SVsUIShell' must be installed for this feature to work. Ensure that this service is available."). Exception thrown: 'System.Exception' in Microsoft.VisualStudio.Shell.15.0.dll ("The service 'Microsoft.VisualStudio.Shell.Interop.SVsUIShell' must be installed for this feature to work. Ensure that this service is available.")
It seems it is not calling the Package.FindToolWindow, but rather the IVsUIShell.FindToolWindow. How should I resolve this.
I am asking this question because I need to get a handle of the ToolWindowPane. Therefore even though the first way shows the toolwindow correctly it is not suffice. An alternative solution to this question, could someone tell me how to get a handle of the ToolWindowPane Through the first method?
You should not create a new instance of ToolWindowPackage by yourself. You should use an existing package instance instantiated by Visual Studio.

Exception in Release mode only while reflectively creating objects

My application is failing only when I attempt to launch it in release mode. Debug mode works fine. I am getting an error that reads
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in PresentationFramework.dll
Additional information: Exception has been thrown by the target of an invocation.
Because this only happens in release, it's been a bit difficult to debug. However, if I uncheck the "Optimize code" checkbox in the project properties, I am able to see an exception thrown in this method:
private static T MakeObject<T>(Type type) where T :class
{
//Default reflective behavior to create an instance with an empty constructor
//
//*note: .GetConstructor can return null.
object obj = null;
T tObj = default(T);
ConstructorInfo ci = type.GetConstructor(TypeInfo.EmptyTypes);
if (ci != null)
{
obj = ci.Invoke(new object[] { /* Empty */});
tObj = obj as T;
}
if (tObj == null)
throw new InvalidCastException("Fatal error occurred within NavigationService (GetConstructor). Type: " + type.ToString());
return tObj;
}
on this line:
ConstructorInfo ci = type.GetConstructor(TypeInfo.EmptyTypes);
The exception reads:
An exception of type 'System.NullReferenceException' occurred in LWDCloudManager.exe but was not handled in user code
Additional information: Object reference not set to an instance of an object.
Does anyone have any suggestions on how I might be able either fix this issue, or how to dig deeper and understand why this could be happening in release mode only?
I discovered the problem. Actually kind of a stupid problem/oversight by me. Recently my company decided that instead of throwing exceptions in internal methods, we would just use Debug.Asserts, so I went and changed all of them. One of the lines of code ahead of this issue was a debug assert wrapped around a call to a TryGetValue call on a dictionary. Because I was attempting to run in release mode, the debug.assert was not executed, thus the value was not retrieved from the dictionary resulting in a null being passed. Thanks for the help guys

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.

'System.Reflection.TargetInvocationException' when calling Activator.CreateInstance()

I am receiving this error:
A first chance exception of type 'System.Reflection.TargetInvocationException'
occurred in mscorlib.dll
and also:
Exception has been thrown by the target of an invocation.
when running this method, and the error is occurring on the CreateInstance(Type.GetType(instantiationString), parameters) call:
public static Report instantiateReport(ReportInfo reportInfo)
{
string instantiationString;
Report reportToReturn;
ReportInfo[] parameters = new ReportInfo[1];
parameters[0] = reportInfo;
instantiationString = reportInfo.Report.InstantiationPath;
reportToReturn = (Report)Activator.CreateInstance(Type.GetType(instantiationString), parameters);
return reportToReturn;
}
ReportInfo is just a custom class that contains variables that help me build the report that I am trying to instantiate and when I investigate it, everything is completely fine. The instantiationString just helps me understand which report is trying to be created at the call and that way I can use the Type.GetType() method. I really have no idea what kind of error this is or what could be going wrong. I researched it a bit but didn't receive any helpful answer so any help is appreciated.
EDIT After looking at the inner exception I am getting Object reference not set to an instance of an object. message. This is strange because neither the ReportInfo or the GetType() methods have a null reference. Say one of the variables within ReportInfo was null, could that cause an issue? It shouldn't right?
FIXED After delving into the stack trace of the inner exception I found that there was some conflicting code causing issues elsewhere. Problem solved.

Categories

Resources