Search code examples
apache-flexfluorinefx

Flex "Unable to cast object of type 'FluorineFx.ASObject' to type." when using FluorineFx and .Net


When using Flex to call a .Net method, there is a casting error on the remote call. The error says:

Unable to cast object of type 'FluorineFx.ASObject' to type com.mynamespace.MyAccessControlType

The caller is flex and the service is served in .net. It is using FlourineFx for communicating/bridging both sides.

The flex call is something like:

public class SavePageDelegate
    {
        private var responder:IResponder;
        private var service:RemoteObject;

        public function SavePageDelegate(page:PageType, responder:IResponder):void
        {
            this.service = ServiceLocator.getInstance().SavePage(page);
            this.responder = responder;
        }
    }

The remote method is as next. Please note that the page object is being sent without problem. The page object has an ArrayList (AccessControlList) of permissions (MyAccessControlType). When I try to access an element using a foreach, the error is thrown:

    /* this is called from Flex*/ 
    public string SavePage(PageType page){
        ...
        InsertAccessControl(page.AccessControlList);
    }

    /* This is called from SavePage */
    public void InsertAccesControl(System.Collections.ArrayList AccessControlList);
    {
        // This is the line where the error is triggered
        foreach (com.mynamespace.MyAccessControlType item in AccessControlList)
        {
            ...
        }
    }

I am using these pages as reference: http://www.fluorinefx.com/docs/fluorine/typeconversion.html - Shows the type casting valid for Fluorine / Flex objects

http://www.fluorinefx.com/docs/fluorine/classmapping.html - For Class Mapping.


Solution

  • You seem to be having a missing mapping for the MyAccessControlType in your flex declaration, since it's being taken as a generic AsObject.

    The mapping would be like this:

    [RemoteClass(alias="com.mynamespace.MyAccessControlType")]
    

    This should allow you to see the full remote class and thus, take down the casting problem. Hope this helps :D