locked
unable to convert type 'System.String' into a dependent RRS feed

  • Question

  • User-2144969750 posted

    Hello all,

    I am getting the error below in an unmodified dynamic data web application ; I am using EF4

    So far I have seen no help on this; could you please help? Thanks in advance

    Erreur du serveur dans l'application '/'.


    Impossible de convertir le type 'System.String' en 'eoi.action'

    Description : Une exception non gérée s'est produite au moment de l'exécution de la requête Web actuelle. Contrôlez la trace de la pile pour plus d'informations sur l'erreur et son origine dans le code.           
    Détails de l'exception: System.InvalidOperationException: Impossible de convertir le type 'System.String' en 'eoi.action'
    Erreur source:

    Ligne 17 :         {
    Ligne 18 :             table = DynamicDataRouteHandler.GetRequestMetaTable(Context);
    Ligne 19 : GridView1.SetMetaTable(table, table.GetColumnValuesFromRoute(Context)); 

    Fichier source : C:\Users\jay\Documents\Visual Studio 2010\Projects\eoi\eoi\DynamicData\PageTemplates\List.aspx.cs    Ligne : 19           
    Trace de la pile:

    [InvalidOperationException: Impossible de convertir le type 'System.String' en 'eoi.action']
       System.Web.DynamicData.Misc.ChangeType(Object value, Type type) +208081
       System.Web.DynamicData.MetaTable.GetColumnValuesFromRoute(HttpContextBase context) +341
       System.Web.DynamicData.MetaTable.GetColumnValuesFromRoute(HttpContext context) +40
       eoi.List.Page_Init(Object sender, EventArgs e) in C:\Users\jay\Documents\Visual Studio 2010\Projects\eoi\eoi\DynamicData\PageTemplates\List.aspx.cs:19
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
       System.EventHandler.Invoke(Object sender, EventArgs e) +0
       System.Web.UI.Control.OnInit(EventArgs e) +92
       System.Web.UI.Page.OnInit(EventArgs e) +12
       System.Web.UI.Control.InitRecursive(Control namingContainer) +134
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +489
    


    Informations sur la version : Version Microsoft .NET Framework :4.0.30319; Version ASP.NET :4.0.30319.17929

    Monday, September 17, 2012 7:47 AM

Answers

  • User-2144969750 posted

    I could do that, although it seems a bit complicated; I will try Enable .NET Framework source stepping that should allow me to step into the source code of the GetColumnValuesFromRoute function

     Doing so I discovered that I cannot have an entity named "action" (referred to by eoi.action , eoi being the namespace) because that conflicts with the the route definition in the Global.asax.cs defined as

             routes.Add(new DynamicDataRoute("{table}/{action}.aspx")
                {
                    Constraints = new RouteValueDictionary(new
                    {
                        action = "List|Details|Edit|Insert"
                    }),
                    Model = DefaultModel
                });

    where the word "action" refers to the action performed on a table.

     

    The cause is in line 65 of internal static bool IsColumnInDictionary(IMetaColumn column, IDictionary<stringobject> values)  of System.Web.DynamicData.Misc:

                return values.ContainsKey(column.Name);

    Because of the route definition the "values" field has at least 2 entries "table" and "action"; and this line returns true when the a column.name is 'action'. It should probably not

     

    Conclusion the word "action" seems to be word reserved in DynamicData and should not be used to name an Entity, a column name or a foreign key

    When I renamed my entity to some other word, the problem disappeared

    Has anyone encountered this problem before?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 21, 2012 6:30 AM

All replies

  • User1137674169 posted

    Can not convert type 'System.String' to 'eoi.action' 

    Make sure your conversions are allowed.

    Tuesday, September 18, 2012 3:37 AM
  • User3866881 posted

    System.InvalidOperationException: Impossible de convertir le type 'System.String' en 'eoi.action'

    Hi

    A default conversion cannot allow you to do a convert from a string to your own type. Maybe you have to define it yourself with exclipt one, something like:

    public class Action
    {
      ………………
      public static exclipt operator Action(string s)
      {
           //Do ur own logic codes
      }
    }

    For more about exclipt, refer this:http://msdn.microsoft.com/en-us/library/xhbhezf4.aspx

    Tuesday, September 18, 2012 9:22 PM
  • User-2144969750 posted

    the error is in this Page_Init fuction the standard Dynamic Data List.aspx

        public partial class List : System.Web.UI.Page
        {
            protected MetaTable table;
    
            protected void Page_Init(object sender, EventArgs e)
            {
                table = DynamicDataRouteHandler.GetRequestMetaTable(Context);
                GridView1.SetMetaTable(table, table.GetColumnValuesFromRoute(Context));
                GridDataSource.EntityTypeFilter = table.EntityType.Name;
    
            } 

    it is the function call

        
    table.GetColumnValuesFromRoute(Context)
    

    that causes the error. The function "GetColumnValuesFromRoute" , as per http://msdn.microsoft.com/en-us/library/system.web.dynamicdata.metatable.getcolumnvaluesfromroute(v=vs.100).aspx , is part of the .NET framework. Possibly in there, there is something that cannot convert a string to an "eoi.action", which is of type EntityObject, part of System.Data.Objects.DataClasses NameSpace.

    I do not know why this is happening, as the eoi.action is generated by Visual Studio's Entity generator and I have no explanation on why this "GetColumnValuesFromRoute" return this error

    Has anybody another explanation or a hint to a solution?Cry

    Wednesday, September 19, 2012 6:12 PM
  • User-2106054853 posted

    Hi,

    It's caused by the Routedata (query string values) doesn't match the Column type in the meta table. You can set a breakpoint after you get the table object to debug. You can use watch window to debug.

    Use Reflector can also help you to understand the code logic of Dynamic Data. (assembly is C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Web.DynamicData.dll)

    internal IDictionary<string, object> GetColumnValuesFromRoute(HttpContextBase context)
    {
        RouteValueDictionary values = DynamicDataRouteHandler.GetRequestContext(context).RouteData.Values;     Dictionary<string, object> dictionary2 = new Dictionary<string, object>();
        foreach (MetaColumn column in this.Columns)
        {
            if (!Misc.IsColumnInDictionary(column, values))
            {
                continue;
            }
            MetaForeignKeyColumn column2 = column as MetaForeignKeyColumn;
            if (column2 != null)
            {
                foreach (string str in column2.ForeignKeyNames)
                {
                    dictionary2[str] = values[str];
                }
                continue;
            }
            dictionary2[column.Name] = Misc.ChangeType(values[column.Name], column.ColumnType);     }
        return dictionary2;
    }
    
     
    


     

    Wednesday, September 19, 2012 10:10 PM
  • User-2144969750 posted

    Thank you Allen for pointing to C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Web.DynamicData.dll where indeed the code is and can be looked at with reflector or ilspy)

    I was looking for it in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.DynamicData.dll, as shown in my project in the path property for the reference to this library; do not know why the project does not point to C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Web.DynamicData.dll directly.

    As the error I have is on the line

     dictionary2[column.Name] = Misc.ChangeType(values[column.Name], column.ColumnType);     

    which is inside a loop on all columns, I would like to know on what column of my metatable this is occurring; 

    Would love to trace execution of GetColumnValuesFromRoute Tongue Out

    Does somebody know if it is possible to trace execution of  GetColumnValuesFromRoute located in C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Web.DynamicData.dll, a part of the .NET Framework?

    Thursday, September 20, 2012 5:50 AM
  • User-2106054853 posted

    Hi,

    You can copy all the code in GetColumnValuesFromRoute to your application code (with slight modification such as replacing "this" to meta table object) and execute the copied code instead of calling this method directly. Some of the methods GetColumnValuesFromRoute calls are internal so you need to use Reflection to call it. You'll then be able to debug.

    Thursday, September 20, 2012 9:43 PM
  • User-2144969750 posted

    I could do that, although it seems a bit complicated; I will try Enable .NET Framework source stepping that should allow me to step into the source code of the GetColumnValuesFromRoute function

     Doing so I discovered that I cannot have an entity named "action" (referred to by eoi.action , eoi being the namespace) because that conflicts with the the route definition in the Global.asax.cs defined as

             routes.Add(new DynamicDataRoute("{table}/{action}.aspx")
                {
                    Constraints = new RouteValueDictionary(new
                    {
                        action = "List|Details|Edit|Insert"
                    }),
                    Model = DefaultModel
                });

    where the word "action" refers to the action performed on a table.

     

    The cause is in line 65 of internal static bool IsColumnInDictionary(IMetaColumn column, IDictionary<stringobject> values)  of System.Web.DynamicData.Misc:

                return values.ContainsKey(column.Name);

    Because of the route definition the "values" field has at least 2 entries "table" and "action"; and this line returns true when the a column.name is 'action'. It should probably not

     

    Conclusion the word "action" seems to be word reserved in DynamicData and should not be used to name an Entity, a column name or a foreign key

    When I renamed my entity to some other word, the problem disappeared

    Has anyone encountered this problem before?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 21, 2012 6:30 AM