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
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
}
}
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?
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;
}
Sincerely,
Allen Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
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.
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
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?
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.
Sincerely,
Allen Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
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 internalstaticbool IsColumnInDictionary(IMetaColumn column, IDictionary<string, object> 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
Member
10 Points
20 Posts
unable to convert type 'System.String' into a dependent
Sep 17, 2012 07:47 AM|ejay|LINK
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:
Informations sur la version : Version Microsoft .NET Framework :4.0.30319; Version ASP.NET :4.0.30319.17929
Member
351 Points
209 Posts
Re: unable to convert type 'System.String' into a dependent
Sep 18, 2012 03:37 AM|graciax8|LINK
Can not convert type 'System.String' to 'eoi.action'
Make sure your conversions are allowed.
My Codepad@Blogspot.com ||
All-Star
94130 Points
18109 Posts
Re: unable to convert type 'System.String' into a dependent
Sep 18, 2012 09:22 PM|Decker Dong - MSFT|LINK
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:
For more about exclipt, refer this:http://msdn.microsoft.com/en-us/library/xhbhezf4.aspx
Member
10 Points
20 Posts
Re: unable to convert type 'System.String' into a dependent
Sep 19, 2012 06:12 PM|ejay|LINK
the error is in this Page_Init fuction the standard Dynamic Data List.aspx
it is the function call
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?
All-Star
31432 Points
4884 Posts
Re: unable to convert type 'System.String' into a dependent
Sep 19, 2012 10:10 PM|Allen Chen – MSFT|LINK
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)
Allen Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Member
10 Points
20 Posts
Re: unable to convert type 'System.String' into a dependent
Sep 20, 2012 05:50 AM|ejay|LINK
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
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
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?
All-Star
31432 Points
4884 Posts
Re: unable to convert type 'System.String' into a dependent
Sep 20, 2012 09:43 PM|Allen Chen – MSFT|LINK
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.
Allen Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Member
10 Points
20 Posts
Re: unable to convert type 'System.String' into a dependent
Sep 21, 2012 06:30 AM|ejay|LINK
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
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<string, object> values) of System.Web.DynamicData.Misc:
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?