Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / August 2003

Tip: Looking for answers? Try searching our database.

Access Denied Exception thrown from Activator.CreateInstance(Type)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Howard Swope - 26 Aug 2003 19:04 GMT
I am trying to get a reference to an ATL COM singleton object running on a
Windows CE 4.1 (w/DCOM) device from a C# client. I have no problem accessing
it from a Win32 client. The code that I am using to instanciate the object
is:

Type t = Type.GetTypeFromCLSID(guid,"machinename",true);

object obj = Activator.CreateInstance(t);

This will acutally launch the exe server on the ce device, but then throws
an exception with a message of Access Denied.

Any thoughts???
Signature

Howard Swope
Software Engineer
Spitz, Inc [http://www.spitzinc.com]

David Stucki [MS] - 26 Aug 2003 23:59 GMT
What type of application is the C# code in?  Is it a Windows Service or
ASP.NET?  It sounds like you may be running into an Access Permissions
problem.

If you create a simple C# console application drop in the code you posted
and run that as the same user does the CreateInstance work?

David Stucki
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Howard Swope - 27 Aug 2003 19:32 GMT
I used PInvoke to call CoInitializeSecurity and turned security off:

int ret = CoInitializeSecurity(IntPtr.Zero, -1, IntPtr.Zero, IntPtr.Zero, 1,
3, IntPtr.Zero, 0, IntPtr.Zero);

This seemed to do the trick.

I now have my object instanciated, but I don't know what to cast it to. I
have tried using tlbimp to import the type information, but that doesn't
work. I also tried to create an interface definition manually to no avail.
This COM component is all custom interfaces, I don't know if this makes a
difference.

I am thinking I may have to write an automation component to talk to this
one and call that from my managed code.

Any thoughts?

> What type of application is the C# code in?  Is it a Windows Service or
> ASP.NET?  It sounds like you may be running into an Access Permissions
[quoted text clipped - 7 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
David Stucki [MS] - 27 Aug 2003 21:14 GMT
If the COM object has an associated Type Library you can use TLBIMP.exe or
Add a project reference to have an interop assembly generated
automatically.  Or you can define an interface manually like this:

//    Here's the IDL:
//    [
//        odl,
//        uuid(C2B41384-A3E6-4E22-9A36-8B78C8D4FCC0),
//        version(1.0),
//        hidden,
//        dual,
//        nonextensible,
//        oleautomation
//    ]
//    interface _Test : IDispatch
//    {
//        [id(0x60030000)]
//        HRESULT GetArray([out, retval] SAFEARRAY(BSTR)* );
//    };

    [   
        ComImport(),
        Guid("C2B41384-A3E6-4E22-9A36-8B78C8D4FCC0"),
        InterfaceTypeAttribute(ComInterfaceType.InterfaceIsDual),
    ]
    interface ITest
    {
        [DispId(0x60030000)]
        [return : MarshalAs(UnmanagedType.SafeArray,
SafeArraySubType=VarEnum.VT_BSTR)]
        Array GetArray();
    }

Once you have a managed definition of the interface you can cast the object
returned from the CreateInstance call to that interface and a
QueryInterface will take place under the covers.

David Stucki
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.