|
Hi,
This ia quite an urgent problem I have here, my project is slipping too far and I have a racing festival to launch my code for very soon so any help would be appreciated!
I have the following code, which is broken down into a more managable form, during the debugging process:
1: object o=new MembershipLevel().FindByItemCode(itemCode);
2: MembershipLevel membershipLevel=o as MembershipLevel;
Now, line 1 successfully extracts a record from the database and populates o accrdingly, with a MembershipLevel object. It's great, I can see it's the correct record, and it is the correct type.
Line 2 is used to cast the type into something so I can get at the data inside it. However, this cast fails. In its original shorthand form of { MembershipLevel membershipLevel=(MembershipLevel)o }, this threw an exception InvalidCast excpetion saying "Cannot cast MembershipLevel into MembershipLevel", so it knows the types are same, but it will not cast it!
MembershipLevel has been loaded via reflection from the web site bin folder. Interestingly, a previous object has also been loaded using the same method and that works fine. Also, this code is in the same assembly. The assembly is present and correct.
Any help appreciated
|
|
|
|
|
My best guess would be that you have two classes with the same name, but in different namespaces. After step 1, try comparing the following two statements, and see if they match:
o.GetType().ToString()
typeof(MembershipLevel).ToString()
Alternatively, it might be the same type, but a different signature. You said you're loading it through reflection, so the file you're loading might have an older version of "MembershipLevel". If the signatures don't match, you can't cast it.
|
|
|
|
|
Thanks for your reply.
The namespaces are identical, I removed them from the code I posted for clarity. (They are quite deep and had company names in)
For your second point, this does seem likely, but I am quite sure it is loading and debugging from the same assembly. I can cast fine in the debugger immediate window, just not in the code. The file is in the bin folder in the web site, where else could it be getting the class? It is in a class library.
HOw can I tell? Particularly if the debugger casting works fine?
|
|
|
|
|
Hmm, it works in the debugger but not in the code itself?
I'm running out of ideas here. There might be some quirk with ASP, which I'm not very familiar with. My best guess is still a duplicate class name. The debugger might be resolving it differently, so try outputting the type name in the code just to be sure.
Other than that, I really can't tell you much without knowing more about the code.
|
|
|
|
|
If you are doing this in ASP, then you might have an older definition of the class sitting around in the IIS compile cache. You may have to try clearing that out and see if it helps. I've had these issues before....and it always is something that I've done or another developer has done. In one case, my test class worked perfectly. But it turned out a web developer created reference to a hard dll location instead of Project Output and the ASP code was executing my code to get the object then using the old reference in the web app for casting. Grrrrrr.
Unfortunately, this is not something that is quick to fix if your solution is huge. Clean out the solution, make sure the dll isn't in any bin or obj folder, make sure there is only a single instance of pubic class ObjectType (sorry I forgot the object name you were erring out on) by doing a solution level Find and also by doing a file-level search with a search string.
I cannot find on my machine where ASP.NET caches the compiles. Maybe someone else here can help.
|
|
|
|
|
Oops, I replied with this info to the wrong person. If you're running in ASP or not -- here are some things to consider.
If you are doing this in ASP, then you might have an older definition of the class sitting around in the IIS compile cache. You may have to try clearing that out and see if it helps. I've had these issues before....and it always is something that I've done or another developer has done. In one case, my test class worked perfectly. But it turned out a web developer created reference to a hard dll location instead of Project Output and the ASP code was executing my code to get the object then using the old reference in the web app for casting. Grrrrrr.
Unfortunately, this is not something that is quick to fix if your solution is huge. Clean out the solution, make sure the dll isn't in any bin or obj folder, make sure there is only a single instance of pubic class ObjectType (sorry I forgot the object name you were erring out on) by doing a solution level Find and also by doing a file-level search with a search string.
I cannot find on my machine where ASP.NET caches the compiles. Maybe someone else here can help.
|
|
|
|
|
Thanks for all your help, guys.
I'm at home now, but I will certainly apply your ideas tomorrow. I have tried many of them, I'm afraid!
Your right, my solution is huge, and that is why it is difficult for me to post more code, because it would complicate the whole thing.
If I'm right, the code cache is in /Windows/Microsoft.NET/Framework/v2.0.5727/Temporary ASP.NET Files ... and I cleared this folder out after recycling IIS.
Still doesn't work.
I will try and delete all instances of the DLL on the machine, as you suggested, and try it.
|
|
|
|
|
Hi all.
Thanks for your help for this so far.
I have tried your suggestions, including:
* Purging all traces of the DLL and rebuilding
* Verifying this is the same class by searching for other classes
With no success.
I have output some extra debug info:
CodeBase of o is file:///C:/Inetpub/Sitecore53SandPit/WebSite/bin/Duke.IomTT.TTLive.DLL, v0.1.0.18554
CodeBase of MembershipLevel is file:///C:/Inetpub/Sitecore53SandPit/WebSite/bin/Duke.IomTT.TTLive.dll, v0.1.0.18554
So, even though it is the same class, and I can see inside the object in the debugger, has the same data - I cannot cast it.
Really stuck!
|
|
|
|
|
If I said I think it might be a file locking issue, would it jog memories?
|
|
|
|
|
Not much of help but.. I would try to look at typeof(o)==typeof(MembershipLevel). Is it false? If yes, why? Look at all (relevant) properties, like FullName...
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
i have a combobox it loads it's data during the loadform
but i want to add this combobox to the specific cell of the datagridview
that is because i want to use the combobox events , that is why i dont like to add a DataGridViewComboBoxColumn
pleas how can i do this
thanks for help
MD_NADA
|
|
|
|
|
Adding a control to a Datagrid has been asked quite alot here. Search the forums to find the answer, I'm sure it's been posted.
|
|
|
|
|
Thank u
but i think u didnt read my question well
i ask about DataGridView not DataGrid
if u know how can i achieve this pls write 2 me
i find how can i add combobox in the datagridview
but it is a templet
so , my case i want 2 add a control from the controls exmple a control that i have it on the form like the combobox
in specific column when i click on that cell
i hope u can get what i mean
MD_NADA
|
|
|
|
|
|
thanks dude. Even i wanted some information on the same.
Keshav Kamat
India
|
|
|
|
|
I am getting the following error and I don't know why...
The given ColumnName 'RS-I2' does not match up with any column in DataSource.
System.Collections.ListDictionaryInternal
That Column name does exist in the datasource, and my column names & mappings are correct. Does anyone have any ideas? Thanks =)
|
|
|
|
|
Maybe the hyphen in your column name causes troubles to database. try to surround the name with square brackets, i.e. [RS-I2] .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
In my code I have the column name in brackets. It's only in the error message that it doesn't have the brackets, I thought that to be a bit strange. Also, I also few other columns that have a hyphen in them, I am only getting the error on that specific one.
-- modified at 17:12 Tuesday 1st May, 2007
|
|
|
|
|
No, this is not strange since brackets usually are not reported on error messages. I'm still doubting about the hyphen...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
bcp.ColumnMappings.Add(new SqlBulkCopyColumnMapping("RS-I2", "[RS-I2]"));
It's in brackets right there, I'm at a loss. I am about to light myself on fire and start punching myself in the face
|
|
|
|
|
Hi,
I tried to formart a double to a 10 digits, and 5 fixed points string.
say if I have a double variable with a value as "512.297812223" and want it to be displayed as " 512.29781"
I surveyed the internet , but seems not finding a solution for this issue.
You help is much appreciated.
Meng
|
|
|
|
|
.ToString("####0.00000")
---
single minded; short sighted; long gone;
|
|
|
|
|
And
System.Console.Write ( "{0:####0.0000}" , 123.456789 ) ;
|
|
|
|
|
how can I use date/time in c# to get only the time.....?
lavi
|
|
|
|
|
lavy2883 wrote:
how can I use date/time in c# to get only the time.....?
DateTime.Now.TimeOfDay(); -> returns Timespan
DateTime.Now.ToLongTimeString(); -> returns hh:mm:ss
DateTime.Now.ToShortTimeString(); -> returns hh:mm
|
|
|
|