none
assembly reference not working in C# script RRS feed

  • Question

  • Hello,

    I'm trying to bring some assemblies into my bin folder for my website. I've got some C# script on the page that references and uses the assemblies. It looks like this:

    [code]
    <%@ Page Language="C#" %>

    <%@ Import Namespace="System.Windows.Forms" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="MySql.Data.MySqlClient" %>

    <html>

    <script runat="server">

    void Page_Load(object sender, System.EventArgs e)
    {
     MySql.Data.MySqlClient.MySqlConnection con = new MySql.Data.MySqlClient.MySqlConnection();
     System.Windows.Forms.MessageBox.Show("greetings");
     Label1.Text = "hello world";
    }

    </script>
    ...
    [/code]

    I can create a new MySqlConnection object just fine but it's the System.Windows.Forms object (or namespace?) that's giving me trouble.

    I found the dll in C:\Windows\Microsoft.NET\assembly\GAC_MSIL and copied it over to my wwwroot/bin/ folder.

    The error I get when I try to load the page is:

    [error]
    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

    Parser Error Message: Could not load file or assembly 'System.Windows.Forms' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

    Source Error:


    Line 57:                 <add assembly="System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    Line 58:                 <add assembly="System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    Line 59:                 <add assembly="*"/>
    Line 60:                 <add assembly="System.Runtime.Serialization, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"/>
    Line 61:                 <add assembly="System.IdentityModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"/>
     
    Source File: C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Config\web.config    Line: 59

    Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Windows.Forms' could not be loaded.

    WRN: Assembly binding logging is turned OFF.
    To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
    Note: There is some performance penalty associated with assembly bind failure logging.
    To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

    Version Information: Microsoft .NET Framework Version:2.0.50727.5456; ASP.NET Version:2.0.50727.5456
    [/error]

    So it says that the assembly I copied over was built more recently than whatever's already loaded (that's how I'm interpreting it at least). It tells me where the exact location of the problem is (line 59 in web.config) and that's where you see the <add assembly="*"/> but it doesn't tell me what to replace it with. It also tells me how to turn assembly binding logging off (whatever assembly binding means), but I don't seem to have the registry path it gives me on my computer.

    Thursday, November 1, 2012 2:48 AM

Answers

  • Why are you doing this in Notepad? Your best bet would be to use Visual Studio's Web Developer Express. It's free and there's really no reason not to use it.

    http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-for-web

    *The reason I suggest just using the IDE is that it handles managing references far easier than trying to do it manually. 

    **Also, why exactly are you referencing a Windows.Forms assembly in an ASP.NET application? Whatever you're trying to accomplish, you're definitely doing it wrong. Can you elaborate?


    Friday, November 2, 2012 4:16 AM

All replies