How to eliminate the error "XamlParseException: Set connectionId threw an exception"? - c#

I develop WPF Prism 6 MVVM multimodule application. Until today everything was OK. But this morning I decided to clean and rebuild my application. And after cleaning and rebuilding I have the following error when my application runs: System.Windows.Markup.XamlParseException" in PresentationFramework.dll. Set connectionId threw an exception: number of line is "5" position in line is "14". I've done all (clean and rebuild my application, e.t.c... in general everything that was suggested in the web to this case) but none of this helped me. You can see the error below.
What the reason of the error? How to eliminate it? Please help.

The "Set connectionId" is a bug in the XAML code generator. Look at this answer: https://stackoverflow.com/a/5642898/200443.
The problem can also occur if loading a Wpf related assembly fails (Xceed.Wpf.Toolkit.dll for not naming it).

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

Weird error: Microsoft (R) Visual C# Compiler version 3.5.0-dev-20359-01 (8da8ba0c)

I have a Unity 2020.3.22f1 project that was perfectly working at first. However, this error occured after editing and saving one of my scripts in Visual Studio (with no apparent bug in it):
I don't give details about my script or the project, because it doesn't seem to relate to the project itself or what I did, as the error appears now in all my Unity projects! I first tried to delete the script that triggered the bug, then I deleted the whole project. I even uninstalled/reinstalled Unity (different versions), Visual Studio and Unity Hub. But it seems that now I'm stuck with this forever.
Does anyone have a single clue about this? I saw one or two people having the same problem on the web, and with no other solution than formatting the hard drive. As I'm not working on my personal computer, I can't do that...I mean, there must be a rational explanation to this bug!!
I downloaded the latest version of Unity (2021.2.2f1), launched a brand new project, and the error now turned to: "The specified path can't be found" (rough translation from french), without more precision...still no idea what it means.
Ok, I found a solution from here: Unity 2019.3.0a7: Microsoft Visual C# Compiler Errors
I don't know how it's related, but it is suggested that the error can be triggered by uninstalling Anaconda and Python (which I happened to do recently), which leads to remaining artifacts in the Windows registry. I then deleted the following item in the Windows registry:
Computer\HKEY_CURRENT_USER\Software\Microsoft\Command
Processor\AutoRun
and restarted Unity. Now it works!
Got the same issue, the problem is in an incomplete path
Command line is : "C:\Program Files\Unity\Hub\Editor\2022.1.0a13\Editor\Data\Tools\netcorerun\netcorerun.exe" "C:/Program Files/Unity/Hub/Editor/2022.1.0a13/Editor/Data/Tools/ScriptUpdater/ApiUpdater.MovedFromExtractor.exe" "Library\Bee\artifacts\mvdfrm\UnityEngine.LocalizationModule.dll_9374ECE80455BEFE.mvfrm" "C:\Program Files\Unity\Hub\Editor\2022.1.0a13\Editor\Data\Managed\UnityEngine\UnityEngine.LocalizationModule.dll"
Unhandled exception. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\damos\project name is missing here\Library\Bee\artifacts\mvdfrm\UnityEngine.LocalizationModule.dll_9374ECE80455BEFE.mvfrm'.
This path is missing the project name between damos ans library

MongoDB C# driver returns MissingMethodException. Any workaround?

I'm writing a fairly simple console app using .NET Core and trying to attach to a Mongo DB. It appears that the current release has been broken because of changes to the DnsClient (i.e. the actual error is: Method not found: 'DnsClient.IDnsQueryResponse DnsClient.LookupClient.Query(System.String, DnsClient.QueryType)'.). Is anyone aware of a work-around for this problem as the Mongo-ites don't seem in any rush to get a fix out for us poor C# junkies?
It looks like there is a ticket created regarding this issue in mongodb issue tracker
https://jira.mongodb.org/browse/CSHARP-2330
Also, there is a comment inside the ticket with a workarund:
I found the solution of this problem. DnsClient 1.1.1 cause this
error. downgrade to 1.0.7, and try again.
if you see error "Could not load file or assembly 'DnsClient' or one
of its dependencies. Manifest definition does not match the assembly
reference",make sure to check redirect setting in web.config.
newVersion section in "dependentAssembly/bindingRedirect" should be
"1.0.7.0".
Actually, I got this exception as well. Follow the above steps solved my problem.

Request.ServerVariables not working in VS 2013

I have been using Visual Studio 2010 for the last few years but today we were required to update to 2013. I went to open my existing project, which worked without any issues previously but now throws the following error:
A first chance exception of type 'System.ArgumentOutOfRangeException'
occurred in mscorlib.dll
Additional information: startIndex cannot be larger than length of string.
This error is triggered at this line of code:
string logon_user = Request.ServerVariables["LOGON_USER"].Substring(7);
Any ideas on how to resolve this? After some research I found a simple workaround by using this line instead:
string logon_user = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Substring(7);
But I am more interested in finding out the reason why Request.ServerVariables doesn't work anymore. I am using this in tons of other projects and would like to see if it's something I can resolve without changing the line in every project.
My guess is that you're running this locally, correct? ON your development machine? If that's the case, then sometimes Visual Studio will reset Anonymous authentication to on, and if it 's on, then the ServerVariables will return null.
See this answer:
IIS express applicationhost.config security is reset every time a solutions is opened in VS2012

Troublesome System.TypeLoadException

I'm currently managing an ASP.NET application for my company. Recently, I have been getting a System.TypeLoadException when I try debugging the code.
The exact message is:
Inheritance security rules violated by type: 'System.Net.Http.Formatting.JsonContractResolver'. Derived types must either match the security accessibility of the base type or be less accessible.
And it keeps pointing to the following region as the source of the error:
Line 21: new { controller = "Help", action = "Index", apiId = UrlParameter.Optional });
Line 22:
Line 23: HelpPageConfig.Register(GlobalConfiguration.Configuration);
Line 24: }
Line 25: }
The above is found in the help page configuration for Web API help content.
Has anyone had any of such issues?
UPDATE:
This particular issue started the very moment I deleted the bin folder from TFS.
After over 24 hours of tireless research (and worrying) I resolved the issue.
Seeing that I kept on throwing a System.TypeLoadException, I researched around that type and found the several reasons why that exception gets thrown.
In my case it was because the particular version of Newtonsoft.Json.dll it needed wasn't what was being referenced, as it was stubbornly pointing to the wrong package folder that held the version meant for .NET 2.0 and 3.5. After removing those packages, I removed the referenced and added it again from the right package folder, cleaned the solution and built and wa-la it was back up and fine.
Those are not the lines that are causing the exception, you see those lines referenced because the HelpPageConfig.Register(GlobalConfiguration.Configuration) is where the code that causes the exception is run. The actual exception is happening somewhere deeper in your Register method on the HelpPageConfig class.
Most likely though, you have another class that is inheriting from JsonContractResolver that is marked as internal. I can't tell you exactly, obviously, without seeing all of your code. But do a quick search across the files for a class that is inherting from that base class and go from there.
I upgraded Microsoft.AspNet.WebApi to version="5.2.7" from version="4.0.30506.0"and updated newtonsoft to 7.0.1.
It is due to a mix of versions in the dependencies. Thanks for the pointer.

Categories