[Mono-dev] NullReferenceException on a callvirt... with a non-null reference? (please help!)

Brian Crowell mono-devel at fluggo.com
Fri Jun 16 04:50:04 EDT 2006


Okay, while dealing with the whole AppDomains-should-be-empty-bug, I came across 
a strange phenomenon. After making sure that new AppDomains carry only the 
corlib, cross-domain calls to that AppDomain fail with a NullReferenceException.

After careful examination, I've determined that this exception occurs inside the 
xdomain-wrapper method created in metadata/marshal.c. Specifically, it occurs 
during the callvirt instruction that *would* carry out the last step of the 
cross-domain call-- calling the method on the object in the next domain.

Yet, by injecting Console.WriteLine calls into this code, I can show that the 
reference to the target object is, in fact, not null. So, I guess what I need to 
know is-- under what other conditions could a NullReferenceException occur on a 
callvirt (in x86)?

I have a feeling this may have to do with the fact that the called method and 
the calling method come from two instances of the same assembly. Example: I have 
one AppDomain which pulls its assemblies from /foo, and the second which pulls 
it assemblies from /bar. Under the original implementation, these AppDomains 
would carry the same assemblies; that is, the ones that come from the original 
AppDomain. Under the new implementation, the assemblies are separately loaded 
from /foo and /bar, like they should be. So maybe the call-wrapping doesn't take 
this into account?

I'm still working through this, but any help on this particular point would be 
appreciated.

--Brian



More information about the Mono-devel-list mailing list