How can I reliably test (in IL or with some methods provided by the .NET) whether a given native int is a valid object reference (O)? The pointer may have been retrieved from some debugger, and it might not be valid (or collected after it was returned). Simply returning it as an object throws uncatchable ExecutionEngineException on invalid addresses. I tried castclass to object, which throws NullPointerException in case of some invalid references, but it also throws bad AccessViolationException with some addresses. Is there a better way to do it, without throwing any uncatchable exceptions or corrupting memory?
Test if a given object reference is valid
278 Views Asked by IS4 At
1
There are 1 best solutions below
Related Questions in .NET
- Does compiler optimize operation on const variable and literal const number?
- What is the point of definnig Asp.net Intrinsic Objects In different places and what is the different betwen them?
- Deleting Orphans with Fluent NHibernate
- IOrderedEnumerable to vb.net IOrderedEnumerable Conversion
- What is this namespace ITypeOfObjectsBoundToListBox ? Couldn't find it
- .net rest service with JSON string and consumed with java client
- What is best way to check if any of the property of object is null or empty?
- Telerik's WPF RadColorPicker NoColorText property not working
- Possible consequences of duplicate ProgId for different classes
- How are multiple requests to Task.Run handled from a resource management standpoint?
- Optimizing C++ call from C#
- Make a per-web-application object available to Web API and SignalR controllers
- System.ComponentModel.DataAnnotations.Schema namespace conflict
- LINQ Except/Distinct based on few columns only, to not add duplicates
- Not displaying content by its URL string - absolute urls
Related Questions in CLR
- Windows Error Reporting doesn't generate mini dump for a .NET 4 application sometimes
- Where exactly is .NET Runtime (CLR), JIT Compiler located?
- SQL CLR Exception when trying to convert PDF
- Obtain non-explicit field offset
- Test if a given object reference is valid
- msclr is not being used
- Mixed mode assembly is built against version xxxx
- “CLR detected an Invalid Program” when compiling a constructor for List<T>
- Set only second argument type in generic method
- Where would the code produced by the JIT would reside
- .NET Framework compatibility issue
- Using the new source provided by microsoft would it be possible to create a variant of the CLR?
- Deadlocked in w3wp for a WCF website. Unable to find source of Issue
- At what point in time does an instance of a C# class with a generic Type parameter lose awareness of its "generic"-ness?
- Type '<Module>' from assembly ... contains more methods than the current implementation allows
Related Questions in CIL
- Test if a given object reference is valid
- MSIL store a value of structure to return
- Changing internal class to public (CIL, Mono.Cecil)
- What is to be considered the "natural alignment" for OpCodes.Ldobj?
- Some questions about the usage of MethodImpl Attribute
- Probably redundantly opcode when explicit base type cast
- C# Getting PropertyInfo within setter using PropertyBuilder
- Properly emit property
- In the IL code produced, there are some lines missing. What task does the in between lines perform?
- Why is there no .NET RuntimePropertyHandle and PropertyInfo.GetPropertyFromHandle?
- How to diagnose "Type load failed" from PEVerify
- Are the placeholders of Generics compiled as an actual data type?
- msil ".maxstack 1" pushes more than 1 value
- CIL - How do I use a public static literal field?
- Why does tail call optimization need an op code?
Related Questions in IL
- Invalid IL code when using callvirt with Mono.Cecil - C#
- Strange IL code emitted by some compiler
- Is C# namespace compiled into IL files to be "complete" names?
- Test if a given object reference is valid
- MSIL store a value of structure to return
- The fastest way to detect if a double is finite?
- IL optimization for JIT compilers
- msil ".maxstack 1" pushes more than 1 value
- How can I use Mono.Cecil to call a generic method
- TypedReference to ref T throws BadImageFormatException
- Get AST from .Net assembly without source code (IL code)
- IL - What am I doing wrong?
- One loop or two? (how to read the IL)
- How to call method on a pointer to a C++ object using OpCodes.Calli
- Is it possible to emit and save IL code from linq expressions?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
In a comment on the question, you said the pointer comes from the profiler API, so I'm going to assume that your debugger is implemented using the profiler API.
There is no reliable way to check if a pointer to an object (ObjectID) is valid. Even if it is pointing to what appears to be a valid object, it might not be the same object. Instead, the normal approach is to track the object through the GC callbacks and update/discard your references as appropriate.
If you store the pointer somewhere that isn't updated and the GC is allowed to run, then you should automatically assume the pointer is invalid.