Cannot perform runtime binding on a null reference

“An error occurred while processing the request: Cannot perform runtime binding on a null reference.”

An error occurred while using an add-in by calling the Gemini API in a program called Autodesk Revit. Previously, it had been running without any issues, but now the error appears as shown above. The versions are Gemini-2.5-pro and Gemini-3-pro-preview.

// [MODIFIED] CallGeminiApiAsync 수정
private async Task CallGeminiApiAsync(string prompt)
{
string apiKey = GetApiKey(); // 기존 GetApiKey() 메서드 사용
string modelName = “gemini-2.5-flash”; // [MODIFIED] 2.5 flash로 변경 (속도 및 성능)
var uri = new Uri($“https://generativelanguage.googleapis.com/v1beta/models/{modelName}:generateContent?key={apiKey}”);

 // [MODIFIED] SystemInstruction 수정 (단일 객체 -> JSON 배열 반환)
 string systemInstruction = @"You are a helpful Revit BIM AI Assistant.

Hi @user3998,

This happens when the API returns an empty response or error object instead of the expected content.

The code snippet you provided doesn’t show how you are handling the response object/Candidate array.

I believe you are trying to access response.Candidates[0] without checking if it exists.

Please try to add a null check to ensure the response is valid before binding to its properties, and see if it works.

Thank you!

1 Like