473,574 Members | 2,692 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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_dat e_ver

ms is for "Microsoft SQL Server", and we got "ora" for Oracle.
customer is customer name, either abbreviated or in full, only english
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:


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

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.GetV alue(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 (_ObjectsWithMo dificationHisto ries == null)
_ObjectsWithMod ificationHistor ies = new Dictionary<Type ,
PropertyInfo>() ;

foreach (Assembly assembly in
AppDomain.Curre ntDomain.GetAss emblies())
foreach (Type type in assembly.GetTyp es())
if (type.IsDefined (typeof(Persist entAttribute), true))
foreach (PropertyInfo pi in GetType().GetPr operties())
(pi.IsDefined(t ypeof(Modificat ionHistoryAttri bute), true) &&
pi.IsDefined(ty peof(Persistent Attribute), true))
if (pi.PropertyTyp e == typeof(String))
_ObjectsWithMod ificationHistor ies[type]
= pi;

if (ModificationHi storyGeneration .Default != null &&
_ObjectsWithMod ificationHistor ies.ContainsKey (GetType()))
PropertyInfo pi = _ObjectsWithMod ificationHistor ies[GetType()];
Object[] args = new Object[0];

String previousValue = (String)pi.GetV alue(this, args); // ***
String newValue =
ModificationHis toryGeneration. Default.Generat eNewValue(previ ousValue);
pi.SetValue(thi s, 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.Reflecti on.RuntimeMetho dInfo.CheckCons istency(Object target) +2329749
System.Reflecti on.RuntimeMetho dInfo.Invoke(Ob ject obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture,
Boolean skipVisibilityC hecks) +114
System.Reflecti on.RuntimeMetho dInfo.Invoke(Ob ject obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
System.Reflecti on.RuntimePrope rtyInfo.GetValu e(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] index, CultureInfo culture) +55
System.Reflecti on.RuntimePrope rtyInfo.GetValu e(Object obj, Object[]
index) +18
***LVK.Data.Per sistence.XPBase ObjectEx.OnSavi ng() in
d:\Dev\VS.NET\G atsoft\LVK.Data .Persistence\XP BaseObjectEx.cs :270***
DevExpress.Xpo. XPBaseObject.De vExpress.Xpo.IX PObject.OnSavin g() +7
DevExpress.Xpo. Session.Trigger ObjectSaving(Ob ject theObject) +65
DevExpress.Xpo. Session.PreProc essSavedList() +231
DevExpress.Xpo. Session.CommitT ransaction() +63
DevExpress.Xpo. Session.Process ingProcess(IDic tionary
markedObjectsHo lder, Object theObject) +113
DevExpress.Xpo. Session.Save(Ob ject theObject) +15
DevExpress.Xpo. XPBaseObject.Sa ve() +67
Gatsoft.Gat.Bus inessLogic.Logg ing.Log.LogUser LoginTraffic(Sy stemSource
source) in d:\Dev\VS.NET\G atsoft\Gatsoft. Gat.BusinessLog ic\Logging\Log. cs:89
MyGat.Persisten ce.Session.WebC ontext.set_User (UserContext value) in
d:\Dev\VS.NET\G atsoft\Applicat ions\Web\MinGat \MinGat_deploy\ Source\App_Code \Persistence\Se ssion\WebContex t.cs:900
Gatsoft.Gat.Bus inessLogic.Secu rity.Login.Cont rollers.UserLog inController.Co nfigureUserCont ext(UserAccount
account) in
d:\Dev\VS.NET\G atsoft\Gatsoft. Gat.BusinessLog ic\Security\Log in\Controllers\ UserLoginContro ller.cs:601
Gatsoft.Gat.Bus inessLogic.Secu rity.Login.Cont rollers.WebUser LoginController .Login()
d:\Dev\VS.NET\G atsoft\Gatsoft. Gat.BusinessLog ic\Security\Log in\Controllers\ WebUserLoginCon troller.cs:353
gtw.frmLogin.bt Login_Click(Obj ect sender, EventArgs e) in
d:\Dev\VS.NET\G atsoft\Applicat ions\Web\MinGat \MinGat_deploy\ Source\frmLogin .aspx.cs:389
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +105
System.Web.UI.W ebControls.Butt on.RaisePostBac kEvent(String
eventArgument) +107
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring
eventArgument) +7
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain(Boolean
includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +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***@vk arlsen.no
Nov 27 '07 #1
1 7090

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***@vk arlsen.no
Nov 27 '07 #2

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

Similar topics

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 and change it with other panel which contains other business logic and UI controls.
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 Windows Application that connects to the remote object and prints out status information. Everything works fine when I first start the service....
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 scanners and developed by neurotechnologija) How does one get an array from a com component?
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, I'm running into a bit of a problem with a specific field type in the database. It seems that fields of type TEXT (a kind of binary way of...
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 = ""; sqlSelectCommand1.CommandType = System.Data.CommandType.StoredProcedure; sqlSelectCommand1.Connection = sqlConnection1; ...
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 vbc doesn't work with error "type 'Int32' is not defined" Your help would be greatly appreciated!
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 instance of an object" for the line 'If mpg.FindControl("lkred").Visible = True Then'. I couldn't find sofar the solution. Any help would be...
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, whenever I try to add a new or change an existing data binding to a text box (as an example), it gives me the error, "object reference not set to an...
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 of DLL. i.e Method of file A -Method of file B -Method of DLL. But in the file B's method while calling DLL's method it is giving me Error...
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 for a project, but I keep getting the error: "Object reference not set to an instance of an object" for the 7th line of the code below which is:...
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.