Re: Cbool problem
From: Joe Fallon (jfallon1_at_nospamtwcny.rr.com)
Date: 10/12/04
- Next message: Ken Tucker [MVP]: "Re: Indexes vba to .net"
- Previous message: Larry Bird: "Re: Reading a Registry Key (Solution)"
- In reply to: Imran Koradia: "Re: Cbool problem"
- Next in thread: scorpion53061: "Re: Cbool problem"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 12 Oct 2004 19:55:20 -0400
Imran,
I had already added Read permission to Network Service account on the temp
folder.
It turns out that message is returned every time there is a syntax error in
the code string being Evaluated.
Once I input a good sample string it ran correctly.
The other major piece was that in the Eval method there are Imports
statements in the code.
Any assembly that is imported needs to be added to the param collection.
Once I married them up and got a good sample it worked!
cp.ReferencedAssemblies.Add("system.dll")
sb.Append("Imports System" & vbCrLf)
Thanks for the help.
I used the code from this article: (thanks Peter!)
http://www.eggheadcafe.com/articles/20030908.asp
-- Joe Fallon "Imran Koradia" <nojunk@microsoft.com> wrote in message news:eSfbrrKsEHA.2940@tk2msftngp13.phx.gbl... > Joe, > > Unfortunately I'm not familiar with ASP.NET. However, looking at the > message, I believe the problem is that the runtime is creating a temporary > assembly in the Temp folder and probably the ASP.NET account does not have > permissions to write to the directory. Thats just a guess..but yes, it does > look like a permissions issue to me. > > > Imran. > > "Joe Fallon" <jfallon1@nospamtwcny.rr.com> wrote in message > news:OBLQB0JsEHA.1036@TK2MSFTNGP10.phx.gbl... > > OK. > > I am now trying to use dynamic code execution in an ASP.Net application. > > > > The code works fine a WinForms app. > > > > > > This is the error I am getting when trying to load the dynamic assembly: > > Dim a As System.Reflection.Assembly = cr.CompiledAssembly > > > > > > > > > > Any ideas what I need to do to get the web server to load the assembly? > > > > === Pre-bind state information === > > LOG: Where-ref bind. Location = C:\WINDOWS\TEMP\umkevkky.dll > > LOG: Initial PrivatePath = bin > > Calling assembly : (Unknown). > > === > > > > LOG: Policy not being applied to reference at this time (private, custom, > > partial, or location-based assembly bind). > > LOG: Attempting download of new URL file:///C:/WINDOWS/TEMP/umkevkky.dll. > > > > -- > > Joe Fallon > > > > > > > > "Imran Koradia" <nospam@microsoft.com> wrote in message > > news:#KWMbWJsEHA.2684@TK2MSFTNGP12.phx.gbl... > >> What you are looking for is dynamic code execution. Here's an example: > >> > >> Private Sub DynamicExecution() > >> Dim strCode As String = " Imports System.Windows.Forms " _ > >> & ControlChars.CrLf & "NameSpace myNameSpace" _ > >> & ControlChars.CrLf & "Class class1" & _ > >> ControlChars.CrLf & "public sub DynamicCode()" _ > >> & ControlChars.CrLf & _ > >> "messagebox.show(CStr(CBool(11=10 OrElse 11=11)))" _ > >> & ControlChars.CrLf & "end sub" & ControlChars.CrLf _ > >> & "end class" & ControlChars.CrLf & "end NameSpace" > >> > >> Dim VBProvider As New VBCodeProvider > >> Dim Compiler As ICodeCompiler = _ > >> VBProvider.CreateCompiler > >> Dim Parameters As New CompilerParameters > >> With Parameters.ReferencedAssemblies > >> .Add("System.dll") > >> .Add("System.Windows.Forms.dll") > >> End With > >> Dim Results As CompilerResults > >> Results = Compiler.CompileAssemblyFromSource( _ > >> Parameters, strCode) > >> Dim oclass1 As Object = _ > >> Results.CompiledAssembly.CreateInstance( _ > >> "myNameSpace.class1", True) > >> oclass1.GetType.InvokeMember( _ > >> "DynamicCode", BindingFlags.InvokeMethod, _ > >> Nothing, oclass1, New Object() {}) > >> End Sub > >> > >> here's a more detailed example: > >> http://www.west-wind.com/presentations/dynamicCode/DynamicCode.htm > >> > >> hope that helps.. > >> Imran. > >> > >> "Joe Fallon" <jfallon1@nospamtwcny.rr.com> wrote in message > >> news:uEqL94IsEHA.868@TK2MSFTNGP12.phx.gbl... > >> > I built up a string in code and now I wish to evaluate it using Cbool > > but > >> I > >> > get a runtime error. > >> > > >> > This is my expression: > >> > ?CBool("11=10 OrElse 11=11") > >> > Run-time exception thrown : System.InvalidCastException - Cast from > > string > >> > "11=10 OrElse 11=11" to type 'Boolean' is not valid. > >> > > >> > If I remove the quotes manually from the string the expression works as > > I > >> > had hoped: > >> > ?CBool(11=10 OrElse 11=11) > >> > True > >> > > >> > The question is: how do you build up the string programatically and > >> > then > >> > evaluate it using Cbool? > >> > > >> > -- > >> > Joe Fallon > >> > > >> > > >> > > >> > >> > > > > > >
- Next message: Ken Tucker [MVP]: "Re: Indexes vba to .net"
- Previous message: Larry Bird: "Re: Reading a Registry Key (Solution)"
- In reply to: Imran Koradia: "Re: Cbool problem"
- Next in thread: scorpion53061: "Re: Cbool problem"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|