Request.ServerVariables not working in VS 2013 - c#

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

Related

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

.NET/C# DB2 for iSeries 'FatalExecutionEngineError' from IBM.Data.DB2.iSeries

Having trouble connecting from a C#/.NET program to a Development (non-live) iSeries
Getting the following failure when trying to open a new connection:-
"Exception of type 'System.ExecutionEngineException' was thrown."
HResult -2146233082
Managed Debugging Assistant 'FatalExecutionEngineError' has detected a problem in 'C:\Users\sclose\Documents\Visual Studio 2015\Projects\iSeries1\iSeries1\bin\Debug\iSeries1.vshost.exe'.
Additional information: The runtime has encountered a fatal error. The address of the error was at 0x71ccec3c, on thread 0x28bc. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
Just a very simple noddy program which sets a connection string and opens a new connection:-
string ConnectionString = "DataSource=MACH03Y;UserID=sysmon;Password=xxxxxxxxx;LibraryList=U1SCLOSE;Naming=System";
_connection = new iDB2Connection(ConnectionString);
Have iAccess for Windows 7.1 installed and am able to connect and sign on to the iSeries through System i Navigator
Tried:-
1) Various combinations of UserId's and Library lists (valid and invalid)
2) Valid and Invalid DataSource values
3) Different IBM.Data.DB2.iSeries.dll versions including the latest
Always the same failure
We know the same code works successfully in a live environment but this is maybe first time it's been tried in a dev environment!
Normally in dev it uses a mock service and goes nowhere near a real iSeries
I have more experience on the iSeries side than the .NET side
Thinking it's maybe a Network/Firewall issue?
Any help gratefully received
Whenever I have seen this error, it has been a problem with the Visual Studio Debugger. I do not think it is a problem with your code or the IBM.Data.DB2.iSeries.dll.
Error code 5 is an access violation in Windows. These debugger crashes are usually fixed by upgrading Visual Studio or applying the latest service pack. VS2015 is screwy in lots of ways, since it was a ground up rewrite, and I had these errors a few years ago until they fixed them. Try a service pack first. If that doesn't help, try either version 2012 or 2017. There also conceivably could be a Windows update that broke this. It has happened before.
See also: "vshost32.exe has stopped working" OR "fatal execution engine error" in Visual Studio

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

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).

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.

Importing workitem to TFS, work item type not found

I'm looking at this MSDN page but the code breaks on the line
WorkItemType workItemType = teamProject.WorkItemTypes["User Story"];
with the error
An unhandled exception of type
'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemTypeDeniedOrNotExistException'
occurred in Microsoft.TeamFoundation.WorkItemTracking.Client.dll
Additional information: TF201077: The work item type User Story cannot
be found. It may have been renamed or destroyed.
Where/what exactly should "User Story" be?
Do I need to import an XML document to my solution? Is the TFS server I'm connecting to not configured right for the way I'm trying to access it?
Which Template are you using? on your TFS Team Project.
As stated in that web page you need to be using
For example, you might create a user story as defined in MSF for Agile
software development for Visual Studio ALM.

Categories