InvalidOperationException: Could not locate the hub named 'Roslyn' - c#

I'm making a Roslyn diagnostic. When debugging the diagnostic, which launches a separate instance of Visual Studio, I get the following exception:
Exception thrown: 'System.InvalidOperationException' in
Microsoft.VsHub.Client.dll
Additional information: Could not locate the hub named 'Roslyn'
No further details are given. What does this exception mean? What can I do about it? I'm quite confused because earlier I was able to debug this project just fine. I've tried to 'git clean -f -x -d' but to no avail.

As discussed, Visual Studio throws a lot of exceptions during startup. Debugging tips are either:
Enable "Just My Code" under Debugging > General in Tools Options.
In the Exception Settings window, make sure breaking on an exception being thrown is off.

Related

Trying to Edit and Continue on a cshtml file is always throwing an exception

When I make any change to a CSHTML file while debugging then reload the page, I get this exception. This used to work, and I'm not aware of any changes that could affect this. Googling this error message hasn't been helpful either. Any direction is very much appreciated.
I have tried all the suggestions in https://stackoverflow.com/a/27672935/3397630 without any luck.
I am currently using Visual Studio Community 2022 and .NET 5, but this same thing was happening with 2019.
An unhandled exception occurred while processing the request.
MissingMethodException: Method not found: 'Void Microsoft.CodeAnalysis.CompilationOptions.set_ReferencesSupersedeLowerVersions_internal_protected_set(Boolean)'.
Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions.WithReferencesSupersedeLowerVersions(bool value)
TypeInitializationException: The type initializer for 'Microsoft.CodeAnalysis.CSharp.CSharpCompilation' threw an exception.
Microsoft.CodeAnalysis.Razor.CompilationTagHelperFeature.GetDescriptors()
It sounds like you may need to enable runtime compilation of Razor files: https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-5.0&tabs=visual-studio
See also: .NET Core 3.0: Razor views don't automatically recompile on change

Exceptions thrown in Output window by mscorlib.dll, System.Data.dll and EntityFramework.dll

I removed a dynamic filter from OnModelCreating and the related NuGet package, EntityFramework.DynamicFilters, from my application as it is no longer required. As soon as I did this I started seeing Exceptions being thrown in the Output Window.
First when I run my application (C# with WPF and EF) I get:
Exception thrown: 'System.TypeLoadException' in mscorlib.dll
Then when I access my Data (Entity Framework) I get a whole bunch of exceptions when my code reaches this statement:
public List<T> GetAll() => Table.ToList();
The errors include:
Exception thrown: 'System.Data.SqlClient.SqlException' in System.Data.dll
Exception thrown: 'System.Data.SqlClient.SqlException' in EntityFramework.dll
Exception thrown: 'System.Data.Entity.Core.EntityCommandExecutionException' in EntityFramework.dll
Exception thrown: 'System.Data.Entity.Core.EntityCommandExecutionException' in EntityFramework.SqlServer.dll
The odd thing is that data is returned as expected and the application appears to be working, however, my gut tells me not to simply ignore them and hope for the best.
Taking advice from other posts I deleted the content of the Debug folder, Cleaned Solution and Rebuilt solution with no improvement.
Following other advice I uninstalled and re-installed Microsoft.Net Core and Microsoft.Net Framework, also with no improvement. My application is targeting .Net Framework 4.8
I removed and repaired the Entity Framework NuGet package, still no help.
To make 100% sure it was not a bug in my code I cloned the application to a different machine and it ran perfectly first time. (Edit: for clarity I also created a new folder on problematic machine and cloned to that with same problem) This tells me it must be something in my environment, but what?
I am all out of ideas, short of formatting by hard drive and re-installing Windows which I actually seriously considered a few time in the last 24 hours.
Reading https://learn.microsoft.com/en-us/visualstudio/debugger/just-my-code?view=vs-2019 prompted me to compare the debug settings on the two machines. Turns out that the problematic machine had Enable Just My Code unchecked. Checking it makes my problem "go away". The question now I suppose is whether it is safe to simply ignore exception which are "not in my code"?
After much research, my problem turned out to be the Debug setting in Visual studio which was not set to "Enable Just My Code". (Tools -> Options -> Debugging Tab, Enable Just My Code). https://learn.microsoft.com/en-us/visualstudio/debugger/just-my-code?view=vs-2019
From what I can gather from Google, it is safe enough to ignore minor errors originating from external assemblies. Assuming they are not impacting your program logic that is. I am not 100% comfortable with ignoring exceptions, but be that as it may.

Exception was thrown during invocation in VisualStudio

How to debug watches Visual Studio debugger is unable to show?
How to know, which exception occurred and how to fix it?
Expression watched is exactly the same as it was in code line earlier, so I suspect Visual Studio just unable to compute certain expressions in debugger.

TFS 2013 Throws Lib2GitSharp Error During Build/Deploy (Intermittent)

For a while now, I have been having an issue with Team Foundation Server build/deploy process throwing the following error intermittently:
Unhandled Exception: System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
at LibGit2Sharp.Core.NativeMethods.git_threads_init()
at LibGit2Sharp.Core.NativeMethods.LibraryLifetimeObject..ctor()
at LibGit2Sharp.Core.NativeMethods..cctor()
--- End of inner exception stack trace ---
at LibGit2Sharp.Core.NativeMethods.RemoveHandle()
at LibGit2Sharp.Core.NativeMethods.LibraryLifetimeObject.Finalize()
Exception Message: MSBuild error 255 has ended this build. You can find more specific information about the cause of this error in above messages. (type BuildProcessTerminateException) Exception Stack Trace: at System.Activities.Statements.Throw.Execute(CodeActivityContext context) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
This problem is very intermittent and it can be bypassed by simply retrying the build. Has anyone else run into this? Any solutions?
I know it is a little bit late for answer but it might help someone else
answer by Buck Hodges
We have now gotten to the bottom of this issue after debugging it with Manoj and customer support. It affected gated checkin of continuous delivery of Azure deployments as part of the build process when using the Azure SDK 2.5 or older. The workaround is to add /p:GenerateBuildInfoConfigFile=false to the msbuild arguments in your build definition. We are working on updating the build VM in production, but that will take 24-48 hours to propagate to all build pools.
You might want to read more in context here
https://social.msdn.microsoft.com/Forums/en-US/5a0d1950-1367-41a6-9171-676a0d0e93c1/tfs-online-getted-checkin-build-failures-vs-online-tfs-online-team-need-to-look-into-it?forum=TFService
Alternative solution based on comments
If you have VS installed on your build server, make sure you have opened it and licensed it. by #Phill
Strangely enough for me, I was getting the same error in the build logs:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\BuildInfo\Microsoft.VisualStudio.ReleaseManagement.BuildInfo.targets (147): The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception.
Unhandled Exception: System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
I was able to simply RETRY the build, and it did not fail on the second try. So for me it was a transitory build issue.
Although late to the party, experienced this error recently and while the solution marked as the answer worked for that build, the error was fixed (and the switch removed) when Visual Studio 2012 was upgraded to Visual Studio 2015 Update 3 on the build server which was running TFS 2015 Update 3.
I hit this after I had upgraded my TFS 2013 XAML build machine to TFS 2015.
I had also changed the user that TFS 2015 XAML build used to run the build (service.
The Fix:
I had to log into the TFS 2015 XAML build machine as that new user and launch VS (I was using VS2013).
It ran through it's first time launch questions and setup.
I still saw the Lib2GitSharp Error issue sometimes after that.
Then I also logged VS (on the TFS 2015 XAML build machine) into a valid VS account.
I have not seen the Lib2GitSharp Error since and I never used the /p:GenerateBuildInfoConfigFile=false option.
I resolved this error by adding the build account to the local administrators group on the build machine.

Remote debugging with informations?

I'm using the Visual Studio 2012 Remote debugguer and it works fine.
But I'm not getting a lot of informations.
I agree with the fact that I can't have the source code when an unhandled exception is throw but I'm surprised that the remote debugguer don't send me the line or the function or simply the stacktrace.
All I got is, for example :
Unhandled ArgumentNullException in System.core.dll
Is there a way to compile a program (with VS 2012) that can send more information in remote debugging?
Check following points :
The assemblies should be built in Debug mode instead of Release mode
The debug symbols should be present at target location (PDB files)
The source code should not have been modified after the remote assemblies were built.
I think you should have administrator privileges for this to complete.

Categories