microsoft / LLMR

MIT License
53 stars 16 forks source link

Roslyn: The type or namespace name 'Widgets' could not be found - The name 'summary' does not exist in the current context #10

Open MJSahebnasi opened 2 months ago

MJSahebnasi commented 2 months ago

Hello, and thank you for sharing this great project!

I could setup the project without any specific errors (added the Roslyn package and my OpenAI API key. Also made a minor change in the code: had to add an explicit cast to String to solve a compile error. No other issues).

When using the tool, I get 3 errors.

Execution log:

e1

The details of the 3 errors:

(2,42): error CS0246: The type or namespace name 'Widgets' could not be found (are you missing a using directive or an assembly reference?)
UnityEngine.Debug:LogError (object)
RoslynCSharp.RoslynCSharp:LogError (string,object[]) (at Assets/RoslynCSharp/Scripts/RoslynCSharp/Runtime/RoslynCSharp.cs:429)
RoslynCSharp.ScriptDomain:LogCompilerOutputToConsole () (at Assets/RoslynCSharp/Scripts/RoslynCSharp/Runtime/ScriptDomain.cs:1448)
RoslynCSharp.ScriptDomain:CompileAndLoadSource (string,RoslynCSharp.ScriptSecurityMode,RoslynCSharp.Compiler.IMetadataReferenceProvider[]) (at Assets/RoslynCSharp/Scripts/RoslynCSharp/Runtime/ScriptDomain.cs:639)
CompileCompletionsWithReferences:RunCode () (at Assets/Scripts/MR_Copilot/CompileCompletionsWithReferences.cs:119)
ChatCompilationManagerModularFiltered:Compile () (at Assets/Scripts/MR_Copilot/ChatCompilationManagerModularFiltered.cs:449)
ChatCompilationManagerModularFiltered/<RunDebugger>d__43:MoveNext () (at Assets/Scripts/MR_Copilot/ChatCompilationManagerModularFiltered.cs:423)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:SetResult ()
ChatCompilationManagerModularFiltered/<RunInspector>d__42:MoveNext () (at Assets/Scripts/MR_Copilot/ChatCompilationManagerModularFiltered.cs:408)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:SetResult ()
ChatBot/<SendNewChatWithInput>d__28:MoveNext () (at Assets/Scripts/MR_Copilot/Orchestration/ChatBot.cs:260)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:SetResult ()
ChatBot/<SendChat>d__20:MoveNext () (at Assets/Scripts/MR_Copilot/Orchestration/ChatBot.cs:177)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<OpenAI.Chat.ChatResponse>:SetResult (OpenAI.Chat.ChatResponse)
OpenAI.Chat.ChatEndpoint/<StreamCompletionAsync>d__4:MoveNext () (at ./Library/PackageCache/com.openai.unity@7.7.9/Runtime/Chat/ChatEndpoint.cs:77)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Utilities.WebRequestRest.Response>:SetResult (Utilities.WebRequestRest.Response)
Utilities.WebRequestRest.Rest/<PostAsync>d__16:MoveNext () (at ./Library/PackageCache/com.utilities.rest@2.5.6/Runtime/Rest.cs:217)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Utilities.WebRequestRest.Response>:SetResult (Utilities.WebRequestRest.Response)
Utilities.WebRequestRest.Rest/<SendAsync>d__49:MoveNext () (at ./Library/PackageCache/com.utilities.rest@2.5.6/Runtime/Rest.cs:1267)
System.Runtime.CompilerServices.AsyncMethodBuilderCore/MoveNextRunner:Run ()
Utilities.Async.AwaiterExtensions:RunOnUnityScheduler (System.Action) (at ./Library/PackageCache/com.utilities.async@2.1.3/Runtime/Async/AwaiterExtensions.cs:248)
Utilities.Async.SimpleCoroutineAwaiter`1<UnityEngine.AsyncOperation>:Complete (UnityEngine.AsyncOperation,System.Exception) (at ./Library/PackageCache/com.utilities.async@2.1.3/Runtime/Async/SimpleCoroutineAwaiter.cs:113)
Utilities.Async.AwaiterExtensions/<ReturnAsyncOperation>d__29:MoveNext () (at ./Library/PackageCache/com.utilities.async@2.1.3/Runtime/Async/AwaiterExtensions.cs:348)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)
(10,9): error CS0103: The name 'summary' does not exist in the current context
UnityEngine.Debug:LogError (object)
RoslynCSharp.RoslynCSharp:LogError (string,object[]) (at Assets/RoslynCSharp/Scripts/RoslynCSharp/Runtime/RoslynCSharp.cs:429)
RoslynCSharp.ScriptDomain:LogCompilerOutputToConsole () (at Assets/RoslynCSharp/Scripts/RoslynCSharp/Runtime/ScriptDomain.cs:1448)
RoslynCSharp.ScriptDomain:CompileAndLoadSource (string,RoslynCSharp.ScriptSecurityMode,RoslynCSharp.Compiler.IMetadataReferenceProvider[]) (at Assets/RoslynCSharp/Scripts/RoslynCSharp/Runtime/ScriptDomain.cs:639)
CompileCompletionsWithReferences:RunCode () (at Assets/Scripts/MR_Copilot/CompileCompletionsWithReferences.cs:119)
ChatCompilationManagerModularFiltered:Compile () (at Assets/Scripts/MR_Copilot/ChatCompilationManagerModularFiltered.cs:449)
ChatCompilationManagerModularFiltered/<RunDebugger>d__43:MoveNext () (at Assets/Scripts/MR_Copilot/ChatCompilationManagerModularFiltered.cs:423)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:SetResult ()
ChatCompilationManagerModularFiltered/<RunInspector>d__42:MoveNext () (at Assets/Scripts/MR_Copilot/ChatCompilationManagerModularFiltered.cs:408)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:SetResult ()
ChatBot/<SendNewChatWithInput>d__28:MoveNext () (at Assets/Scripts/MR_Copilot/Orchestration/ChatBot.cs:260)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:SetResult ()
ChatBot/<SendChat>d__20:MoveNext () (at Assets/Scripts/MR_Copilot/Orchestration/ChatBot.cs:177)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<OpenAI.Chat.ChatResponse>:SetResult (OpenAI.Chat.ChatResponse)
OpenAI.Chat.ChatEndpoint/<StreamCompletionAsync>d__4:MoveNext () (at ./Library/PackageCache/com.openai.unity@7.7.9/Runtime/Chat/ChatEndpoint.cs:77)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Utilities.WebRequestRest.Response>:SetResult (Utilities.WebRequestRest.Response)
Utilities.WebRequestRest.Rest/<PostAsync>d__16:MoveNext () (at ./Library/PackageCache/com.utilities.rest@2.5.6/Runtime/Rest.cs:217)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Utilities.WebRequestRest.Response>:SetResult (Utilities.WebRequestRest.Response)
Utilities.WebRequestRest.Rest/<SendAsync>d__49:MoveNext () (at ./Library/PackageCache/com.utilities.rest@2.5.6/Runtime/Rest.cs:1267)
System.Runtime.CompilerServices.AsyncMethodBuilderCore/MoveNextRunner:Run ()
Utilities.Async.AwaiterExtensions:RunOnUnityScheduler (System.Action) (at ./Library/PackageCache/com.utilities.async@2.1.3/Runtime/Async/AwaiterExtensions.cs:248)
Utilities.Async.SimpleCoroutineAwaiter`1<UnityEngine.AsyncOperation>:Complete (UnityEngine.AsyncOperation,System.Exception) (at ./Library/PackageCache/com.utilities.async@2.1.3/Runtime/Async/SimpleCoroutineAwaiter.cs:113)
Utilities.Async.AwaiterExtensions/<ReturnAsyncOperation>d__29:MoveNext () (at ./Library/PackageCache/com.utilities.async@2.1.3/Runtime/Async/AwaiterExtensions.cs:348)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)
Object reference not set to an instance of an object
UnityEngine.Debug:LogError (object)
ChatCompilationManagerModularFiltered/<RunDebugger>d__43:MoveNext () (at Assets/Scripts/MR_Copilot/ChatCompilationManagerModularFiltered.cs:429)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:SetResult ()
ChatCompilationManagerModularFiltered/<RunInspector>d__42:MoveNext () (at Assets/Scripts/MR_Copilot/ChatCompilationManagerModularFiltered.cs:408)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:SetResult ()
ChatBot/<SendNewChatWithInput>d__28:MoveNext () (at Assets/Scripts/MR_Copilot/Orchestration/ChatBot.cs:260)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:SetResult ()
ChatBot/<SendChat>d__20:MoveNext () (at Assets/Scripts/MR_Copilot/Orchestration/ChatBot.cs:177)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<OpenAI.Chat.ChatResponse>:SetResult (OpenAI.Chat.ChatResponse)
OpenAI.Chat.ChatEndpoint/<StreamCompletionAsync>d__4:MoveNext () (at ./Library/PackageCache/com.openai.unity@7.7.9/Runtime/Chat/ChatEndpoint.cs:77)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Utilities.WebRequestRest.Response>:SetResult (Utilities.WebRequestRest.Response)
Utilities.WebRequestRest.Rest/<PostAsync>d__16:MoveNext () (at ./Library/PackageCache/com.utilities.rest@2.5.6/Runtime/Rest.cs:217)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Utilities.WebRequestRest.Response>:SetResult (Utilities.WebRequestRest.Response)
Utilities.WebRequestRest.Rest/<SendAsync>d__49:MoveNext () (at ./Library/PackageCache/com.utilities.rest@2.5.6/Runtime/Rest.cs:1267)
System.Runtime.CompilerServices.AsyncMethodBuilderCore/MoveNextRunner:Run ()
Utilities.Async.AwaiterExtensions:RunOnUnityScheduler (System.Action) (at ./Library/PackageCache/com.utilities.async@2.1.3/Runtime/Async/AwaiterExtensions.cs:248)
Utilities.Async.SimpleCoroutineAwaiter`1<UnityEngine.AsyncOperation>:Complete (UnityEngine.AsyncOperation,System.Exception) (at ./Library/PackageCache/com.utilities.async@2.1.3/Runtime/Async/SimpleCoroutineAwaiter.cs:113)
Utilities.Async.AwaiterExtensions/<ReturnAsyncOperation>d__29:MoveNext () (at ./Library/PackageCache/com.utilities.async@2.1.3/Runtime/Async/AwaiterExtensions.cs:348)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)

Thanks in advance!

Kappa666 commented 1 month ago

Sorry for the late reply! This sounds like an issue with the Roslyn Compiler not recognizing the Widgets class defined in the project. The way this is done in the project is a bit hacky - it depends on using the assembly generated by Unity for the project (Assembly-csharp.dll). This should be included in the Assemblies folder - did you perhaps forget to make an assembly reference asset for it? Note that you can also alternatively specify already loaded assemblies in the project rather than refer to the .dll files too.

hepitk commented 1 month ago

Hi, thanks for sharing this project!

I had the same problem, it is fixed by adding the abovementioned Assembly-CSharp reference from the Assemblies folder. In addition, unsafe code needs to be allowed from the Roslyn C# settings and code security checks need to be disabled (found in Tools -> Roslyn C# -> Settings).

Ale8599 commented 1 month ago

I also had the same problem with the same three errors. In general, I think it is quite hard to understand how to properly set up the assembly reference assets. Anyway, I think I managed to solve most of it but it still doesn't work fully and I don't know how to solve the third error presented in this thread, which is "Object reference not set to an instance of an object".

Nyamamoto432 commented 1 week ago

I have the same error. As a beginner with Unity, I am unsure how to create a reference to Assembly-CSharp.dll. Could someone please guide me on this?

youetube commented 1 week ago

I have the same error. As a beginner with Unity, I am unsure how to create a reference to Assembly-CSharp.dll. Could someone please guide me on this?

Firstly, add Roslyn C# runtime plugin to the projects.

Then, ①Inside Unity Editor, open folder→ /Assets/RoslynCSharp/AssemblyReferences/
②Assets > Create > Roslyn C# > Assembly Reference Asset

Image

Look at Inspector

so rename and select file like this↓

Image

Go to /Assets/RoslynCSharp/Resources/ Image

Nyamamoto432 commented 6 days ago

@youetube Thank you so much for your help! I followed your advice, and I was able to resolve the issue. Now I've able to play Playground_new demo successfully!

youetube commented 6 days ago

I also had the same problem with the same three errors. In general, I think it is quite hard to understand how to properly set up the assembly reference assets. Anyway, I think I managed to solve most of it but it still doesn't work fully and I don't know how to solve the third error presented in this thread, which is "Object reference not set to an instance of an object".

@Ale8599 I suspect that unnecessary .dll (AssemblyReference) files were added to RoslynCSharpSettings.asset Only Assembly-CSharp.dll should be appended, while the default 14 .dll files should remain as they are. https://github.com/microsoft/LLMR/issues/14#issuecomment-2474007880

Ale8599 commented 3 days ago

@youetube Thank you for your insight but I still can't manage to make it work. I actually had unnecessary .dll files added to RoslynCSharpSettings.asset but, even by removing them, it doesn't change the result. I'll add a couple of screens to document my situation. Image Image Image

youetube commented 2 days ago

@Ale8599 Press the button of "Select Assembly File" and choose /LLMR-main/Assemblies/Assembly-CSharp.dll Do NOT use "Select Loaded Assembly"! Error message "version=0.0.0.0, PublicKeyToken=NULL" means invalid path to the .dll file Image

Ale8599 commented 1 day ago

Once again thank you for your help, even if the thing you suggested unfortunately didn't actually work. I didn't know that that error message meant it was an "invalid path to the .dll file" problem. Anyway I already used the "Select Assembly File" button to select the path. So the problem must be somewhere else.