Hi Wayne,
> You're correct. Even after adding the serialization, it still
> complained about not being able to find the assembly where
> that custom exception is defined.
Exactly. Think of the serialized data as being the ingredients
and the assembly as containing the recipe for how too mix them
to create your cake - I mean object. :-)
> Is there a way to solve that? It seems that NUnit could
> catch that event that it can't resolve the assembly and then
> resolve it itself. I learned about that while researching
> this problem and tried it but they problem, I think, was that
> the event was happening in the "other" AppDomain. That was
> before I realized NUnit created 2 of them.
Not sure which one you mean by "other" but it probably doesn't
matter. Strictly speaking, NUnit creates one of them - your
test domain. The primary AppDomain is created by the runtime
for NUnit to run in.
> It seems NUnit could add that features to assume that
> whatever DLL it can't find will be in the same folder as the
> assembly under test. (That's where mine is).
It's not impossible, but a bit messy.
> However, I confess, that will not always solve it for everyone.
>
> But we should be able to find a smart generalized solution.
Yes, it would be better to devote time to a general solution.
Think of the problem this way: Two programs need to communicate -
nunit-console and your test. These two programs may be in different
AppDomains of the same process, or in different processes or even
on different computers. They can only do that by sharing some common
structure that they both define. Then they can use serialization,
.NET remoting, TCP, etc. but without that shared structure, there
can be no real communication - just bytes going back and forth.
Really, I was being approximate. The two programs in question are
actually two parts of NUnit, one of which is injected into the
appdomain/process/machine on which your tests are running. They
*can* share a common structure, which is how to solve this
problem. But that common structure can't be your custom
exception. It needs to be some generalized information
representation - like text, JSON or xml. That's our path
for the future.
> My interest in this wanes since I have now learned myself and
> have fixed my root problem.
Oh no! We were just starting to have fun. :-)
> But I spent almost 6 hours figuring this out due to the
> useless stack trace.
>
> IN FACT, a much better solution would be to recognize in
> NUnit (as you said earlier) that the stack trace is a
> SerializationException and therefore, most likely, useless so
> it could then log a message like this"
>
> WARNING: The stack trace below is likely useless because
> NUnit was unable to serialize a custom exception into the
> primary AppDomain. To figure out this exception you need to
> catch the exception inside your AppDomain handling the
> AppDomain.UnhandledException and the
> Application.ThreadException events.
>
> The the stack trace can follow since it might be useful in rare cases.
I don't think so - although it may be useful to me in fixing
this. That's because it's an exception thrown at the point where
NUnit is trying to access your exception - the stacktrace has
nothing whatsoever to do with your code. But we could still
construct a message that would point you in the right
direction.
It would be helpful if you could file a bug on this so
we don't forget to do something about it.
Charlie
> System.Runtime.Serialization.Formatters.Binary.__BinaryParser.
> ReadObjectWithMapTyped
>
> (BinaryObjectWithMapTyped record)
> at
>
> System.Runtime.Serialization.Formatters.Binary.__BinaryParser.
> ReadObjectWithMapTyped