tags:

views:

124

answers:

1

I have a silverlight application with a service reference back to a Silverlight-Enabled WCF service. When I try to "new up" the WCF objects I get an exception about not having a constructor when I do the following.

Activator.CreateInstance(type, true);

However; this works:

Activator.CreateInstance(type);

Any idea why?

+2  A: 

If your code does not have the appropriate ReflectionPermission bit (presumably ReflectionPermissionFlags.RestrictedMemberAccess) then the underlying reflection search for non-public members will bomb out.

RestrictedMemberAccess is a very powerful permission and likely isn't granted to any code running in a browser, with the possible exception of an assembly reflecting over itself and/or anything granted by InternalsVisibleToAttribute. Accessing private members of the Silverlight runtime libraries, for example, is prohibited by default policy.

Jeffrey Hantin