Hack Forums
[.NET] CodeDom compiler having trouble accessing dll's in temp - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] CodeDom compiler having trouble accessing dll's in temp (/showthread.php?tid=5773690)



CodeDom compiler having trouble accessing dll's in temp - NovaHowl - Dec 23, 2017

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!


RE: CodeDom compiler having trouble accessing dll's in temp - Zettabit - Dec 24, 2017

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?


RE: CodeDom compiler having trouble accessing dll's in temp - NovaHowl - Dec 24, 2017

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.


RE: CodeDom compiler having trouble accessing dll's in temp - Zettabit - Dec 24, 2017

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.


RE: CodeDom compiler having trouble accessing dll's in temp - NovaHowl - Dec 24, 2017

(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.


RE: CodeDom compiler having trouble accessing dll's in temp - NovaHowl - Dec 29, 2017

Nope, I don’t need to reference any dll’s. If anyone could help me with this, it would be greatly appreciated.