Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2004

Tip: Looking for answers? Try searching our database.

.NET Framework 1.1 sp1 breaks our application!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
paulio - 10 Sep 2004 11:25 GMT
We're having problems with events from a Windows Forms Control embedded in a
web page not firing in javascript after installing sp1 of the .net 1.1
framework.  I have de-installed SP1 and can confirm that the problem is
solved by reverting to the original 1.1 framework.

For some background on sinking events in IE script, read the following:
http://support.microsoft.com/default.aspx?scid=kb;en-us;316516

To demonstrate the problem, I have created a simple control with an event.  
The assembly is strong named, and a code group/permission set for the strong
named assembly has been created with Security --> calls to unmamanged
assemblies enabled (needed to be able to fire events in JScript).  The
SecurityPermissionFlag.UnmanagedCode is asserted before firing the event,
otherwise the standard permissions for the relevent zone are used which
disallow calls to unmanagaged code.  Also note that the
AllowPartiallyTrustedCallers attribute has been set.  In the original .NET
1.1 framework, clicking the button on the web page fires the event in the
control - the message is alerted in the JScript.  In the SP1 framework, the
"EVENT NOT FOUND" message appears.  After clicking outside the control, then
clicking on the control, the event will then subsequently fire correctly.  We
attempted to simulate by calling the click() method on various objects but to
no avail.

Changing the permission set for the relevent zone to one that allows
unamanaged code solves the problem, but of course it leaves a gaping security
hole and is therefore not a viable solution.

Any suggestions for a solution or workaround would be most gratefully
received.

C# code from the control is below:

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;

[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("mykeyfile.snk")]
[assembly: AllowPartiallyTrustedCallers()]
[assembly: AssemblyVersion("1.0.*")]

namespace MyControl
{
   [GuidAttribute("2E3F0470-9499-4eaf-B0F2-6F6CDF9BF1DC")]
   [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
   public interface ICOMEvents
   {
       [DispId(1)]
       [SecurityPermissionAttribute(SecurityAction.Assert,
UnmanagedCode=true)]
       void onSendMessage(string sSendMessage);
   }

   public interface IGridCOMIncoming
   {
       void setPermissions();
       void checkEvent();
   }

    /// <summary>
    /// Summary description for UserControl1.
    /// </summary>

   public delegate void SendMessage(string theMessage);

   [ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(ICOMEvents))]
   [SecurityPermissionAttribute(SecurityAction.Assert, UnmanagedCode=true)]
    public class SimpleControl :
System.Windows.Forms.UserControl,IGridCOMIncoming
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;
       private System.Windows.Forms.Button button1;
       private SecurityPermission sp;

       private event SendMessage m_sendMessage;

       public event SendMessage onSendMessage
       {
           add
           {
               sp = new SecurityPermission(
SecurityPermissionFlag.UnmanagedCode );
               sp.Assert();
               m_sendMessage += value;
           }
           remove
           {
               sp = new SecurityPermission(
SecurityPermissionFlag.UnmanagedCode );
               sp.Assert();
               m_sendMessage -= value;
           }
       }

       public void setPermissions()
       {
           sp = new SecurityPermission(
SecurityPermissionFlag.UnmanagedCode );
           sp.Assert();

       }

       public void checkEvent()
       {
           sp = new SecurityPermission(
SecurityPermissionFlag.UnmanagedCode );
           sp.Assert();

           if ( m_sendMessage == null )
           {
               MessageBox.Show("EVENT NOT FOUND");
           }
           else
           {
               m_sendMessage("Event fired OK");
           }

       }

        public SimpleControl()
        {
           sp = new SecurityPermission(
SecurityPermissionFlag.UnmanagedCode );
           sp.Assert();
         
           
           // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();
           // TODO: Add any initialization after the InitComponent call
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if( components != null )
                    components.Dispose();
            }
            base.Dispose( disposing );
        }

        #region Component Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
           this.button1 = new System.Windows.Forms.Button();
           this.SuspendLayout();
           //
           // button1
           //
           this.button1.Location = new System.Drawing.Point(40, 64);
           this.button1.Name = "button1";
           this.button1.TabIndex = 0;
           this.button1.Text = "Click Me";
           this.button1.Click += new System.EventHandler(this.button1_Click);
           //
           // SimpleControl
           //
           this.Controls.Add(this.button1);
           this.Name = "SimpleControl";
           this.ResumeLayout(false);

       }
        #endregion

       private void button1_Click(object sender, System.EventArgs e)
       {
           checkEvent();
       }
    }
}

HTML & JScript web page below:

<head>
<title></title>
</head>
<body>
<input type='button' onclick='SimpleControl.checkEvent();' value='Check
Event' ID="Button1" NAME="Button1">
<object id='SimpleControl'
classid='MyControl.SimpleControl.dll#MyControl.SimpleControl' height=100
width=100 VIEWASTEXT>
</object>
<script language='JScript'>
    function SimpleControl::onSendMessage( sMessage )
    {
        alert(sMessage);
    }
</script>
</body>
</html
lwickland - 24 Sep 2004 19:45 GMT
We started an MSDN incident about this issue.  Eventually, the support rep
admitted that they have a problem.  She said they'd probably work on a hot
fix.  That was about a week ago.  Today she got back to us and said that we
shouldn't expect a fix any time soon.

The MS workaround for the problem is to add a site code group instead of
using a strong name code group.

> We're having problems with events from a Windows Forms Control embedded in a
> web page not firing in javascript after installing sp1 of the .net 1.1
[quoted text clipped - 206 lines]
> </body>
> </html
John Smith - 29 Sep 2004 11:48 GMT
sir lwickland,

how did you report the problem..i've got another problem..how can i report
it to microsoft to get a fix?

> We started an MSDN incident about this issue.  Eventually, the support rep
> admitted that they have a problem.  She said they'd probably work on a hot
[quoted text clipped - 213 lines]
> > </body>
> > </html

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.