Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

assembly reference not working in C# script

Status
Not open for further replies.

gib99

Programmer
Mar 23, 2012
51
CA
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>
...

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 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.
 
The S.W.Forms dll is installed in the GAC 'cos that's where it needs to sit to resolve all its dependencies. You may be able to find out what its dependencies are by changing the registry key as mentioned, but what you are trying to do is bypass the GAC, which isn't possible.
What is it you are trying to achieve with this code? Assuming you can get it to work, what would happen is somebody would hit the web page, the server would then show a MessageBox, which would block the request until somebody logged into the server and pressed ok. The end user would not see the messagebox, all they'd see is a blank screen, until they got bored and cancelled the request.
If you are trying to display a messagebox on the client machine, you need to check out javascript, if you're trying to debug your website and see what gets called when, you should investigate the Trace functionality.

hth

Ben

----------------------------------------------
Ben O'Hara
David W. Fenton said:
We could be confused in exactly the same way, but confusion might be like Nulls, and not comparable.
 
Thanks Ben,

I've been advised to use VS 2012 Exp. Web to develop my web app. I'm told this is the way to go.
 
Sorry if i am

Sorry if I am stating the obvious here. You do know you are using the windows forms dll in a web page? I am sure that won’t work? Did you mean to uses the System.Web.UI.WebControls.Label. That is the label for an ASP.NET webpage.

The webserver will not have the permissions to run that dll...

Maybe I misunderstand the problem?

Age is a consequence of experience
 
I tried using System.Windows.Forms.MessageBox.Show() just for a test (too see if I could do it). I'm told this will only execute on the server side and it won't be seen on the client side, but in my case I'm running it on localhost.

If you're asking about Label1, that refers to this (further down the page):

<asp:Label ID="Label1" runat="server"></asp:Label>
 
Perhaps we should approach this from a different angle... I know I am digressing from the original question but would you mind if I asked what you are trying to do. This may help point you in the right direction?

What you are trying to do is not something I have ever tried to do but I assume .Net will not allow this type of shenanigans. Hence maybe why you get this
[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.

You say you are running local host but there is still a client server system to show you the web pages. It just so happens that they are on the same machine.

You didn’t say what happened when you tried to use System.Windows.Forms.messagebox? I assume nothing or an error. This is because the browser cannot be allowed to do these things. The web would be in turmoil as the browser would need access to some very low level windows API's. This is also why Microsoft use different dlls for webpage controls to Windows forms controls that use low level API's and not HTML.



Age is a consequence of experience
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top