Recently, I suddenly began getting the current exception being thrown from a Flex library. The file I was working on (Login.mxml) suddenly began throwing up this exception while loading.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.binding::StaticPropertyWatcher/updateParent()[E:\dev\4.x\frameworks\projects\framework\src\mx\binding\StaticPropertyWatcher.as:150]
at _components_LoginWatcherSetupUtil/setup()
at components::Login()[C:\Users\username\Documents\MP_MAIN\src\components\Login.mxml:0]
<snip ...>
at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:700]
at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1072]
Running it in the debugger doesn't give me a line of my code that is in error, but it does give me a line in StaticPropertyWatcher. Specifically:
override public function updateParent(parent:Object):void
{
// The assumption is that parent is of type, Class, and that
// the class has a static variable or property,
// staticEventDispatcher, of type IEventDispatcher.
parentObj = Class(parent);
if (parentObj["staticEventDispatcher"] != null) /* Exception thrown from here */
{
...
The debugger shows the parentObj is indeed null, explaining the immediate reason for the exception, but I can't seem to determine the deeper cause (i.e. what I did wrong). The updateParent method is being called from the _components_LoginWatcherSetupUtil class, but the debugger says there is no code for that, so the crucial connection between what I wrote and what caused the exception is missing.
So, basically, I can't even debug this. Any ideas for what to do to shed light on what's going wrong?
Your error is being reported as Login.mxml:0
When I see line 0 as the error it tells me that there is a syntax error of some sort. Open string maybe?
I would suggest looking at the file and see if it is set up properly.
Post the full Login.mxml file and let us look at it.
After laboriously adding back every change I made since last committing to my repository, I tracked down the culprit to this problem. Basically, there were several static variables used to keep track of server addresses like this:
public static var MAIN:String = "http://192.168.1.1/";
public static var MANAGE:String = MAIN + "Manage/";
The issue was that I used a non-compile-time constant MAIN to initialize MANAGE. Changing these variables to const fixed the problem.
public static const MAIN:String = "http://192.168.1.1/";
public static const MANAGE:String = MAIN + "Manage/";
Hopefully this will help anyone else coming across this problem
Related
I am working on an asp.net mvc-5 web application and i am using ap.net version 4.5.
Inside my web application I am executing some power-shell scripts to get some hardware info about some servers and VMs, and get back the results inside my code, as follows:
var shell = PowerShell.Create();
string PsCmd =
"add-pssnapin VMware.VimAutomation.Core; $vCenterServer = '"
+ vCenterName.Trim() + "';$vCenterAdmin = '" + vCenterUsername.Trim()
+ "' ;$vCenterPassword = '" + vCenterPassword + "';"
+ System.Environment.NewLine;
PsCmd += "$VIServer = Connect-VIServer -Server $vCenterServer -User $vCenterAdmin -Password $vCenterPassword;" + System.Environment.NewLine;
PsCmd += "Get-VMHost " + System.Environment.NewLine;
shell.Commands.AddScript(PsCmd);
dynamic results = shell.Invoke();
var temp_result = results[0].BaseObject == null ? results[0] : results[0].BaseObject;
var otherIdentityInfo = temp_result.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo;
now currently when i run this inside my Visual Studio 2012 professional , i will get the following exception :-
System.StackOverflowException was unhandled
An unhandled exception of type 'System.StackOverflowException' occurred in VimService55.XmlSerializers.dll
on
var otherIdentityInfo = temp_result.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo;
So can anyone adivce on this? I know that in general a "StackOverflowException" exception is related to the fact that too many data exists inside the stack, but in my case I do not have control over this data as I am scanning VM server information. So can anyone advice on this please?
EDIT
I am not sure what is really raising the error (the debugger OR the code)? because when i try calling this code on the hosted application inside IIS (not inside Visual Studio) I will get null value for the otherIdentityInfo variable, rather than getting an exception. However, when i debug the code inside Visual Studio using Autos i will get the exception, so as #JmaesP mentioned the exception is being raised by the debugger, but not sure how i can debug this value to see why i am getting null??
A stack overflow exception from an XML serializer might indicate an issue with one of you serializable types. If the type declaration by itself is somewhat recursice, the default XML serializer will end up in inifite recursion. Consider this example:
[Serializable()]
public class Foo : IEnumerable<Foo>
{
public Foo()
{
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
public IEnumerator<Foo> GetEnumerator()
{
throw new NotImplementedException();
}
public void Add(Foo item)
{
throw new NotImplementedException();
}
}
The default XML serializer first tries to figure out how to (de-)serialize an instance of Foo, then it tries to figure out how to (de-)serialize an IEnumerable<Foo>, and to do that it tries to figure out how to (de-)serialize a Foo — resulting in infinite recursion. Typically, a solution to this would to use a custom serializer as described here.
However, in your case the serializer is provided by the third-party component. The exception likely occurs during the serialization/deserialization that is happening when objects are passed from the PowerShell session to your process. So what you could to is to change the object that is returned from the PowerShell script. Instead of returning a VMHost object (requiring to serialize the entire object tree of the VMHost object), you could just return the SystemInfo or OtherIdentifyingInfo.
Large recursions can cause out-of-stack errors.
Your problem is likely that your program is attempting to consume an infinite amount /very large amount of stack.
Without seeing your stack trace, it's a bit difficult to provide a definitive answer, but I think sticking to the basics leads me to believe the source of your StackOverflow is the PsCmd += which continuously adding the data into the stack and results in StackOverflowException.
You can increase the stack size by using the below code:
Editbin.exe /Stack:14000000 "$(TargetDir)MyProject.exe"
Have you analyzed your code to find out that how deep your recursion goes on average? Does it always hit a StackOverflow? Try hardcoding a single entity and see the result.
Since 64 bit code can up more stack space than equivalent 32 bit code, large recursions can cause out-of-stack errors to occur earlier.
In that case, making the stack larger is not a good idea either. Instead we should find the deeply recursive algorithm and make it into an iterative one.
For Stack-Trace;
You can read up this property: Environment.StackTrace.
If the stacktrace exceded a specific threshold that you preset, you can return the function.
Note: From .Net 2.0 and above, you cannot get a StackOverflowException object using a try-catch block.
Let me know if at all it helps you.
I added a new method to the CustVendPaym class called sendersBankCompanyStatementName of type BankCompanyStatementName.
This is the code of said method:
public BankCompanyStatementName sendersBankCompanyStatementName(BankCompanyStatementName _sendersBankCompanyStatementName = sendersBankCompanyStatementName)
{
sendersBankCompanyStatementName = _sendersBankCompanyStatementName;
return sendersBankCompanyStatementName;
}
I added the definition in the classDeclaration method:
BankCompanyStatementName sendersBankCompanyStatementName;
Then in the method vendPaym in the VendOutPaym class, a new instance of VendPaym (which extends CustVendPaym) is created:
vendPaym = new VendPaym();
//A bunch of properties are set then one I created:
vendPaym.sendersBankCompanyStatementName (bankAccountTable.BankCompanyStatementName);
If I break there, I see the assignment with the value I'm expecting working correctly, but then the debugger (watch) never actually shows the new property I added with the value that's supposed to be in it.
Then if I just continue code execution, the AOS server in which I'm developing just crashes :|
Any ideas, am I doing something obviously wrong ?
Thanks.
EDIT: If I rollback my changes (that is deleting the newly added method and removing any references to it) everything works as it was before.
Have you compiled forward the CustVendPaym class?
HiI have this error :
Implicit coercion of a value of type X to an unrelated type X
where X is the type of the object and yes it's type X to an unrelated type X.
It appears 6 times in my project, in 3 differents .mxml file, in the script element. It's in 3 files that I'm not editing and the file I has changing has no link with the 3 files with the errors.
Here a line of code with the problem.
var loadApplicationEvent:LoadApplicationEvent = new LoadApplicationEvent(application);
It was working perfect an when it was compiling and other file that I changed, it put me and error.
Bug from Flash Builder or Flex? Or not?
How can I get ride of it?
I just ran into this issue myself with Flash Builder 4.5. The return type is exactly as it should be.
The solution for me was to do a full rebuild of the project via: Project -> Clean.
I have recently started having this problem with FlashBuilder and here's what I did.
Starting with:
protected var _foo:FooType;
(X) public function get foo():FooType { return this._foo; }
(where (X) is the error in the form Snote described it, with X = FooType)
change to:
protected var _foo:FooType;
public function get foo():* { return this._foo; }
and rebuild. The * type always passes type checking no matter what, so the error disappears.
Then change it back:
protected var _foo:FooType;
public function get foo():FooType { return this._foo; }
The error message then disappears, at least for a while.
So far this technique seems to be reliable, if annoying.
I had the same problem. I resolved it by disabling "strict type checking"
Project properties > ActionScript Compiler > Enable strict type checking
It happens when you try to assign a different type object to some variable. For example, if you try to assign a string value('4') to an object where an int(4) is expected. Look for all the given locations and correct the type casting.
It is an implicit casting, but I cannot tell you the precise problem with the information you have provided.
var loadApplicationEvent:LoadApplicationEvent = new LoadApplicationEvent(application);
What type of object is "application" and what argument is expected by the LoadApplicationEvent constructor? That is where your implicit coercion is occurring. My guess is "application" is not the same type as expected by LoadApplicationEvent in its constructor.
In my case is was going every thing right. Thus it looks to be a IDE problem, as the same code worked few times and the other time it showed me this error. You can try few steps to solve this problem
1. Clear the compiled code and compile again. (There is a clear option in Project tab).
2. Create the a file with the same code and delete the old file.
3. If all this doesn't work, make another class which inherits the base class and change the expected value to *
example:
public class DataGroupOX extends DataGroup
.....
public function set itemRenderer2(value:*):void{
value = value as IFactory;
super.itemRenderer = value;
}
I'm getting error while running a game I created with flex.
I know there has been some question about this, but my case is quite weird. I created a simple typing game that is running OK on my computer, but when I tried to deploy it online to facebook, I got those errors. I used code from the tutorial from adobe here http://www.adobe.com/devnet/facebook/articles/flex_fbgraph_pt4.html to deploy my flex game to facebook
This is the error message:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at FacebookUserStatusWeb/init()
at FacebookUserStatusWeb/___FacebookUserStatusWeb_Application1_creationComplete()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()
at mx.core::UIComponent/set initialized()
at mx.managers::LayoutManager/doPhasedInstantiation()
at mx.managers::LayoutManager/doPhasedInstantiationCallback()
And here is snippet of the init() function:
protected var text1:String="Text to be typed"; //hard-coded temporarily
protected const TIMER_INTERVAL:int = 10;
protected var t:Timer = new Timer(TIMER_INTERVAL);
protected var topURL:String=ExternalInterface.call('top.location.toString');
protected function init():void
{
t.addEventListener(TimerEvent.TIMER, updateTimer);
ProblemText.text = new String(text1);
Facebook.init("<my app id>",loginHandler);
currentState = (topURL) ? "loggedout": "loggedoutonfacebook";
}
Some notes:
1.my app id is my facebook app id which I prefer not to show
2.ProblemText is a richtext which I placed the paragraph to be typed by the player.
3.I have deleted the method Application1_creationComplete() but it still appears at the error listing
And also I am curious about the errors other than the first two. What do they mean?
Ah, and if it is helpful, I can post some more of the code
First: You're only seeing one error. Everything you see below the #1009 error is your stack trace, not additional errors.
The stack trace basically tells you the series of things that happened prior to the error occurring, with the most recent at the top. This is useful because often things which happen prior to the actual error you see will contribute to said error.
Second: The null object reference is occurring because something in your init() function tried to access a property in an object that doesn't exist, or an object that doesn't exist. One (slightly messy but effective) way to debug this would be to drop some trace statements in the code to see how far it gets before barfing with the error -- the idea being to isolate the specific line that's causing the problem. Once you've done that, you need to work backwards to figure out why the object or property you're trying to use is null. It could be something simple, like a typo, or it could be more complex. You'll have to sleuth it out, one way or another =)
Good luck!
Finally got the bug. Just in case people have the same case with me, what exactly happened is at my computer I simulated the game with just one state, but when I'm deploying to facebook I have several states (loggedin,loggedout,etc). In the init() I tried to access ProblemText Label that is not present in the current state.
When I'm in the flash debugger, and I have some callbacks saved, I can see that the functions have a property named savedThis that is very usefull to know where that callback came from.
I'm trying to access that property from code, but for some reason I can't.
callback.savedThis throws an Error because it can't find the property, probable because it's private.
So I tried to add a method to the Function class that would give me access to it:
Function.prototype.getSavedThis = function()
{
return this.savedThis
}
But it gives me the same error about not finding the property, even though I can see it in the debugger.
Is there a way to access it?
Note: I'm not planing on using this in production code, I'm making some classes to help me with debugging by automating some data gathering, and it would be incredible useful to get this information without having to add code to every callback saved informing of the this object.
You can get a reference to a calling function by using the 'arguments.callee' property.
For example:
bar( arguments.callee );
public function bar( caller:Function ) : void { trace( caller ); }