Accessing .net class/assemblies from classic asp

Mar 17, 2010 at 11:38 AM

I was wondering if it is/will be possible to access asp.net classes/assemblies from within classic asp whilst using this compiler; I assume it's possible on some level as we're compiling to the CLR, but I don't know the syntax for it :) Any help would be fantastic.

Coordinator
Mar 17, 2010 at 3:24 PM
Yes, you might access the asp.net classes/assemblies. You might take a look of the StringBuilder example on this page: http://aspclassiccompiler.codeplex.com/wikipage?title=History&referringTitle=Home. There are two syntax changes to make it possible: the first is to use the imports keyword to import the top name space. The second is to use the new keyword to instantiate your class. Once instantiated, you can use the .net object like any other object.
 
You might also use static methods without New. For example: System.Web.HttpContext.Current.Session,,,
 
Li

On Wed, Mar 17, 2010 at 4:38 AM, Malediction <notifications@codeplex.com> wrote:

From: Malediction

I was wondering if it is/will be possible to access asp.net classes/assemblies from within classic asp whilst using this compiler; I assume it's possible on some level as we're compiling to the CLR, but I don't know the syntax for it :) Any help would be fantastic.

Read the full discussion online.

To add a post to this discussion, reply to this email (aspclassiccompiler@discussions.codeplex.com)

To start a new discussion for this project, email aspclassiccompiler@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Mar 17, 2010 at 3:40 PM

Oh awesome, thank you very much! :)

Mar 18, 2010 at 10:12 AM

When using System.Text.RegularExpressions.Regex I'm recieving the following error when I attempt to compile this line:


Dim regEx = New System.Text.RegularExpressions.Regex("^\d{4}\-\d{2}\-\d{2}T.*")

Dlrsoft.VBScript.Parser.Argument is not yet implemented

 

Do I need a newer version of the compiler? :o

Mar 18, 2010 at 1:30 PM

I've written a wrapper class in C# to get around the inability to send constructor parameters for the moment, but now I'm having trouble loading my custom assembly to be accessed from within asp. The binaries are in /bin/ and I've added the neccesary <add assembly="etc etc" /> to web.config (And signed the assembly), I've then also added a runtime assembly codebase locator in web.config:

<dependentAssembly>
 <assemblyIdentity name="WrapperObjects" publicKeyToken="etc etc" />
 <codeBase version="1.0.0.0" href="bin/WrapperObjects.dll" />
</dependentAssembly>
 
But then upon trying to open the page I get the following error:

Server Error in '/' Application.

Import: can't find name in globals -- WrapperObjects

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Import: can't find name in globals -- WrapperObjects

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

 
[ArgumentException: Import: can't find name in globals -- WrapperObjects]
   Dlrsoft.Asp.AspHandler.ProcessRequest(HttpContext context) in F:\projects\dotnet35\VBParser80\asp\AspHandler.cs:107
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75



Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927

I'm unsure if this means it's an error on my part, or the compiler's. Any help would be great :) 

Mar 18, 2010 at 5:25 PM

Also, elsewhere in the code I'm getting this error, and I can't pinpoint where it's coming from (either the app code or the compiler). If you need anymore details/dissaemblies please let me know! :)

Server Error in '/' Application.

Input string was not in a correct format.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[FormatException: Input string was not in a correct format.]
   Dlrsoft.Asp.AspHandler.ProcessRequest(HttpContext context) in F:\projects\dotnet35\VBParser80\asp\AspHandler.cs:107
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75



Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927

Coordinator
Mar 19, 2010 at 6:03 AM
Malediction,
You asked 3 questions. Let me answer them one by one:
The first question is regarding constructors with arguments. As you I have found, I did not implement it, but it can be added fair easily.
The second question is regarding asp classic compiler not finding your custom class. The reason is that you actually have to tell it a list of assemblies to search for classes. This is again fairly easy and I will provide a method to load external assemblies.
The third question is regarding the exception. If you see the exception at line 181, the code actually compiled. The exception is thrown by the compiled code, and unfortunately this is quite difficult to debug at this time. The design of the next major release will allow developers to exam the local variables but I will probably come up with a minor release that will simply emit the line number that the exception occurred.
I will try to come out a minor release in the next few days to address this issues. Thank you for your feedback.
Li

From: [email removed]
Sent: Thursday, March 18, 2010 10:25 AM
To: [email removed]
Subject: Re: Accessing .net class/assemblies from classic asp [aspclassiccompiler:205235]

From: Malediction

Also, elsewhere in the code I'm getting this error, and I can't pinpoint where it's coming from (either the app code or the compiler). If you need anymore details/dissaemblies please let me know! :)

Server Error in '/' Application.

Input string was not in a correct format.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[FormatException: Input string was not in a correct format.]
   Dlrsoft.Asp.AspHandler.ProcessRequest(HttpContext context) in F:\projects\dotnet35\VBParser80\asp\AspHandler.cs:107
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75



Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927

Mar 19, 2010 at 10:17 AM

Glad I could help :)

I think I've found a functional issue with string comparison; if I have a statement such as:

if Request("Login") > "" then
       doSomething
end if

It will compile, but then throws a runtime error("Input string was not in a correct format" - the same one I found above), it seems to be related to the > and < operators used on strings (<> works fine though since it's just a NOT).


Keep up the great work, this is a very cool product! :)

Coordinator
Mar 19, 2010 at 3:06 PM
Your information is very helpful. Fortunately, My comparison binder does not support string comparison; It is trying to convert the string to number and hence the error. This is quite easy to fix and I will fix it in the next minor release.
 
Li

On Fri, Mar 19, 2010 at 3:17 AM, Malediction <notifications@codeplex.com> wrote:

From: Malediction

Glad I could help :)

I think I've found a functional issue with string comparison; if I have a statement such as:

if Request("Login") > "" then
       doSomething
end if

It will compile, but then throws a runtime error("Input string was not in a correct format" - the same one I found above), it seems to be related to the > and < operators used on strings (<> works fine though since it's just a NOT).


Keep up the great work, this is a very cool product! :)

Read the full discussion online.

To add a post to this discussion, reply to this email (aspclassiccompiler@discussions.codeplex.com)

To start a new discussion for this project, email aspclassiccompiler@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Apr 1, 2010 at 11:07 AM

Hey,

Thanks for posting a new build with fixes! Is it possible to load a custom .net assembly now? or is that for a future build? :)

Keep up the good work! :D

Apr 1, 2010 at 12:12 PM
Edited Apr 1, 2010 at 12:57 PM

I found your blog post about loading custom assemblies, very nice :) Although I am encountering some new problems now:

System.Object doesn't support the NOT unary operator so statements such as "if not someBoolean" error at runtime.

Edit: Removed the 2nd error, found the problem. :-)

Coordinator
Apr 1, 2010 at 2:53 PM
Thank you for reporting. There is probably a problem with my unary operation binder and I may need some conversion there. I will take a look.

On Thu, Apr 1, 2010 at 5:12 AM, Malediction <notifications@codeplex.com> wrote:

From: Malediction

I found your blog post about loading custom assemblies, very nice :) Although I am encountering some new problems now:

System.Object doesn't support the NOT unary operator so statements such as "if not someBoolean" error at runtime.

I'm also encountering a runtime exception on a seemingly normal if statement:

      if SessionsExceeded or blnLicenseExceeded or blnScheduledLogoutDue then

The 3 variables are all valid (They can be outputted with Response.write fine), but inside an if statement they cause a runtime exception. Here's the ASP.net error below: 

Server Error in '/' Application.


Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

 
[NullReferenceException: Object reference not set to an instance of an object.]
   Dlrsoft.Asp.AspHandler.ProcessRequest(HttpContext context) in F:\projects\dotnet35\VBParser80\asp\AspHandler.cs:110
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75



Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927

 

Read the full discussion online.

To add a post to this discussion, reply to this email (aspclassiccompiler@discussions.codeplex.com)

To start a new discussion for this project, email aspclassiccompiler@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Coordinator
Apr 5, 2010 at 12:56 AM

Please download 0.6.2 and give it a try. Also, see http://weblogs.asp.net/lichen/archive/2010/04/05/how-to-enable-tracing-in-asp-classic-compiler.aspx on how to see the file name and line number when you get runtime exception from VBScript.net compiled code.

May 20, 2010 at 3:34 AM

Is there a way to import the System.Collections namespace into the VBScript.net parser as some of the objects that I add to the Script scope inherit from System.Collections.SortedList and withing the VBScript I have statement like this:

Set variable = MyObject.Item("0")

This piece of code gives me error at runtime stating that it Cannot bind invoke MyObject.Item.