Object is not from this UnitOfWork - eclipselink

I get an error saying:
Exception [EclipseLink-6004] ... The Object bla bla is not from this UnitOfWork object space, but from the parent session's. The Object was never registered with this UnitOfWork.
This is an exception that pops up at random. Does anyone have a clue as to how to solve the issue?
thank you for your advice,
Micha

It means you have somehow corrupted your persistence context. Most likely by mixing detached and managed objects.

Related

VB.NET Track COM RCW error

I have a really big project that I can not easily strip down.
When the application is being closed, I get the error
"InvalidComObjectException: A COM object that has been disconnected from the RCW can not be used."
Details:
System.Runtime.InteropServices.InvalidComObjectException has occured.
HResult=-2146233049
Message=A COM object that has been disconnected from its RCW can not be used.
Source=mscorlib
StackTrace:
at System.StubHelpers.StubHelpers.StubRegisterRCW(Object pThis)
InnerException:
Unfortunately I can not see what COM object this is about.
Does anybody know how I can find that out? Unfortunately I can't read ASM to analyze the disassembly.
There are some steps you could try and since you haven't posted any code I will try to enumerate some of the most common key factors...
First, there is no order when disposing objects. If a close/dispose/finalize action is invoked, object C might be disposed before object A and if some object is still alive it might try to access an already disposed object.
Second, beware of events. It's very common to get errors about accessing a disposed object originated from an event call.
Third, do not dispose objects inside an event scope nor destructors. Create your own method to free your object(s).
Since you don't know which COM object is the culprit, I suggest you look for the ones that you do close, dispose, disconnect, etc...
You might want to read this blog in order to better understand how RCW's work and also to help you with your problem.
Edit:
After reading your comment, I felt I should add two possible causes:
If after removing Microsoft.VisualBasic runtime methods you've solved your problem, then I suspect that inside one, or more, of those methods you have incremented the count of a reference to one, or more, of your COM(s) and did not release properly.
Be sure to ReleaseComObject checking the reference count until it's 0 and then set it to nothing(VB) or null(C#) and let the Garbage Collector do the rest.
The other option is that one of those methods tried to access an already disposed reference to a COM object, resulting in a RCW error, since is no longer callable.
As a final comment, after releasing the COM object always set it to nothing or null, this will release the reference to the variable and you can always check it's availability anywhere in the code.

Handling exception obtained by calling native-to-managed thunk

The scenario is pretty straighforward, I've embedded mono runtime 2.10.8 in my app, and I'm calling the managed methods via pointers obtained by: mono_method_get_unmanaged_thunk:
// obtain pointer
bool (__stdcall*foo) (MonoException**);
foo = mono_method_get_unmanaged_thunk(somemethod);
// call it
MonoException* exc;
foo(&exc);
if(exc)
// handle exception
// nothing else...
What puzzles me, that I'm doing nothing else with the MonoException pointer (documentation I've read doesn't say anything about this). Is it removal handled by the managed runtime? If so, how it can be sure that my native side is not holding a pointer to it?
Edit
I've read through the sources and found out that exceptions are just pointers to objects created with mono_object_new, so they are subject of the garbage collection.
Now, I've also read that if I want to keep some pointer on native side and prevent it from being garbaged I need to obtain GC handle for it. So the (modified) question now is:
If the point of returned pointer to exception object is only to serve as error reporting facility, and such error reporting is made right after the managed call, is it safe to assume it won't get garbaged before I handle it (without using gc handle)?
To quote the page you linked:
Note that this registration is not necessary for LOCAL variables, as they are stored on the stack. It is only necessary for global variables, as they are not a part of the GC's root set.
So that means in your scenario you don't have to allocate a handle.

What do I do when the NSZombie causing a crash is a class?

So I've just started using Instruments to try to debug my app more in depth as I have recently developed a zombie problem. All was going well up to the point of me realising that the category of the zombie is a class of mine called "CreaterPage".
All the examples I've seen of removing zombies had the category listed as something like a string. I therefore have no idea how to go about fixing this problem and removing the zombie
If anybody can offer any tips or answers they would be greatly appreciated,
Thanks,
Matt
A zombie just means that you're trying to send messages to an object that has been deallocated. The class of the zombie object doesn't really matter (except in that it might help you pinpoint the root of the problem).
Instruments should give you some information about the zombie object, where it was allocated etc. It's up to you to figure why your code was trying to message a dead object. Often this will be because you forgot to retain an object, released something you didn't have ownership of or kept on using something after you released it.

Objective-C - Calling Methods in objects.

I'm new to Objective-C, and I seem to be struggling with accessing a method of an object I created. I'm checking out the documentation, but I'm not entirely sure that this is a job for a delegate.
For example I have an object (1) that creates another object (2). I can access a method of the object (2) after I create it, but I can't access it from a method of object (1). I get a error that the object was not defined in this scope.
If anyone can help I greatly appreciate it. I just need a nudge in the right direction so that I can at least get a grasp on how to think about the interaction between the objects.
Turns out I did not define the object in #interface. This caused my methods to not have access to it. So for anyone with a similar issue, make sure to define your i-vars in the interface and not init :)

more detailed information about the exception in xcode

So I am trying to troubleshoot why adding an item to my dictionary causes an exception.
It turns out that I used a NSDictionary instead of NSMutableDictionary.
However the exception I saw... setobject format exception was no help at all.
Where do you look in xCode to get detailed exception information? Or is this all that is given?
It's unfortunate that the emitted stacktrace contains the memory address of the method calls on the stack rather than their names.
I recommend using the debugger and setting a breakpoint at objc_exception_throw. The debugger can tell exactly where the exception was made and what the arguments were.
markjnet provides a nice writeup on exception debugging here.