[NET] System.MissingMethodException: Method not found: System.Object Microsoft.Extensions.AI.ChatOptions.get_ContinuationToken()

ช่วงนี้เจอ Error นี้บ่อย System.MissingMethodException: Method not found อาจจะเพราะใช้ Lib เกี่ยวกับ Microsoft Agent Framework (C#) ด้วย เห็นว่า Build รายวันเลยนะ โดยตัว Error เต็มๆตามนี้ครับ

System.MissingMethodException: Method not found: 'System.Object Microsoft.Extensions.AI.ChatOptions.get_ContinuationToken()'.
2
         at Microsoft.Agents.AI.ChatClientAgent.PrepareThreadAndMessagesAsync(AgentThread thread, IEnumerable`1 inputMessages, AgentRunOptions runOptions, CancellationToken cancellationToken)
         at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
         at Microsoft.Agents.AI.ChatClientAgent.PrepareThreadAndMessagesAsync(AgentThread thread, IEnumerable`1 inputMessages, AgentRunOptions runOptions, CancellationToken cancellationToken)
         at Microsoft.Agents.AI.ChatClientAgent.RunCoreAsync[TAgentRunResponse,TChatClientResponse](Func`5 chatClientRunFunc, Func`2 agentResponseFactoryFunc, IEnumerable`1 messages, AgentThread thread, AgentRunOptions options, CancellationToken cancellationToken)
         at ChatService.ProcessMessageAsync(String connectionId, String userMessage) in d:\NET_CODE\LicenseWeb\LicenseGenChatApi\ChatService.cs:line 46
ChatService: Error: Error processing message for connection 44prlK4P-2A65O0AVFDcGA

System.MissingMethodException: Method not found: 'System.Object Microsoft.Extensions.AI.ChatOptions.get_ContinuationToken()'.
2
   at Microsoft.Agents.AI.ChatClientAgent.PrepareThreadAndMessagesAsync(AgentThread thread, IEnumerable`1 inputMessages, AgentRunOptions runOptions, CancellationToken cancellationToken)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at Microsoft.Agents.AI.ChatClientAgent.PrepareThreadAndMessagesAsync(AgentThread thread, IEnumerable`1 inputMessages, AgentRunOptions runOptions, CancellationToken cancellationToken)
   at Microsoft.Agents.AI.ChatClientAgent.RunCoreAsync[TAgentRunResponse,TChatClientResponse](Func`5 chatClientRunFunc, Func`2 agentResponseFactoryFunc, IEnumerable`1 messages, AgentThread thread, AgentRunOptions options, CancellationToken cancellationToken)
   at ChatService.ProcessMessageAsync(String connectionId, String userMessage) in d:\NET_CODE\LicenseWeb\LicenseGenChatApi\ChatService.cs:line 46

สาเหตุที่เป็นไปได้

📌 Code มีการปรับ API จริงๆ - อาจจะต้องไปไล่ดูใน Git ของ Lib หรือ ถาม Vendor
📌 ตัว Lib NuGet Lib base.common ดันมี Lib a และ b เอามาใช้ร่วมกัน ที่นี้จะมีปัญหาตอน resolve ว่ามันจะเอา Version ได้ ปกติจะเอาใหม่สุด

อันนี้เป็น Error ในหน้าจอ Dev UI ของ Microsoft Agent Framework

ทางแก้หละ

📌 แบบแรก แทนที่จะ ref lib A / B พร้อมกัน มาดูก่อน ว่า Lib A กับ B มี Dependency กันไหม เช่น A required B แทนที่จะใส่ทั้ง A กับ B ลงใน csproj เอาเฉพาะ Lib A ก็พอ อย่างเคสที่ผมเจอจริง เป้นเรื่องของ Lib Microsoft Agent Framework พอใส่ตาม readme มันพัง 5555

  • ก่อนทำ
 <ItemGroup>
    <PackageReference Include="Azure.AI.OpenAI" Version="2.5.0-beta.1" />
    <PackageReference Include="Azure.Identity" Version="1.17.1" />
    <PackageReference Include="Google_GenerativeAI.Microsoft" Version="3.4.1" />
    <PackageReference Include="Microsoft.Agents.AI.DevUI" Version="1.0.0-preview.251114.1" />
    <PackageReference Include="Microsoft.Agents.AI.Hosting" Version="1.0.0-preview.251114.1" />
    <PackageReference Include="Microsoft.Agents.AI.Hosting.OpenAI" Version="1.0.0-alpha.251114.1" />
    <PackageReference Include="Microsoft.Agents.AI.OpenAI" Version="1.0.0-preview.251114.1" />
    <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0" />
    <PackageReference Include="Microsoft.Extensions.AI.AzureAIInference" Version="10.0.0-preview.1.25559.3" />
    <PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="10.0.1-preview.1.25571.5" />
    <PackageReference Include="ModelContextProtocol" Version="0.4.0-preview.3" />
    <PackageReference Include="OllamaSharp" Version="5.4.11" />
  </ItemGroup>
  • อันนี้เรา ตัด Lib ใน csproj ออก เชื่อมทีตัว Microsoft.Agents.AI.DevUI มัน Ref มา ตัวที่ตัวออก เช่น
    - Microsoft.Agents.AI.Hosting
    - Microsoft.Agents.AI.Hosting.OpenAI
    - Microsoft.Agents.AI.OpenAI
    - Microsoft.Extensions.AI.OpenAI
  • จากนั้นทดสอบ Run ครับ

📌 แบบที่สอง Ref ทุก Lib ใน csproj ของเราเลยครับ แล้วทำ Test ดู Compatibly แต่เนื่องจากเรามีเวลาน้อย ผมเลยเลือกแบบแรกไปครับ

และผลลัพธ์ ใช้งานได้ครับ ส่วน Blog How to Microsoft Agent Framework - DevUI


Discover more from naiwaen@DebuggingSoft

Subscribe to get the latest posts sent to your email.