Friday, March 6, 2009

Implemented IObjectSafety in .NET but object still unsafe for scripting : RESOLVED

Hello Friends,


The intended audience of this article are not those developers who are looking how to implement IObjectSafety in .NET but those who have already done that and still getting “Object unsafe for scripting” popup in Internet Explorer.

(they can find the implementation on msdn blog here:


I saw a lot of confusion related to implementation of IObjectSafety in .NET and thought to share my experience about the same.


So the simple cause to this big problem is our knowledge about COM & Guids J


Basically when we get the interface from any knowledgebase we include it to out project and like a good programer we generate a new Guid and replace the one which is given in orignal documenttaion.


That’s it; we have messed our code and we are not even aware of it.


So the crux is that for any IObjectSafety implementation the guid of out interface should always be

{"CB5BDC81-93C1-11cf-8F20-00805F2CD064"}. Period.


By the time you end up reading the above line your problem is hopefully solved and your component is now safe for scripting.


So this is how your interface will eventually look like:


using System;

using System.Runtime.InteropServices;


namespace Atreya.SampleCode


    /// <summary>

    /// Methods in this interface needs to be implemented to mark any object safe for scripting in IE

    /// </summary>




    internal interface IObjectSafety



        int GetInterfaceSafetyOptions(ref Guid riid, out int pdwSupportedOptions, out int pdwEnabledOptions);



        int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions);





  Anugrah Atreya 


No comments: