Welcome to MSDN Blogs Sign in | Join | Help

Strong names for controls in the browser

If you have a control hosted in the browser and you try to strong name it, you may find that it stops working.  Looking at the IEHostLog (http://blogs.msdn.com/andrewdownum/archive/2006/02/10/Using_DebugIEHost.aspx) you might see something like this:

Microsoft.IE.SecureFactory: System.Security.SecurityException: That assembly does not allow partially trusted callers.
   at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed)
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
   at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateComInstanceFrom(String assemblyName, String typeName, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
   at System.AppDomain.CreateComInstanceFrom(String assemblyFile, String typeName, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
   at System.AppDomain.CreateComInstanceFrom(String assemblyFile, String typeName, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
   at Microsoft.IE.SecureFactory.CreateInstanceWithSecurity(Int32 dwFlag, Int32 dwZone, String pURL, String uniqueIdString, String link, String licenses)
The action that failed was:
LinkDemand

As the error message implies, you need to add the AllowPartiallyTrustedCallers attribute to your assembly. This happens if the AppDomain hosting the control is partially trusted.

See http://support.microsoft.com/?kbid=839300 for more discussion.

Published Friday, February 10, 2006 4:37 PM by AndrewDownum
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Hosting Controls in Internet Explorer

Saturday, February 11, 2006 4:08 AM by Kirk Allen Evans' Blog
I recently tried to do a simple demo of hosting a control in IE to show how the CLR will behave when...

# re: Strong names for controls in the browser

Tuesday, February 14, 2006 9:28 AM by Frank Hileman
We stopped recommending .net controls in the browser because:

- compressing managed dlls in cab files is not supported

- the HttpWebRequest class, needed to download data from the server, is extremely slow when running in a control in IE, as opposed to a control in a winforms app.

Have either of these problems ever been addressed?

Cool .net control example:
http://weblogs.asp.net/frank_hileman/archive/2004/07/23/192509.aspx

# re: Strong names for controls in the browser

Tuesday, February 14, 2006 6:17 PM by AndrewDownum
You are correct that compressing managed dlls into cab files is not supported.  Generally you can get the benefit of compression by enabling HTTP response compression on the server (see http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/d52ff289-94d3-4085-bc4e-24eb4f312e0e.mspx for IIS)

I have not seen that HttpWebRequest is slower for controls hosted in IE as opposed to Windows Forms apps.  (I just ran a sample app that did this and saw practically identical download times for HttpWebRequest and WebClient regardless of whether they were hosted in a WinForms app or in the browser).

I'll post soon on how you can use a loader stub to optimize the downloading of your control.

# re: Strong names for controls in the browser

Monday, February 20, 2006 8:49 AM by Frank Hileman
I have a reproducible test for the web request problem I can send. I did not try with .net 2.0 yet, maybe the problem is fixed now.

# re: Strong names for controls in the browser

Saturday, March 11, 2006 5:17 PM by AndrewDownum
If you want to send me this repro, I would be happy to have a look at it (Andrew D is my address at microsoft)

# Project Coelacanth

Wednesday, March 22, 2006 2:58 PM by Eric Lee - A Humble Blog
I followed the walk through, more or less  and created a .NET Winforms control that is hosted in...

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker