简体   繁体   中英

Visual Studio for Mac: Logs work on a Project and are shown on Azure, but fail on another Project of same Solution

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屏幕截图

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM