Microsoft.Cis.Monitoring.Query error when using Azure.AI.TextAnalytics Package

KA 76 Reputation points
2022-05-10T05:40:03.643+00:00

Hello,
I am building an ASP .NET Web Application using VB.NET. The application will use the Azure.AI.TextAnalytics Package to extract Health Information from a given text.
However, when I run the App using Visual Studio 2019 I keep getting the error as shown below (after the code snippet):

Imports Microsoft.Azure
Imports Azure.AI.TextAnalytics
Public Class WebForm1

    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim azureKC As Azure.AzureKeyCredential
        Dim azureEP As Uri
        Dim client As TextAnalyticsClient
        Dim HealthOpeartion As AnalyzeHealthcareEntitiesOperation

        azureKC = New Azure.AzureKeyCredential("***********************")
        azureEP = New Uri("https://eastus.api.cognitive.microsoft.com/")
        client = New TextAnalyticsClient(azureEP, azureKC)

    End Sub
End Class

Here is the error detail:

Server Error in '/' Application.
Could not load file or assembly 'Microsoft.Cis.Monitoring.Query' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.BadImageFormatException: Could not load file or assembly 'Microsoft.Cis.Monitoring.Query' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.Cis.Monitoring.Query' could not be loaded.


=== Pre-bind state information ===
LOG: DisplayName = Microsoft.Cis.Monitoring.Query
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Microsoft.Cis.Monitoring.Query | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/Kamran/Documents/Python Projects/VBTextAnalyticsWebApp/VBTextAnalyticsWebApp/
LOG: Initial PrivatePath = C:\Users\Kamran\Documents\Python Projects\VBTextAnalyticsWebApp\VBTextAnalyticsWebApp\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Kamran\Documents\Python Projects\VBTextAnalyticsWebApp\VBTextAnalyticsWebApp\web.config
LOG: Using host configuration file: C:\Users\Kamran\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/Kamran/AppData/Local/Temp/Temporary ASP.NET Files/vs/4d81e030/65f461dd/Microsoft.Cis.Monitoring.Query.DLL.
LOG: Attempting download of new URL file:///C:/Users/Kamran/AppData/Local/Temp/Temporary ASP.NET Files/vs/4d81e030/65f461dd/Microsoft.Cis.Monitoring.Query/Microsoft.Cis.Monitoring.Query.DLL.
LOG: Attempting download of new URL file:///C:/Users/Kamran/Documents/Python Projects/VBTextAnalyticsWebApp/VBTextAnalyticsWebApp/bin/Microsoft.Cis.Monitoring.Query.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

Stack Trace:


[BadImageFormatException: Could not load file or assembly 'Microsoft.Cis.Monitoring.Query' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +37
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +159
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +80
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +22
   System.Reflection.Assembly.Load(String assemblyString) +29
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38

[ConfigurationErrorsException: Could not load file or assembly 'Microsoft.Cis.Monitoring.Query' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +726
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +196
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +45
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +172
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +111
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +156
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +695

[HttpException (0x80004005): Could not load file or assembly 'Microsoft.Cis.Monitoring.Query' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +660
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +89
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +189
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,251 questions
Azure AI Language
Azure AI Language
An Azure service that provides natural language capabilities including sentiment analysis, entity extraction, and automated question answering.
353 questions
{count} votes

2 answers

Sort by: Most helpful
  1. KA 76 Reputation points
    2022-05-12T06:58:23.127+00:00

    @Yijing Sun-MSFT and @romungi-MSFT Thanks to both of you for providing your inputs.

    I solved the problem by simply deleting the entire solution directory and then restarting from scratch.

    1 person found this answer helpful.
    0 comments No comments

  2. Yijing Sun-MSFT 7,066 Reputation points
    2022-05-12T03:28:45.53+00:00

    Hi @KA ,
    BadImageFormatException usually means 64 vs 32 bit conflict. One of the assemblies is set to a specific platform i.e. 64 bit or 32 bit while the other is set or defaults to a different one.
    Right click on project settings, then click on build and set the platform target from Any to x64 or x86 , according to your dll settings.

    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments