7

On the main Project of the Solution I have:

public static void Main(string[] args)
{
    // Testing Logs on Azure Application Insights: 
    var telemetry = new Microsoft.ApplicationInsights.TelemetryClient();
    telemetry.TrackTrace("Test of ApplicationInsights.TelemetryClient() on Program.cs");

    CreateWebHostBuilder(args).Build().Run();     
}

It's working and the log is being shown on Azure Application Insights.

Unfortunately, when I add the same code to another Project of the same Solution, it does not work: a Exception is throw on Azure instead.

I've tried to add a reference to the main Project (as I think that would import its nugets and rest of things needed). Unfortunately I can't because it says:

cyclic dependencies not allowed

So I've added the same nugets to that other Project of the Solution. By doing that, it compiles and I can upload to Azure. But I cannot see the Log (Trace) because of that error:

Azure screenshot

Text version of the Log (Trace) being shown on Azure:

AI (Internal): [Microsoft-ApplicationInsights-AspNetCore-StartupBootstrapper] Could not load Microsoft.AspNetCore.ApplicationInsights.HostingStartup. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.ApplicationInsights.HostingStartup, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
File name: 'Microsoft.AspNetCore.ApplicationInsights.HostingStartup, Culture=neutral, PublicKeyToken=null'
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, IntPtr ptrLoadContextBinder)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, IntPtr ptrLoadContextBinder)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, StackCrawlMark& stackMark, IntPtr pPrivHostBinder)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, StackCrawlMark& stackMark)
   at System.Reflection.Assembly.Load(String assemblyString)
   at Microsoft.ApplicationInsights.AssemblyLoader.Load(String assemblyName)
   at StartupBootstrapper.Startup.TryLoadStartupAssembly(String assemblyName)

I'm on Visual Studio for Mac (aka VS for mac 2019). Notice it is actually different to Visual Studio for Windows: it's much easier to Debug on Azure using Visual Studio for Windows!

What am I doing wrong?

chelder
  • 3,819
  • 6
  • 56
  • 90
  • 1
    Notice I'm also asking this question here: https://techcommunity.microsoft.com/t5/Azure/telemetry-TrackTrace-quot-my-text-quot-works-on-a-workspace-but/m-p/808827 – chelder Aug 17 '19 at 21:25
  • Are app settings same on both projects? – Vova Bilyachat Sep 11 '19 at 23:58
  • @VolodymyrBilyachat No: I have to repeat the same code over and over in all projects of the solution? It seems a ugly solution as I should repeat any change a lot of times, so it's hard to maintain... :/ – chelder Sep 12 '19 at 14:57

1 Answers1

0

Try adding package to the project via nuget package manager or via dotnet cli command

dotnet add package Microsoft.ApplicationInsights --version 2.10.0

If it's already installed try to reinstall and get it up to date

Adam Marczak
  • 2,257
  • 9
  • 20