Invalid URI with UNC path - c#

I have a path that uses some unc paths in the background such as:
\\crfile2\..some folders..\myFile.lbp
and needs to check if the file exists (won't exist in many cases). I have a simple check that reads the file if it exists. It works fine on almost all cases, but I have one customer that is getting an error:
Unhandled Error: Invalid URI: The format of the URI could not be determined.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at RDES.Common.RDLicenseCommon.LicenseBypassData.<GetBypassData>b__0(String x)
at System.Linq.Enumerable.WhereListIterator`1.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
This seems like a valid UNC path correct? I'm not sure where the error is here, and even more so I find it confusing that my machine and hundreds of others use the same path string with no issues but this one user is getting this issue. I know it's very limited because for him it's cause a crash on startup and the program is used by enough people that when I post something with a critical issue like that I know it from many people in very short order (not that I ever have posted anything like that...). Anyway any help would be appreciated.
Here is the code line where the exception is being thrown:
string myPath = AllValidPaths.Where(x => VerifyFileExists(new Uri(x),500)).FirstOrDefault();
You can see by the stack that the exception is being thrown by the constructor of the URI inside of the lambda expression.

Related

MagickBlobErrorException: no such file or directory

When i run the testcase c# application from windows(local machine) it works fine. But when run from azure pipeline getting below exception. Anyone faced like this error? Please help me on this.
i used code:
MagickImage sourceImage = new MagickImage("../../../Images/OutputImages/output-SlightSkew.jpg");
Got error:
Error Message:
ImageMagick.MagickBlobErrorException : UnableToOpenBlob '../../../Images/OutputImages/output-SlightSkew.jpg': No such file or directory # error/blob.c/OpenBlob/3537
Stack Trace:
at ImageMagick.NativeInstance.CheckException(IntPtr exception, IntPtr result)
at ImageMagick.MagickImage.NativeMagickImage.ReadFile(IMagickSettings1 settings) at ImageMagick.MagickImage.Read(String fileName, IMagickReadSettings1 readSettings, Boolean ping)
at ImageMagick.MagickImage.Read(String fileName, IMagickReadSettings`1 readSettings)
at ImageMagick.MagickImage.Read(String fileName)
at ImageMagick.MagickImage..ctor(String fileName)
According to your error message, the error is most likely due to the wrong file path.
In Azure DevOps pipeline, your source code files are in $(System.DefaultWorkingDirectory).
You can check if there is a output-SlightSkew.jpg file in ../../../Images/OutputImages/ in your repository.
If the answer is no, change your path to the correct path.
If the answer is yes, try to replace your path to a specific path, for example {folder A}/{folder B}/Images/OutputImages/output-SlightSkew.jpg.

'Expected Global Line.' exception while loading solution using Roslyn

I'm learning Roslyn and trying it out for the first time. I've written a small code snippet to load a solution and get a reference to a workspace.
IWorkspace workspace = Workspace.LoadSolution(solutionPath);
foreach (IProject project in workspace.CurrentSolution.Projects)
{
CommonCompilation objCompilation = project.GetCompilation();
}
return workspace;
But I'm getting an exception in the first line. The exception details are given below.
Message : Expected Global Line.
stack trace : at
Roslyn.Services.Host.SolutionFile.ParseGlobal(TextReader reader)
at Roslyn.Services.Host.SolutionFile.Parse(TextReader reader) at
Roslyn.Services.Host.LoadedWorkspace.LoadSolution(SolutionId
solutionId, String filePath) at
Roslyn.Services.Host.LoadedWorkspace.OpenSolution(String fileName)
at Roslyn.Services.Host.LoadedWorkspace.LoadSolution(String
solutionFileName, String configuration, String platform, Boolean
enableFileTracking) at
Roslyn.Services.Workspace.LoadSolution(String solutionFileName, String
configuration, String platform, Boolean enableFileTracking) at
Ros2.Program.GetWorkspace(String solutionPath) in
c:\users\amnatu\documents\visual studio
2015\Projects\Ros2\Ros2\Program.cs:line 30
I referred to this link which shows the same issue that I faced. However, the solution of removing the space between EndProject and Global isn't really applicable in my case as my solution file doesn't have any space between them.
Am I missing anything here?Any suggestions on how to resolve this issue?
Apologies for the delayed response. The comment by #JoshVarty helped me understand the issue.
I was indeed using the out dated version and had to use the latest Microsoft.CodeAnalysis library. After I made these changes and updated all classes accordingly, everything worked perfectly.
Thanks JoshVarty.!

type initializer for System.Data.SqlClient threw an exception

This actually worked before but now, not.
string sqlConnString ="Server=server1;Database=Production;Trusted_Connection=true;User ID=User;Password=pwd";
try {
conn = new SqlConnection(sqlConnString );
And I get the exception. (I know the connection string should be in app.config but that didn't work, either.)
This most likely means that there is an error in your app.config file, e.g. badly formed XML or unexpected elements. The error happens because the static fields inside SqlConnection read from app.config to determine trace detail level as described here: http://msdn.microsoft.com/en-us/library/ms254503.aspx
(this question is a duplicate of Exception: type initializer for 'system.data.sqlclient.sqlconnection'?)
Remove the underscore between Trusted and Connection.

FileNotFoundException - no file missing

When entering a view for the first time, this exception is raised:
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
First of all - why would it just happen the first time I enter that specific view? Even IF the issue was in the constructor (which it could not be), it would be called (and the exception thrown) every time I enter the view.
Second of all - how would I find the source of such an exception? It doesn't break into the debugger, and there are no resource files (like background images, app bar icons) missing.
Lastly - what (except directly referencing files in the code) would throw such an exception?
I would show you the code in question, but the file is a bit too big to post all of it.
UPDATE:
After debugging, I have noticed that the error happens after the constructor and OnNavigatedTo() and before Loaded(). There is a thread being launched in the OnNavigatedTo method, but I have tried to try-catch every single element of that part (and every internal part of it), and no error was found.
UPDATE 2:
After debugging some more, I found the error message:
File or assembly name 'System.Windows.debug.resources, Version=2.0.5.0, Culture=en-US, PublicKeyToken=xxxxxxxxxxxxx', or one of its dependencies, was not found.
Also the stack trace:
at System.ThrowHelper.throwVersion37CompatException(ExceptionType newEType,
String newString, ExceptionType oldEType, String oldString)
at System.Reflection.Assembly.Load(String assemblyString)
at System.Windows.Resx..ctor()
at System.Windows.Resx.GetLoader()
at System.Windows.Resx.GetStringHelper(String name)
at System.Windows.Resx.GetString(String name)
at System.Windows.Controls.Primitives.ToggleButton.ToString()
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj,
IntPtr unmanagedObjArgs, Int32 argsTypeIndex,
Int32 actualArgsTypeIndex, String eventName)
you can set break for the first chance exception visual studio, debug in to see the detail about the FileNotFound exception, which file is missing.
sometime, clr try to find some extension dll, which is normally too magic to us. for example, if you use XmlSerialize in your project, if you don't use sgen.exe to generate the dynamic xml serialize dll for your serializble type, CLR will generate one during runtime, but before this, clr will try to load the assemble, which will cause FileNotFoundException, but catched

Issue with GetLocalResource object

I am trying to access my local resources file in my code-behind. I did some googling since I was unsure of how to do it and found this:
oContent.Text = HttpContext.GetLocalResourceObject("NonSupport").ToString();
However, I get an error saying that it needs at least two parameters: VirtualPath and ResourceKey. There is a third, CultureInfo but that one is optional. When I put this in as my virtual path:
HttpContext.GetLocalResourceObject("App_LocalResources/ExpandableListView.aspx.resx", "NonSupport").ToString();
I get the following compiler error message:
The relative virtual path 'App_LocalResources/ExpandableListView.aspx.resx' is not allowed here.
I must be doing something wrong with this since my searches (and some posts I found on here) say all I need to do is call the resource key.
Any thoughts? Thanks!
Did you put a resource file with the name (your aspx web page).aspx.resx into a App_LocalResource folder underneath the path where your ASPX page lives??
Furthermore, just simply call the GetLocalResourceObject method on your current page:
oContent.Text = GetLocalResourceObject("NonSupport").ToString();
No need to use HttpContext for that - the method is defined on the Page class.
Marc

Categories