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?
If your code does not have the appropriate
ReflectionPermissionbit (presumablyReflectionPermissionFlags.RestrictedMemberAccess) then the underlying reflection search for non-public members will bomb out.RestrictedMemberAccessis 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 byInternalsVisibleToAttribute. Accessing private members of the Silverlight runtime libraries, for example, is prohibited by default policy.