MonoRail - "Unexpected item on the stack" Error - castle-monorail

Anyone seen this MonoRail error before and know what it means?
Unexpected item on the stack: found UCampus.Core.Models.Nested.Hours, expecting UCampus.Core.Models.Business
I'm saving a Business object when this error occurs, Hours is a child of a child of Business.
Thanks,
Justin

In the Hours class it for some reason was overriding the GetHashCode method and that was causing this peculiar exception. Any idea why they would've been overriding GetHashCode??
//public override int GetHashCode()
//{
// unchecked
// {
// return (GetHours(Open) * 397) ^ GetHours(Close);
// }
//}

Related

C++/WinRT: CoreApplication::Run(IFrameworkViewSource const&) is throwing E_INVALIDARG

I'm trying to figure out why at this point in the code I'm getting an E_INVALIDARG hresult:
// main.cpp
class App : public implements<App, IFrameworkView>
{
// stuff ...
};
class AppFactory : public implements<AppFactory, IFrameworkViewSource>
{
public:
IFrameworkView CreateView()
{
return make<App>();
}
};
int WINAPI wWinMain(
_In_ HINSTANCE,
_In_ HINSTANCE,
_In_ LPWSTR,
_In_ int)
{
init_apartment();
auto vpf = make<AppFactory>();
CoreApplication::Run(vpf); // <-- throwing E_INVALIDARG somewhere inside CoreApplication::Run
uninit_apartment();
return S_OK;
}
I'd have expected a compile error if I didn't do something required by a class inheriting implements<AppFractory, IFrameworkViewSource>, but as far as I know I'm checking (static) boxes.
fwiw the exception is triggered here:
// Windows.ApplicationModel.Core.h
template <typename D> auto consume_Windows_ApplicationModel_Core_ICoreApplication<D>::Run(winrt::Windows::ApplicationModel::Core::IFrameworkViewSource const& viewSource) const
{
check_hresult(WINRT_IMPL_SHIM(winrt::Windows::ApplicationModel::Core::ICoreApplication)->Run(*(void**)(&viewSource)));
}
The thing inside check_result(...) is what's returning E_INVALIDARG, and subsequently triggering the exception. I'm not a super expert at writing windows applications, largely still in the "copy the template and hope it works while trying to understand something" phase. If there's some kind of tool I should be using to understand what the actual argument I'm passing is that is invalid, I'd appreciate some kind of pointer. I would think if I'm not passing the correct thing here, the strong type check of the argument would trigger a compile error and I'd have an opportunity to address the issue.
Honestly I'm lost here, would appreciate a hint towards where to look to resolve my issue. Thank you.
Update:
Don't know if this is relevant but in the Output tab in VS a line prints out:
Exception thrown at 0x00007FFA6D9A4FD9 (KernelBase.dll) in MyProgram.exe: WinRT originate error - 0x80070057 : 'serverName'.
I have no idea what this is... "serverName"? I don't even see a mention of this in the CoreApplication::Run docs.

Invalid pointer operation when freeing TStreamAdapter

Can anyone clarify why do I get "Invalid pointer operation" when I attempt to delete TStreamAdapter? Or... how to properly free the memory from TStreamAdapter? It works, if I remove the delete but that causes a memory leak. Even if I use boost::scoped_ptr it also fails with the same error.
Note: I also tried initializing TStreamAdapter with soOwned value, same error.
The code:
HRESULT LoadFromStr(TWebBrowser* WB, const UnicodeString& HTML)
{
if (!WB->Document)
{
WB->Navigate("about:blank");
while (!WB->Document) { Application->ProcessMessages(); }
}
DelphiInterface<IHTMLDocument2> diDoc = WB->Document;
if (diDoc)
{
boost::scoped_ptr<TMemoryStream> ms(new TMemoryStream);
{
boost::scoped_ptr<TStringList> sl(new TStringList);
sl->Text = HTML;
sl->SaveToStream(ms.get(), TEncoding::Unicode);
ms->Position = 0;
}
DelphiInterface<IPersistStreamInit> diPSI;
if (SUCCEEDED(diDoc->QueryInterface(IID_IPersistStreamInit, (void**)&diPSI)) && diPSI)
{
TStreamAdapter* sa = new TStreamAdapter(ms.get(), soReference);
diPSI->Load(*sa);
delete sa; // <-- invalid pointer operation here???
// UPDATED (solution) - instead of the above!!!
// DelphiInterface<IStream> sa(*(new TStreamAdapter(ms.get(), soReference)));
// diPSI->Load(sa);
// DelphiInterface is automatically freed on function end
return S_OK;
}
}
return E_FAIL;
}
Update: I found the solution here - http://www.cyberforum.ru/cpp-builder/thread743255.html
The solution is to use
_di_IStream sa(*(new TStreamAdapter(ms.get(), soReference)));
or...
DelphiInterface<IStream> sa(*(new TStreamAdapter(ms.get(), soReference)));
As it will automatically free the IStream once it is out of scope. At least it should - is there a possible memory leak here? (CodeGuard did not detect any memory leaks).
TStreamAdapter is a TInterfacedObject descendant, which implements reference counting semantics. You are not supposed to delete it at all, you need to let reference counting free the object when it is no longer being referenced by anyone.
Using _di_IStream (which is just an alias for DelphiInterface<IStream>) is the correct way to automate that with a smart pointer. TComInterface<IStream> and CComPtr<IStream> would also work, too.

Selenium - Java - How to check button is enabled or not?

I have tried so many times isenabled property but it always return "true" as the button is disabled on the page but it still return "True"
Please suggest the workaround to handle this?
Here is the code:
public void OpenSearchPage_and_verifyaddtofavoriteslink() throws InterruptedException
{
try
{
driver.navigate().to(favouritepagelink);
driver.findElement(FavoritesCheckBoxSelectAll).click();
//verify condition if product exist on favorites page
if(driver.findElement(FavoritesDelConditionCheck).isEnabled())
{
System.out.println("Enter in condition");
}
else
{
System.out.println("Out of condition");
}
}
catch(Exception ex)
{
System.out.println("SearchPage not opened: " +ex.getMessage());
}
}
Suggestions:
There can two reasons for getting this issue:
i) Issue with object
ii) Issue with the property
I) Issue with object: We can ensure we are using the right object for the button
and refresh the object before performing the operation
ii) Issue with property: Please check if some other property other then enabled is indicating this behaviour by verifying the html code behaviour.
Problem resolved :)
I have used getattribute to get class name then apply condition based on class attribute and its working fine.
Thank you all for the help :)

Managed C++, Object reference not set to an instance of an object

I've run into this problem before, but never in a situation like this. I'm completely confused. As the question states, I'm getting the runtime error "Object reference not set to an instance of an object." Using the debugger tools, I think I've pinpointed the problem to this line:
dataFileLocation = path;
The entire function is here:
void DATReader::SetPath(String^ path)
{
if(!File::Exists(path))
{
MessageBox::Show( "DATReader (missing dat file: \n"+path+"\n )", "Error", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
return;
}
dataFileLocation = path;
}
dataFileLocation is declared here, but nothing is assigned to it:
ref class DATReader
{
private:
System::String^ dataFileLocation;
// ...
}
Now I know the reason I'm getting the error is because dataFileLocation is assigned to nothing. But I'm having problems assigning it. When I add = 0; to it, it won't build because its a ref class. When I try to assigned it to = 0; in the constructor, it yells at me for trying to convert it from a System::String^ to an int. If I assign it to a = gcnew String(""); it builds, but throws the same runtime exception.
I don't get it, am I reading the debugger wrong, and this isn't the source of the problem at all? I've just started to use managed code recently, so I'm confused :\
You may want to check and make sure your DATReader object isn't null as well It may be throwing the exception at your DATReader.SetPath() call.
This is a nicety in C# that's missing in C++/CLI. C# generates code that ensures this can never be null. Easily seen in the debugger by setting a breakpoint on the method and inspecting "this". Here's an example program that reproduces the exception:
#include "stdafx.h"
using namespace System;
ref class Example {
String^ dataFileLocation;
public:
void SetPath(String^ path) {
dataFileLocation = path; // Set breakpoint here and inspect "this"
}
};
int main(array<System::String ^> ^args)
{
Example^ obj /* = gcnew Example */;
obj->SetPath("foo");
return 0;
}
Remove the /* */ comments to fix. Fix your code by looking at the call stack to find the method that forgot to instantiate the object.
Managed C++ uses nullptr for null references. So you can check:
if (path == nullptr) { ... }
or use:
if (!String::IsNullOrEmpty(path))

Problem with Html.Action call to action with [HttpGet] attribute

I have just encountered a strange problem. I have fixed it, but I am hoping that you may be able to help me better understand what actually went wrong. I'll start with an explanation of what happened. The problem concerns a simple MVC3 RC1 app.
In my app's master page there is a call to an action on a controller to render a login-form:
#Html.Action("LoginForm", "Account")
The action method on the AccountController class returns a PartialViewResult containing the login-form.
public PartialViewResult LoginForm()
{
return PartialView();
}
Today I made a change to this action method and attributed it with the HttpGetAttribute like so:
[HttpGet]
public PartialViewResult LoginForm()
{
return PartialView();
}
This is what caused problems. However, the problems only existed in one particular scenario - and this is what baffles me. When posting a form to a controller everything would work just fine provided that the controller action then returned a RedirectToRouteResult. If the action just returned a ViewResult (to its default view), my Http404 error handling would kick in and loop forever.
I have implemented 404 error handling in a manner very similar to what is described in the third answer to this question: Requirements for 404. If you don't want to read that post, in simple terms I override the HandleUnknownAction method on my base controller class, and in that method I instantiate an instance of my ErrorController class and call Execute on it, passing it an instance of RouteData:
protected override void HandleUnknownAction(string actionName)
{
// If controller is ErrorController dont 'nest' exceptions
if (this.GetType() != typeof(ErrorController))
this.InvokeHttp404(HttpContext);
}
public ActionResult InvokeHttp404(HttpContextBase httpContext)
{
IController errorController = DependencyResolver.Current.GetService<ErrorController>();
var errorRoute = new RouteData();
errorRoute.Values.Add("controller", "Error");
errorRoute.Values.Add("action", "Http404");
errorRoute.Values.Add("url", httpContext.Request.Url.OriginalString);
errorController.Execute(new RequestContext(httpContext, errorRoute));
return new EmptyResult();
}
All the ErrorController does is log the error and return a view with a friendly error message. Well, that's how it should work. But in this case the error handling would enter into an infinite loop where the AccountController (to which my form was posted) would invoke the HandleUnknownAction over and over and over again.
There was nothing in the error logs to indicate what had gone wrong (I think I log just about everything) - which was also strange. So I figured that if removed the HandleUnknownAction method from my controller base class maybe something else would be revealed. And it was:
2010-12-10 19:11:47,956 [4] ERROR Infrastructure.Log4NetAuditor [System.Web.HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'. ---> System.Web.HttpException (0x80004005): Execution of the child request failed. Please examine the InnerException for more information. ---> System.Web.HttpException (0x80004005): A public action method 'LoginForm' was not found on controller 'Cdo.Web.Controllers.AccountController'.
What the? When I saw this I remembered that I'd put the HttpGetAttribute on this method - so I promptly removed it... and order was restored. I am happy to have discovered what caused this - but I remain in the dark on why it happened. If you are able to help me shed some light on this I'd be much obliged. Why would the HttpGetAttribute make a difference here?
try setting outputcache attribute to action. I remember that kind of problem and this was a solution. set duration on 1
[OutputCache(Duration = 1, VaryByParam = "None")]