COMException caused by Application.EditClear Method - ms-project

I have a COMException caused by the following code
MSProject.Application mspApp;
bool result = mspApp.SelectColumn(Constants.ACTUALS_RECENT_INDEX, Missing.Value, Missing.Value, Missing.Value);
mspApp.EditClear(Missing.Value, Missing.Value, Missing.Value, Missing.Value);
The value of result is true.
Here's the exception:
System.Runtime.InteropServices.COMException (0x000003EC): An unexpected error occurred with the method.
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Microsoft.Office.Interop.MSProject._MSProject.EditClear(Object Contents, Object Formats, Object Notes, Object Hyperlinks)
Anybody knows the cause of this exception?

It sounds like the column that is getting selected is a read-only field such as ID, Unique ID, Project, etc.
Make sure the column being selected is the one you really want. You could do this by creating a table at run-time (and apply it) so you can be confident that the user has not changed the active view and/or underlying table.

The root cause is that a customized filter is applied while calling EditClear function. This filter will result in no data in the table. The issue disappeared if not applying the filter.

Related

How to send data to list

I tried to give the data to the list(this is all happening inside the widget), but it gives an error. I can't figure out why.
uid = widget.uid;
List<String> ref;
ref.add(uid);
This is the error - The method 'add' was called on null.
Receiver: null
Tried calling: add("TK4DCxUTnnThPhyuLIEFFFBNMuk1")
You need to instantiate it first:
uid = widget.uid;
List<String> ref=[];
ref.add(uid);
The error is self explanatory, get used to reading and understanding errors. Your error is telling you that you tried to call a method .add on an object which is currently equal to null. It points to no place in memory, it only booked a name for it in memory, and that name is ref. But what does ref contain? How does it look like? Nobody knows, therefore it's assigned a value of null. When you use =[ ], it points to a place in memory which is an empty list. Your error goes away. You will encounter this with many objects. If you are using null safety, this error would've been avoided also. The IDE will not have allowed you to declare it as ref;

Kotlin Bundle.putString not explicitly adding "String" but instead is "String?"

val args = Bundle()
args.putString("type", details.type)
navigator.navigate(context!!, findNavController(), Destination.TYPE, args)
I am quite confused as to why in the receiving fragment when I go to access the arguments I have passed through it is responding with...
val type: String = arguments.getString("type")
The arguments.getString is all underlined red and says "Required String Found String?" But how when I called method "putString"?!?
It is resulting in text not being rendered in the new fragment and I assume this is a nullability issue.
It's a matter of knowledge that is available in the receiving Fragment.
The Fragment is not aware of how its arguments were created (or modified) so it has to assume the "type" key you're looking for might not be in the arguments Bundle. That's why it returns a nullable (String?) result (the null value would mean absent in arguments).
Your fragment might be created in many places in your app and its arguments might have been modified in many places. We have no way of tracking that.
There are different solutions for this problem, depending on your approach in other parts of the code and how "confident" you are in creating of your Fragment.
I would usually choose a solution in which I assume setting the type is mandatory. Therefore if the type is absent - I fail fast. That would mean the Fragment was misused.
val type: String = arguments!!.getString("type")!!
The code above will crash if either:
a) arguments weren't set, or
b) String with type wasn't put in the arguments Bundle.
You are right, that is a : null ability issue.
First you should be sure if you are expecting a value, so try adding "?" or "!!", i would recommend "?", or go with the block of if {} else
To read the string safely you can use:
val type: String = arguments?.getString("type").orEmpty()
The orEmpty call at the end ensures that a valid String is returned even if either arguments or getString() returns null.
The method signature for getString() returns a nullable String. This is because at compile time, the compiler can't know if the value exists in the bundle or not. You will have the same issue when retrieving anything from any Map.
If you know for certain that the value in the bundle or map should exist at the time you call getString(), you can use the !! operator. That's what it's there for. When you know something should always be there, it is appropriate to want an exception to be thrown (in this case KNPE) if it's not there so you can easily find any programming error during testing.
isEmpty() or ?.let aren't helpful in this particular case because they would just be masking a programming error and making it harder to discover or debug.

ASP.NET Error Object reference not set to an instance of an object

Object reference not set to an instance of an object
I am getting this error sometimes.
I have a page where I load questions and for some question system generate this error. Why do I get this error? Please help me.
It means that somewhere something dereferences a null reference. Crude example:
Foobar foo = null;
foo.DoSomething(); // this line will trigger a NullReferenceException
Here's what you can do:
compile in debug mode
run it until it crashes
examine the stack trace; it will tell you where the exception originates (unless you're doing stupid things like catching and rethrowing improperly). You may have to follow the chain of inner exceptions
if that doesn't provide sufficient information, step through your code with a debugger until right before the call that makes it crash. Examine any variables that might be null.
Once you have found the culprit, you need to find out why it is null and what to do about it. The solution can be one of:
fix incorrect program logic that causes something to be null that shouldn't be
check if something is null before dereferencing it
handle the exception at a point that makes sense, and translate it into something more meaningful (probably some sort of custom exception)
You got null reference and if it can't handle it will show that message.
It can caused by some case
The return value of a method is null
A local variable or member field is declared but not initialized
An object in a collection or array is null
An object is not created because of a condition
An object passed by reference to a method is set to null
I suggest you to track the null value using a debug mode
You get this error, whenever you are trying to make use of variable with Null value in it.

Object Reference Error - Show class name with error?

When I get an Object Ref error, it can sometimes be a real pain to find out which variable is causing the error (when you can't debug). Is there a way for this error to throw the classname that isn't assigned?
So: I want the name of the type of the variable that was unexpectedly null.
Thanks in advance.
I dont think you can get the class name, the closes I get is to get the class and method name, then the stack trace:
try
{
}
catch ( Exception ex )
{
xxx.API.ErrorHandler.Handler.HandleError( ex, System.Reflection.MethodBase.GetCurrentMethod().Name, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName );
}
Well, its only the information in the stack trace which would be the first step in finding out where the error has originated. Also you should make sure you check the complete stack trace (all inner exceptions too). This would give you the method name with complete namespace. So that should be fairly good step to see where the error is, unless the standard coding is really bad.

.NET Exception handler page: How to show line number with exception?

How to identify the line nr. where the exception has occured and show a piece of code around the exception?
I would like to implement a custom exception handler page which would display the stack trace, and I'm looking for the easiest way to accomplish the above. While most of the information is available through the Exception object, the source code information is not available there.
You need to use the StackTrace class.
For example:
var st = new StackTrace(exception, true);
var sourceFrame = Enumerable.Range(0, st.FrameCount).FirstOrDefault(i => st.GetFrame(i).GetFileLineNumber() > 0);
This code will find the first frame which has line number information available, or null, if none of the frames have line numbers.
You can then call the methods of the StackFrame object to get more information. Note that source information is usually only available in debug builds.

Resources