473,416 Members | 1,659 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,416 software developers and data experts.

Need help, get error "Object does not match target type" in one instanceof an app, when others work

I get the above error in some of the ASP.NET web applications on a
server, and I need some help figuring out how to deal with it.

This is a rather long post, and I hope I have enough details that
someone who bothers to read all of it have some pointers.

Note, I have posted the stack trace and the code exhibiting the problem
further down so if you want to start by reading that, search for +++

Also note that I am unable to reproduce this problem in a smaller app,
otherwise I would try to post a working example that could be tested by
others.

Here's the deal.

I got a IIS6 web server hosted on W2K3 running a website containing
internal test instances of our web application. The web server does
nothing else and was explicitly set up for the purposes of these instances.

We have multiple databases hooked up and 3 different versions of the app
installed, so the basic setup is as follows:

- 3x versions
- 6x databases

Let's call the 3 versions version 1 through 3, and the databases
database A-F.

Since the instance name contain the version number (2, 3 and 3 digits
respectively) as well as the database name (which bears the name of the
customer we've gotten it from), the actual names of the instances
differs in lengths, varying from 17 to 20 characters. Since it doesn't
seem to be a pattern in that long instance names doesn't work and short
does, I assume that doesn't matter either.

The names all follow the following patterns:

ms_customer_date_ver

ms is for "Microsoft SQL Server", and we got "ora" for Oracle.
customer is customer name, either abbreviated or in full, only english
letters.
date is YYMMDD of the date the database was sent to us.
ver is 49, 499 or 410, depending on the version of the app.

The full (masked for security) url to one such database would be as follows:

http://our.internal.domain/ms_customer_070205_49/

18 instances in total. 3 and 3 share the same files, except for one line
in the web.config file with the connection string. Everything else has,
on the file level, been confirmed identical with a file comparing tool.

Files in the instances does not change after the app is loaded.

I set up the 18 web apps by first configuring the web site with the
default values, and then just adding 18 virtual directories below it,
pointing to each of the directories. The only thing I changed afterwards
was to point 6 and 6 versions to a separate app-pool, one for each
version. I added these app-pools after getting the error message, hoping
it would fix the problem, but it changed nothing so it apparently has no
bearing on it.

The strange thing now is that of the 18 instances, about 9 of them work.
I say "about" because it seems to be ill-tempered.

Version 1, all databases, work. Version 2, only one database works, and
version 3, 1 work all the time and the other only seems to work for a
short period of time after I restart the web server service.

There seems to be no apparent pattern to why these would work as I have
dropped and recreated the virtual directories inside IIS to try to fix
it. I also dropped and recreated one that worked and this one keeps on
working fine.

I tried separating out the 3 versions on their own 3 virtual web servers
with their own header hostnames on the same server, but if I can't get
this working I'm probably forced to split it up physically on different
servers.

Ok, that's the setup I've done, now I'll describe where the problem
appears. +++

The stack trace identifies the problem as the following line (at least
this is the last method in my own code that executes):

String previousValue = (String)pi.GetValue(this, args);

pi is of type PropertyInfo.
args is new Object[0]

The problem occurs in a base class used for descendant ORM objects, all
autogenerated. Some of these classes have one special property, of type
String, that needs to be auto-maintained on each update according to a
specific pattern. This is done by first finding the property, reading
the current value, passing that value through the update logic to get
the new value, and then writing it back.

For some objects (seemingly without a pattern), this fails on
pi.GetValue(...) with the mentioned exception message.

The code above is executed as part of the OnSaving() method for the
objects, before the object is persisted to the database.

Since the property name could be different on different objects, and not
all the objects have such a property, instead of looping through all the
properties on each save to see if any of them is such a special
property, I build a dictionary the first time, by finding all the types
in all the assemblies in the current appdomain, that have a property
tagged with a specific attribute. I keep track of the PropertyInfo
object for these properties.

The whole OnSaving method looks like this:

protected override void OnSaving()
{
base.OnSaving();

if (_ObjectsWithModificationHistories == null)
{
_ObjectsWithModificationHistories = new Dictionary<Type,
PropertyInfo>();

foreach (Assembly assembly in
AppDomain.CurrentDomain.GetAssemblies())
{
foreach (Type type in assembly.GetTypes())
{
if (type.IsDefined(typeof(PersistentAttribute), true))
{
foreach (PropertyInfo pi in GetType().GetProperties())
{
if
(pi.IsDefined(typeof(ModificationHistoryAttribute) , true) &&
pi.IsDefined(typeof(PersistentAttribute), true))
{
if (pi.PropertyType == typeof(String))
{
_ObjectsWithModificationHistories[type]
= pi;
break;
}
}
}
}
}
}
}

if (ModificationHistoryGeneration.Default != null &&
_ObjectsWithModificationHistories.ContainsKey(GetT ype()))
{
PropertyInfo pi = _ObjectsWithModificationHistories[GetType()];
Object[] args = new Object[0];

String previousValue = (String)pi.GetValue(this, args); // ***
String newValue =
ModificationHistoryGeneration.Default.GenerateNewV alue(previousValue);
pi.SetValue(this, newValue, args);
}
}

The first time the method is called, it finds that the dictionary is
null and thus creates it, by populating it with all the PropertyInfo
objects for all the properties for all the types, binding them to the
Type object for that type.

What I think is happening is some kind of pollution of the assemblies,
in that one class is found when the app is first executing this code,
and when the code is executed later, a different (but yet identical
enough to be found in the dictionary) Type object is used and thus the
GetValue(...) method fails.

The stack trace is as follows:

[TargetException: Object does not match target type.]
System.Reflection.RuntimeMethodInfo.CheckConsisten cy(Object target) +2329749
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture,
Boolean skipVisibilityChecks) +114
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
System.Reflection.RuntimePropertyInfo.GetValue(Obj ect obj, BindingFlags
invokeAttr, Binder binder, Object[] index, CultureInfo culture) +55
System.Reflection.RuntimePropertyInfo.GetValue(Obj ect obj, Object[]
index) +18
***LVK.Data.Persistence.XPBaseObjectEx.OnSaving() in
d:\Dev\VS.NET\Gatsoft\LVK.Data.Persistence\XPBaseO bjectEx.cs:270***
DevExpress.Xpo.XPBaseObject.DevExpress.Xpo.IXPObje ct.OnSaving() +7
DevExpress.Xpo.Session.TriggerObjectSaving(Object theObject) +65
DevExpress.Xpo.Session.PreProcessSavedList() +231
DevExpress.Xpo.Session.CommitTransaction() +63
DevExpress.Xpo.Session.ProcessingProcess(IDictiona ry
markedObjectsHolder, Object theObject) +113
DevExpress.Xpo.Session.Save(Object theObject) +15
DevExpress.Xpo.XPBaseObject.Save() +67
Gatsoft.Gat.BusinessLogic.Logging.Log.LogUserLogin Traffic(SystemSource
source) in d:\Dev\VS.NET\Gatsoft\Gatsoft.Gat.BusinessLogic\Lo gging\Log.cs:89
MyGat.Persistence.Session.WebContext.set_User(User Context value) in
d:\Dev\VS.NET\Gatsoft\Applications\Web\MinGat\MinG at_deploy\Source\App_Code\Persistence\Session\WebC ontext.cs:900
Gatsoft.Gat.BusinessLogic.Security.Login.Controlle rs.UserLoginController.ConfigureUserContext(UserAc count
account) in
d:\Dev\VS.NET\Gatsoft\Gatsoft.Gat.BusinessLogic\Se curity\Login\Controllers\UserLoginController.cs:60 1
Gatsoft.Gat.BusinessLogic.Security.Login.Controlle rs.WebUserLoginController.Login()
in
d:\Dev\VS.NET\Gatsoft\Gatsoft.Gat.BusinessLogic\Se curity\Login\Controllers\WebUserLoginController.cs :353
gtw.frmLogin.btLogin_Click(Object sender, EventArgs e) in
d:\Dev\VS.NET\Gatsoft\Applications\Web\MinGat\MinG at_deploy\Source\frmLogin.aspx.cs:389
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEven t(String
eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

I apologize for the low readability of this but the usenet posting
program wordwraps.

I've added *** to the above stacktrace to last (topmost) call that is
our code. I've added *** to the code posted above the stacktrace for
what corresponds to line 270.

The application relies on a bunch of assemblies, all working together,
and I've verified that the correct versions of them all has been copied
to the web directory. Also, since another copy of the same version, just
with a different connection string, works fine, I don't think this is
the problem.

I tried adding some code to dump the version numbers of the files in
question, as well as paths, etc. and it all matches up to what I expect
for each instance.

Can anyone see a flaw, or know something that could point me in the
right direction? *Anything* would help.

--
Lasse Vågsæther Karlsen
mailto:la***@vkarlsen.no
http://presentationmode.blogspot.com/
Nov 27 '07 #1
1 7067
Solved!

Bug in the loop at the bottom.

The code essentially did this:

- foreach assembly in appdomain
--- foreach type in assembly
------ if type is to be included
--------- find all properties in *current type*

that was the bug, did not use the type I was currently iterating for,
and minor differences in the databases meant that for some databases one
object was the first to be saved, in other it was another object, which
meant that it used one object as a template for wether *all other*
objects had this special string property or not.

Removed the rest of the code, see the parent post if you really want to
look at it.

--
Lasse Vågsæther Karlsen
mailto:la***@vkarlsen.no
http://presentationmode.blogspot.com/
Nov 27 '07 #2

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

Similar topics

7
by: Ryan Park | last post by:
Hi, //SITUATION I got a panel control that hold a certain position on a form. Every controls or UIs are on this panel. At certain situation, I called dispose() method of this panel control...
3
by: Steve Lutz | last post by:
Hi All, I have a Windows Service that runs well. The service hosts a remote object. The purpose of the object is so that I can "peak" into the service to see what it's doing. I wrote a small...
3
by: Karel Vandenhove | last post by:
Hi, I get an error "cannot apply indexing with to an expression of type object" when I try to compile the code below. SSLScannerManager is a COM component. (Used to access fingerprint...
0
by: David P. Donahue | last post by:
I'm using C# to create an ASP .NET website backed by a MySQL database. One of the things I do often on the site is populate a DataList by binding it to a DataSet pulled from the database. However,...
0
by: Dica | last post by:
i'm getting an error when trying set my dataAdapter's selectCommand. the sqlStatement is a storedProc which takes parameters, so it's constructed as: sqlSelectCommand1.CommandText = ""; ...
4
by: bob95226 | last post by:
Hi All, I wrote a VB.NET control in Visual Studio 2003 IDE, I am trying to re-compile it with command line compiler vbc.exe like this: vbc /t:library /out:my_control.dll my_control.vb However...
35
by: Chris | last post by:
Hi, I tried to create a class which must change the propety 'visible' of a <linktag in the masterpage into 'false' when the user is logged. But i get the error: "Object reference not set to an...
11
by: narpet | last post by:
Hello all, I'm hoping somebody can help me with this. I have an app that I've been developing in MS Visual Studio 2005 Pro, C#. I have connectivity to a SQL server database. All of the sudden,...
2
by: =?Utf-8?B?U3dhcHB5?= | last post by:
hi, I am working on application in this i am using two files. In first (consider A) file i am calling the function of other file (consider B). In that function of file B i am calling the method...
3
by: Sarah | last post by:
Hi - Please be gentle. I am quite new to visual basic, but I have been going through tutorials and reading up. I found a code snippet on the internet that I wanted to see if I could re-purpose...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.