Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

CodeDom compiler having trouble accessing dll's in temp

Code
Public Function GenerateScript(code As String) As IScript
    Using provider As New VBCodeProvider()
        Dim parameters As New CompilerParameters()
        parameters.GenerateInMemory = True
        parameters.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location)
        Dim interfaceNamespace As String = GetType(IScript).Namespace
        Dim codeArray() As String = New String() {"Imports " & interfaceNamespace & Environment.NewLine & code}
        Dim results As CompilerResults = provider.CompileAssemblyFromSource(parameters, codeArray)
        Return CType(results.CompiledAssembly.CreateInstance("Script"), IScript)
    End Using
End Function
I am using the code above to run a string that may change over time. When I run this however, I get this error:
Code
System.IO.FileNotFoundException: 'Could not load file or assembly 'file:///C:\Users\nova\AppData\Local\Temp\ykujgxkp.dll' or one of its dependencies. The system cannot find the file specified.'
I'm not sure how to fix this. Could anyone help me please?

Thanks!


Ok, I've realised now after some googling that the application is trying to access the system temp, not the local temp. I was wondering whether I could change it to use the local temp instead of the system one? And if so, how? Thanks!
I'm confused on what you mean by local temp.

I'm assuming this is what you're referring to:
Local temp is C:\Users\username\AppData\Local\Temp
System temp is C:\Windows\Temp

Just by looking at your error message, it says that it is attempting to access the local temp, but the file it's searching for is not in the directory. Can you see it by viewing the folder in explorer?
шкідливе ПО для ентузіастів

Jabber: [email protected]
[email protected]

In the above edit I was mistaken. It is trying to access the local temp or the user temp (C:\Users\username\AppData\Local\Temp). CodeDom compiler uses these dll's only temporarily and then deletes them, hence why it's in the temp folder. You can also see this because the name of the dll changes each time. And no, I cannot see the dll in file explorer.
Looking back at your code, why are you adding a reference to the executing assembly? Would this not most likely be the EXE every time? Or in this case it's resolving to the temporary DLL, which might be your problem.
шкідливе ПО для ентузіастів

Jabber: [email protected]
[email protected]

(Dec 24, 2017 02:29 AM)Zettabit Wrote:  Looking back at your code, why are you adding a reference to the executing assembly? Would this not most likely be the EXE every time? Or in this case it's resolving to the temporary DLL, which might be your problem.

It is resolving to the temporary dll. My issue is that it either can’t read it or write it.


I now think I need to reference a dll to make this work. I don't know which one though.
Nope, I don’t need to reference any dll’s. If anyone could help me with this, it would be greatly appreciated.


Possibly Related Threads...
Thread / Author Replies Views Last Post
by arul12Nov 23, 2023 10:10 AM 2 156 Nov 23, 2023 10:10 AM
Last Post: arul12
[C] by SecurifierJan 17, 2020 07:20 AM 12 416 Jan 17, 2020 07:20 AM
Last Post: SIM-3602340
[C#] by autisticilabJan 12, 2018 10:34 AM 13 630 Jan 12, 2018 10:34 AM
Last Post: Ninja