开发者

Creating WCF objects using Activator.CreateInstance

开发者 https://www.devze.com 2022-12-16 19:10 出处:网络
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 d

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消