C# assembly not invoked if accessing System.Web !!!

  • Thread starter Thread starter mqsash
  • Start date Start date
M

mqsash

Hi

I have written a simple C# Class Assembly.
Normally it works fine, but when I write some code (in the ctor) which
tries to reference the System.Web, then the CTOR does not get invoked
at all !!

The code is as shown below.
-------------------------------------------------------------------
1. using System;
2. using System.Web;
3. using System.Windows.Forms;
4.
5. namespace testAssembly
6. {
7. public class Class1
8. {
9. public Class1()
10. {
11. string URL ="Blank";
12. MessageBox.Show("ctor");
13. URL = "test";
14. MessageBox.Show(URL);
15. }
16. }
17. }
-------------------------------------------------------------------
The assembly is embedded into the following html

<html> <body >
<OBJECT ID="myAssembly"
classid="testAssembly.dll#testAssembly.Class1"></OBJECT>
This is a testAssembly
</body> </html>

When I open this html, everything works as expected.
1. The assembly's constructor is invoked,
2. I get a MessageBox with the "ctor" message. (Line #12)
3. I then get the next MessageBox with the "test" message (Line #14)


NOW if I try to access something under System.Web ( Line #13 ).......

13. URL = System.Web.HttpContext.Current.Request.RawUrl;;

The expected behaviour is that after the "ctor" message, I should get
the current url in a MessageBox (Line #14).
BUT I do not even get the "ctor" message !! Seems like even the
constructor is not invoked !

I have added reference to the System.Web.dll so that should not be a
problem.

Can anybody shed some light over here ? What might be causing this ?

TIA
mqs
 
My guess would be permissions. If it's embedded in the page, then IE runs
it with (normally) low permissions.

-mike
MVP
 
Hi Michael,
I'm still a rookie in the dotnet world. Could you please give me some
more details regarding the permissions? Do I have to sign the assembly
or regasm it? or something similar?

Incidently I get the same behaviour if I try to use the "Process",
ie. my assembly's CTOR is not invoked if I call
System.Diagnostics.Process.GetCurrentProcess();

Same problem?

thanks
mqs
 
That would sound like it. Where are you downloading from? Localhost? At
any rate, to increase permissions for a specific assembly, goto
"Administration Tools" and run one of the .NET Wizards.
-mike
MVP
 
Mi Michael,

Thanks, for the tip. I changed the permissions and it is now working.
Just one more query....
For performance reasons, I want to deploy the assembly as a cab file.
I went according to the steps mentioned in
http://msdn.microsoft.com/library/d...ml/mwconredirectingtomobilewebapplication.asp

1. Created the cab file called it testAssembly.cab (using cabarc.exe)
2. Created a config file called testAssembly.config
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="testAssembly"/>
<codeBase version="1.0.0.0"
href="http://mypc/testAssembly.cab"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

3. In the HTML I specified this config file
<link rel="Configuration" href="http://mypc/testAssembly.config"/>

4. The object tag remains unchanged, ie
<OBJECT ID="myAssembly"
classid="testAssembly.dll#testAssembly.Class1"></OBJECT>

But this did not work. Seems like the Browser could not understand it,
because the Fuslogvw.exe did not register any failure.
BTW - the assembly is strong named.

Any idea what I did wrong ?

thanks
mqs
 
Back
Top