Integrate Google.Cloud.Vision sdk with AutoCAD .net plugin

Integrate Google.Cloud.Vision sdk with AutoCAD .net plugin

tom.zhengGNS4G
Contributor Contributor
1,827 Views
1 Reply
Message 1 of 2

Integrate Google.Cloud.Vision sdk with AutoCAD .net plugin

tom.zhengGNS4G
Contributor
Contributor

Hi. I'm working with Google.Cloud.Vision.V1 package lately. I want to integrate some OCR feature with my .net plugin.

 

I tested the sdk in a simple c# console app project ( run in .net framework 4.8 ) at first and it works as expected ( can extract text from the image ). But I met some errors when the same code snippet run in my plugin project. Below is my code for extract text : 

 

using Google.Apis.Auth.OAuth2;
using Google.Cloud.Vision.V1;

var clientBuilder = new ImageAnnotatorClientBuilder()
{
    GoogleCredential = GoogleCredential.FromFile("application_default_credentials.json")
};
ImageAnnotatorClient client = clientBuilder.Build();

Image img = Image.FromFile(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\test.png");
IReadOnlyCollection<EntityAnnotation> textAnnotations = client.DetectText(img);

foreach (EntityAnnotation text in textAnnotations)
{
    Console.WriteLine("\n" + text.Description);
}

 

 

the error occurs at line : 

var clientBuilder = new ImageAnnotatorClientBuilder()
{
    GoogleCredential = GoogleCredential.FromFile(credentialsPath)
};

 

the error message:

FileNotFoundException: Could not load file or assembly 'Google.Api.CommonProtos, Version=2.6.0.0, Culture=neutral, PublicKeyToken=...' or one of its dependencies.

 

I have bindingRedirect in my app.config as below but it seems like it's not working:

<dependentAssembly>
    <assemblyIdentity name="Google.Api.CommonProtos" publicKeyToken="3ec5ea7f18953e47" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.7.0.0" newVersion="2.7.0.0" />
</dependentAssembly>

 

All the dependencies is installed automatically when I install Google.Cloud.Vision.V1 via NeGet package manager. I didn't do any changes to the dependencies. I have no idea why this error occurs when running in AutoCAD plugin, while working well in other project. Has anyone encoutered similar problem before? I need some suggetions. Really appreciate for help!

0 Likes
1,828 Views
1 Reply
Reply (1)
Message 2 of 2

boliekcubarti2436
Explorer
Explorer

The problem often comes from the plugin’s sandboxed environment, where dependencies aren’t always loaded properly. You can check if the required assemblies are being copied to the plugin's bin folder or try manually referencing the Google.Api.CommonProtos assembly. Another option is to ensure your plugin runs on the same framework version as your test console app (like .NET Framework 4.8) to avoid any compatibility issues.

 

As for costs, I've used Google Cloud Vision in several projects, and the pricing has been manageable, especially after finding discounts that made scaling the service cheaper. You can explore Google Cloud Pricing to see what options are available based on your usage.

0 Likes