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 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.
精彩评论