Where are situated all SharePoint server error codes descriptions? - c#

During execution the code belowe Microsoft.SharePoint.Client.ServerException with ServerErrorCode = -2147024894 has been thrown. But I don't know any information about this code. May be you know where I can find the correspondence between SP ServerErrorCodes and their descriptions ?
private SP.Folder GetFolderByRelativeUrl(string folderRelativePath)
{
var folder = _spClientContext.SpContext.Web.GetFolderByServerRelativeUrl(folderRelativePath);
_spClientContext.SpContext.Load(folder);
_spClientContext.SpContext.ExecuteQuery(); // here exception is thrown
return folder;
}
MSDN has no information about codes' descriptions.
UPDATED:
Full description
Microsoft.SharePoint.Client.ServerException: File Not Found.
at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
...

Finally, by chance I've found.
SharePoint server erros codes

Many common error codes are included in the ClientErrorCodes class:
CSOM: Microsoft.SharePoint.Client.ClientErrorCodes
JSOM: SP.ClientErrorCodes

Related

How can I retrieve the LoaderExceptions property from the Exception class? [duplicate]

I get a error message while updating my service reference:
Custom tool warning: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
How can I retrieve the LoaderException property?
Update: My errors went away when I reimported the domain object projects. I have no idea why this fixed the issue, but I'm happy it's working.
try
{
// load the assembly or type
}
catch (Exception ex)
{
if (ex is System.Reflection.ReflectionTypeLoadException)
{
var typeLoadException = ex as ReflectionTypeLoadException;
var loaderExceptions = typeLoadException.LoaderExceptions;
}
}
catch (ReflectionTypeLoadException ex)
{
foreach (var item in ex.LoaderExceptions)
{
MessageBox.Show(item.Message);
}
}
I'm sorry for resurrecting an old thread, but wanted to post a different solution to pull the loader exception (Using the actual ReflectionTypeLoadException) for anybody else to come across this.
Using Quick Watch in Visual Studio you can access the LoaderExceptions from ViewDetails of the thrown exception like this:
($exception).LoaderExceptions
Another Alternative for those who are probing around and/or in interactive mode:
$Error[0].Exception.LoaderExceptions
Note: [0] grabs the most recent Error from the stack

C# get the directory name from the DirectoryNotFoundException

I made an application that search for some files in some directories. When a directory isn't there it throws the DirectoryNotFoundException. I catch that exception but it doesn't have a DirectoryName property or something like that like the FileNotFoundException (FileName). How can I find the Directory Name from the exception properties?
There's no way to natively do this.
Add this class somewhere to your project:
public static class DirectoryNotFoundExceptionExtentions
{
public static string GetPath(this DirectoryNotFoundException dnfe)
{
System.Text.RegularExpressions.Regex pathMatcher = new System.Text.RegularExpressions.Regex(#"[^']+");
return pathMatcher.Matches(dnfe.Message)[1].Value;
}
}
Catch the exception and use the type extension like this:
catch (DirectoryNotFoundException dnfe)
{
Console.WriteLine(dnfe.GetPath());
}
It looks like a hack, but you can extract the path from the Message property. As for me, I would prefer to check if the directory exists first, by using the Directory.Exists method.
catch (DirectoryNotFoundException e)
{
// Result will be: Could not find a part of the path "C:\incorrect\path".
Console.WriteLine(e.Message);
// Result will be: C:\incorrect\path
Console.WriteLine(e.Message
.Replace("Could not find a part of the path \"", "")
.Replace("\".", ""));
}
It is a little inconsistent that FileNotFoundException has the file name, but DirectoryNotFoundException doesn't have the directory name, isn't it?
Here's a work around: Before you throw the exception, associate the errant directory name using Exception's Data property.
Immediately before you attempt to find files in a directory, save the name of the directory in a variable. Then begin a try block for the code that looks in that directory. You now have the directory name available should that block of code throw.
For example:
// ... somewhere in some method that's about to search a directory.
var dirName = directories[i]; // or something -- how do you get it before you pass it to DirectoryInfo?
try
{
SearchDirectory(dirName); // or a block of code that does the work
}
catch(Exception e)
{
// at this point, you know dirName. You can log it, add it to a list of erroring
// directories, or whatever. You could throw here, or swallow the error after logging it, etc.
}
Check that it exists first with Directory.Exists
If you are only looking to stomp this one bug in your IDE, then you can try doing this:
In Visual Studio, go to Debug -> Exceptions, then check the Thrown box for Common Language Runtime Exceptions. This will take you right to an exception when it happens, instead of waiting to get caught.
Sorry to dig up an old post, but as other has said it is pretty stupid that DirectoryNotFoundException does not have the directory as a property when FileNotFoundException does.
I've put it in as feature request for .NET:
http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/4472498-directorynotfoundexception-should-expose-the-name-
The format of the Message member of the DirectoryNotFoundException thrown from most Directory class methods is "Directory 'input' not found.". It shouldn't be hard to extract the input from this string.
Question thou, why would you need to get the input parameter from the exception if you're the one invoking the method with that exact parameter?

How to retrieve the LoaderException property?

I get a error message while updating my service reference:
Custom tool warning: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
How can I retrieve the LoaderException property?
Update: My errors went away when I reimported the domain object projects. I have no idea why this fixed the issue, but I'm happy it's working.
try
{
// load the assembly or type
}
catch (Exception ex)
{
if (ex is System.Reflection.ReflectionTypeLoadException)
{
var typeLoadException = ex as ReflectionTypeLoadException;
var loaderExceptions = typeLoadException.LoaderExceptions;
}
}
catch (ReflectionTypeLoadException ex)
{
foreach (var item in ex.LoaderExceptions)
{
MessageBox.Show(item.Message);
}
}
I'm sorry for resurrecting an old thread, but wanted to post a different solution to pull the loader exception (Using the actual ReflectionTypeLoadException) for anybody else to come across this.
Using Quick Watch in Visual Studio you can access the LoaderExceptions from ViewDetails of the thrown exception like this:
($exception).LoaderExceptions
Another Alternative for those who are probing around and/or in interactive mode:
$Error[0].Exception.LoaderExceptions
Note: [0] grabs the most recent Error from the stack

How to create resource manager in ASP.NET

I would like to create resource manager on my page and use some data stored in my resource files. (default.aspx.resx and default.aspx.en.resx)
The code looks like this:
System.Resources.ResourceManager myResourceManager = System.Resources.ResourceManager.CreateFileBasedResourceManager("resource",
Server.MapPath("App_LocalResources") + Path.DirectorySeparatorChar, null);
if (User.Identity.IsAuthenticated)
{
Welcome.Text = myResourceManager.GetString("LoggedInWelcomeText");
}
else
{
Welcome.Text = myResourceManager.GetString("LoggedOutWelcomeText");
}
but when i compile and run it on my local server i get this type of error:
Could not find any resources appropriate for the specified culture (or the neutral culture) on disk.
baseName: resource locationInfo: fileName: resource.resources
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture (or the neutral culture) on disk.
baseName: resource locationInfo: fileName: resource.resources
Source Error:
Line 89: else
Line 90: {
Line 91: Welcome.Text = myResourceManager.GetString("LoggedOutWelcomeText");
Line 92: }
Line 93:
can you please assist me with this issue?
Use GetLocalResourceObject() which is part of a System.Web.Page's base.
If you wish to access global resources use GetGlobalResourceObject().
keep it simple ;-)
According to MSDN, CreateFileBasedResourceManager is expecting compiled resource files. Usually, one puts .resx files in App_LocalResources. Do you have files in this directory named resource.XXX.resources (where XXX is the current culture id) in this directory.
I don't have a VS handy in order to check this in an ASP.NET project, but the usual way to handle resource strings is to go the project properties, Resources tab and create strings there. This generates a strongly-typed wrapper around your resources, avoiding the need to explicitly create your own ResourceManager.

Why can't I use the 'AccessDeniedException' namespace?

I get the message that the namespace can't be found when I use the code below. Where does the AccessDeniedException live?
try { ... }
catch (SomeKindOfException ex)
{
MessageBox.Show(ex.Message);
}
catch (AccessDeniedException ex)
{
//Do something else
}
Thanks
I don't think that's the exception you're looking for. The only one with this name (that I can find) is in a Sharepoint namespace. Try attaching the debugger and seeing exactly what the type of the thrown exception is.
The type of the exception is going to vary depending on your context. So for example, if it's an "access denied" when trying to open a file, it could be a FileLoadException, or something similar. If it's encountered because of Code Access Security, it will be SecurityException. And so on.
You may need to give the full namespace on the exception, or have a using statement at the top of your code file so .NET knows where to find the exception you're talking about. If that doesn't work, maybe you need to add the DLL that contains that exception to the "REFERENCES" list in your project.

Categories