✅ problems with executing code from variable
earlier I asked a question in this server how to execute code from variable. Now i have another problem: usual code is executing good, but my code doesn't want to, it execute with error
17 Replies
code:
it's the same error as if you forgot a using in normal C# code
you mean i should add
using DllImportAttribute
?'i don't use this scripting stuff but you have a line with what look like usings
i'll try
i added this, and nothing was changed
still this error
options = options.WithImports("System", "System.Console");
here?var result = await compiledScript.RunAsync();
here's error
or
what do you meani mean those look like usings, so if it was me i would try adding the namespace to that list on the line i shared
that's not a namespace
that's just the type name
DllImportAttribute Class (System.Runtime.InteropServices)
Indicates that the attributed method is exposed by an unmanaged dynamic-link library (DLL) as a static entry point.
System.Runtime.InteropServices is the namespace
just like you would need
using System.Runtime.InteropServices;
if this was a normal C# programbut i added this into code in the top.. or in variable with code, you mean, right?
sorry if i'm being stupid, but i may not understand you
i don't like this site in total because it always gives me not those im looking for
What are you trying to make?
I believe he meant for you to add
System.Runtime.InteropServices
to WithImports
, and remove DllImportAttribute
from it.oh, now it works, thank you!
but another one thing
can i all these dll imports
put into this string?(
WithImports
)
to make code more cleanno, p/invoke has to be done with attributes