473,385 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

ObjectDataSource, DataObjectTypeName and '...could not find a non-generic method ...'

Hi Everyone,
This Saturday the stage was set. The problem simply could not go on
existing -- it had to be solved. Many hours, articles, compilations
and frustrations later I still did not find an answer. Even pacing
around my flat until I nearly went into an altered state of reality
proved futile.

So here is the problem...

When I link up the ObjectDataSource UpdateMethod to a method in the
TypeName class that takes individual parameters (using
'<UpdateParameters... </UpdateParameters>') all is well. Eg.

<asp:ObjectDataSource ID="ObjectDataSource1"
Runat="server"
EnableCaching="false"
TypeName="RecipeToolUI.MaterialComponent"
SelectMethod="GetMaterials"
UpdateMethod="UpdateMaterial"
OldValuesParameterFormatString="{0}"
<UpdateParameters>
<%-- just a lot of prameters --%>
</UpdateParameters>
</asp:ObjectDataSource>

When I try to link up a method that takes an object (using
DataObjectTypeName) instead of individual value types like this:

...
DataObjectTypeName='RecipeTool.Material'
...

I keep on getting this error:
"""
ObjectDataSource 'ObjectDataSource1' could not find a non-generic
method 'UpdateMaterial' that takes parameters of type
'RecipeTool.Material'.
"""

Things I have tried (besides the pacing):
0. Using only VS 2005 to link things up.

1. Adding attributes to the UpdateMethod method in the
DataObjectTypeName class, as well as to the class itself.

This only resulted in VS seeing the method (in the ObjectDataSource
configuration wizard), but it does not solve the problem.

2. Tried various method signatures.

3. Deleted the Asp.Net temporary files.

4. Changed namespaces, method names, class names. This proved that
the compiler/runtime can find the class, but not the method.

Any suggestions or help will be greatly appreciated.

Regards.

Sep 3 '07 #1
9 8789
Are you using OldValuesParameterFormatString?

If so, are you providing a method
RecipeToolUI.MaterialComponent.UpdateMaterial which takes both old and
new values?
Sep 3 '07 #2
On Sep 3, 11:04 pm, Muhammad Naveed Yaseen <mnyas...@gmail.comwrote:
Are you using OldValuesParameterFormatString?

If so, are you providing a method
RecipeToolUI.MaterialComponent.UpdateMaterial which takes both old and
new values?
Hi, thanks for responding hey!

I have used OldValuesParameterFormatString="{0}", and left it out
completely, while specifying ConflictDetection="OverwriteChanges".
This should cause the runtime to request a function taking a single
object argument (that specified in DataObjectTypeName) as parameter.

I have also tried setting OldValuesParameterFormatString="{0}", and
leaving it out, while setting ConflictDetection="CompareAllValues" and
then I also provided (in addition to the single object parameter
method) a method taking two objects (just as the docs say, one for the
old, one for the new values).

It seems to me as if the way the runtime looks up methods when you
specify DataObjectTypeName, as apposed to when you provide
'<UpdateParameters... </UpdateParameters>' differ.
I have also noticed the following. When trying to configure the
ObjectDataSource in VS, two entries for the business objects appear in
the dropdown lists (eg. when selecting what object the
ObjectDataSource must use for the TypeName, there are two entries for
RecipeTool.Material, and all the other objects in namespace
RecipeTool).

Could it be due to two versions of everything in RecipeTool being
visible to the runtime, and that for some reason, using
DataObjectTypeName (as apposed to specifying UpdateParameters) makes
the ObjectDataSource choose the wrong DataObjectTypeName to look for
while trying to identify the right method to call in class specified
by TypeName?

In other words, the 'public void UpdateMaterial (Material m)' method
in the TypeName class 'MaterialComponent' use one version of the
'Material' class, while the ObjectDataSource's DataObjectTypeName
refers to another version of the 'Material' class?

How can I check this? How can I remove the extra classes (that might
be causing the problem)?

Thanks in advance again!

Sep 3 '07 #3

Have you ensured that

1) The type 'RecipeTool.Material' is constructible without parameter
(i.e. it's default public parameterless contructor isn't suppressed by
presence of parameter constructors or private parameterless
constructor)

2) The type 'RecipeTool.Material' has matching public get-set
properties for all fields with exact spelling match

3) If InsertMethod or DeleteMethod are being called, those are also
using same type (RecipeTool.Material)

4) The methods SelectMethod, InsertMethod and DeleteMethod are public
and either,,,

a) static
b) OR public parameterless constructor is not suppressed by presence
of parameter constructors or private parameterless constructor.
c) OR an object instance provided in ObjectCreating event

If it is still not working with these conditions being true, I would
be keen to look into the code. Kindly post here or drop at
mn******@gmail.com
Regarding the two types you are seeing in VS, if the leading
namespaces before these two types are same, then that is not a
problem. Sometimes VS does pick up same type more than once during
recursion. However if leading namespaces are different then that is
not right.

Sep 4 '07 #4
On Sep 4, 7:27 am, Muhammad Naveed Yaseen <mnyas...@gmail.comwrote:
Have you ensured that

1) The type 'RecipeTool.Material' is constructible without parameter
(i.e. it's default public parameterless contructor isn't suppressed by
presence of parameter constructors or private parameterless
constructor)

2) The type 'RecipeTool.Material' has matching public get-set
properties for all fields with exact spelling match

3) If InsertMethod or DeleteMethod are being called, those are also
using same type (RecipeTool.Material)

4) The methods SelectMethod, InsertMethod and DeleteMethod are public
and either,,,

a) static
b) OR public parameterless constructor is not suppressed by presence
of parameter constructors or private parameterless constructor.
c) OR an object instance provided in ObjectCreating event

If it is still not working with these conditions being true, I would
be keen to look into the code. Kindly post here or drop at
mnyas...@gmail.com

Regarding the two types you are seeing in VS, if the leading
namespaces before these two types are same, then that is not a
problem. Sometimes VS does pick up same type more than once during
recursion. However if leading namespaces are different then that is
not right.
Hi Muhammad,
Thanks again for your help, I really appreciate it. It would be hard
to give you relevant code samples short of giving you the whole
project because things are tied up a bit.

I have carefully confirmed that all of the above assertions are true.
While reading through a sample of what I want to do, I saw that the
sample place the TypeName class in the App_Code folder, while mine is
in a folder just off the root of the project.

After placing It in App_Code I got an error I had long before (which I
solved back then by taking the code out of App_Code):

"Unable to cast object of type 'RecipeTool.Logic.Material' to type
'RecipeTool.Logic.Material'.".

(I added the 'Logic' namespace a bit earlier, placing all the logic
classes there, but it could just as well not be there -- does not
influence anything.)
This error is thrown from within the method I could not get at before,
(the UpdateMethod), but now the SelectMethod also throws this error at
spots where I try to cast from objects returned by NHibernate -- a
kind of ORM library I am using. Note that the SelectMethod and
UpdateMethod (with value type parameters) both work fine while the
class they are in is not in App_Code.

I strongly suspect there being two versions of Material, but how can I
remove the one?

Sep 4 '07 #5
One possible place where shadow copy of a type may exist is asp.net
compiler cache (usually C:\windows\Microsoft.NET\Framework
\v2.0.50727\Temporary ASP.NET Files).

If I would be in this situation I would have proceeded like following.

1) Ensure that type 'RecipeTool.Logic.Material' has public scope and
not internal (i.e. ***public*** class Material,,, instead of class
Material)

2) Delete contents of C:\windows\Microsoft.NET\Framework
\v2.0.50727\Temporary ASP.NET Files (may have to stop IIS or restart
computer to delete contents)

3) Now compile again and see if we still get the error.

4) If still getting error, then take the grid and object to a new
temporary working solution (remove all dependancies, as purpose here
is not make it 100% in temporary solution but to find out which
component is causing shadow copy)

5) After ensuring simple most version is working in temporary
solution, would add other components to this solution, and after each
addition see if it is still working. Wherever it stop working, that
component may be the culprit (perhaps an undetected cricular
reference, or too deeply nested types/controls)
Sep 4 '07 #6
On Sep 4, 6:51 pm, Muhammad Naveed Yaseen <mnyas...@gmail.comwrote:
One possible place where shadow copy of a type may exist is asp.net
compiler cache (usually C:\windows\Microsoft.NET\Framework
\v2.0.50727\Temporary ASP.NET Files).

If I would be in this situation I would have proceeded like following.

1) Ensure that type 'RecipeTool.Logic.Material' has public scope and
not internal (i.e. ***public*** class Material,,, instead of class
Material)

2) Delete contents of C:\windows\Microsoft.NET\Framework
\v2.0.50727\Temporary ASP.NET Files (may have to stop IIS or restart
computer to delete contents)

3) Now compile again and see if we still get the error.

4) If still getting error, then take the grid and object to a new
temporary working solution (remove all dependancies, as purpose here
is not make it 100% in temporary solution but to find out which
component is causing shadow copy)

5) After ensuring simple most version is working in temporary
solution, would add other components to this solution, and after each
addition see if it is still working. Wherever it stop working, that
component may be the culprit (perhaps an undetected cricular
reference, or too deeply nested types/controls)
I tried deleting the temp files before but will give it a go again,
thanks.
>From some debug printouts at the point where the cast fails I saw that
the two objects came from different assemblies.
The one instanciated from within code in App_Code came from a
'App_Code.asdfsd' assembly, and the one loaded from the NHibernate
classes (called in App_Code, but through the NHibernate classes)
belonged to the proper 'RecipeTool' assembly -- will post the details
later -- so I can understand why they can't be casted.

Now my question is how to force code to use the proper 'RecipeTool'
assembly instead of the `on-the-fly` generated assemblies... I would
really like to know which VS solution template to use for what
situation or, better still, how to compile things by use of the
command line tools, or the msbuild tools so that one can have a solid
control of what is compiled and where.

There is a reason why tools like Ant exists: building anything larger
than a couple of files becomes complicated. Have seen NAnt, which I
assume to be a .Net port of Ant?

Sep 4 '07 #7
On Sep 5, 3:30 am, Muhammad Naveed Yaseen <mnyas...@gmail.comwrote:
Following links may be useful for manual compilation.

http://msdn2.microsoft.com/en-us/lib...1/11/3415.aspx
Good news!! I think I found a solution!

At the point where the cast failed, I managed to get debug output (by
printing 'typeof(Material).AssemblyQualifiedName' and 'q.List()
[0].GetType().AssemblyQualifiedName'):
-----
RecipeTool.Logic.Material, App_Code.-0vbez6p, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
RecipeTool.Logic.Material, RecipeTool, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
----
(the list 'q' contains the loaded objects)

Then I followed these steps:
created a new "C# Web Application Project"
copied everything relevant in
made sure it compiles
"Build" "Publish RecipeTool"
create a virtual directory there where I just published
brows to that virtual directory

and it works!

Now the debug output gives:
----
RecipeTool.Logic.Material, RecipeTool, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
RecipeTool.Logic.Material, RecipeTool, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
----

Still need to test if everything is solved now, but it looks like the
ObjectDataSource now correctly identifies the UpdateMethod.

Thank you very much for the help man!

Until next problem , all the best.

Sep 5 '07 #9
I, too have been wrestling with this one for quite some time and finally
found a solution last night.

The problem seems to occur when you create a selection statement in the
table adapter that uses more fields than the update statement uses. When you
update, it is still seeking for the parameter that the select statement uses,
even when you have removed all other references to it.

I tried everything I ever found posted online for this one to no avail.
Finally, I ended up building a stored procedure for my update statement, and
here's the key... I included in the stored procedure a reference to the
parameter that was not used, but then I simply did nothing with that
parameter in my update statement. This way, .NET was happy because it passed
the parameter, and the update statement ran okay because it did nothing with
the parameter other than capture it in the stored procedure.

Hopefully this will save someone all the time that it cost me to figure it
out!

--
Tony L
Albuquerque, NM
Oct 2 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: MTomov | last post by:
Hi fellas, has anyone managed to get ObjectDataSource to work Datasets where the Dataset is used as BusinessEntity class? What I mean is the following architecture: 1.WebPage with...
3
by: Jeronimo Bertran | last post by:
I have a FormView that shows details of a specific record on a table. The SelecMethod returns a DataSet that includes all the fields from my Event table and other read-only fields from linked...
4
by: Joe | last post by:
I need to do a find/replace on a column name in DataColumn.Expression. Is there a way to do the following using RegEx? MyColumn 10 and Desc = "This is MyColumn desc" I need to replace the...
3
by: 13 | last post by:
Hello list, I have been searching the internet for python version 0.9.0 sources which had been posted to alt.sources list, but without any luck. Maybe someone has it available somewhere ? ...
0
by: GMartin | last post by:
I have a pop-up form with a three columned Grid that has checkboxes in a Template Column in the first/left-most column. (The form is to allow users to select "Members" of a group, where they check...
1
by: Allan Ebdrup | last post by:
I have a asp.net v2 website that runs fine on our development server. I have published the website to a stage server and it runs fine, but when I publish it to production I get the following error:...
2
by: tawright915 | last post by:
Ok so here is my regex (--.*\n|/\*(.|\n)*?\*/). It finds all comments just fine. However I want it to return to me all strings that are not commented out. Is there a way to exclude the comments...
2
by: SM | last post by:
Ok, this must be simple but the more i search the more i don't find. It's about SimpleXML and PHP. How to find non-existing nodes or nodes with no text My XML file looks a little bit like this:...
1
by: SM | last post by:
Ok, this must be simple but the more i search the more i don't find. It's about SimpleXML and PHP. How to find non-existing nodes or nodes with no text My XML file looks a little bit like this:...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.