COMException while adding paths to a ShellLibrary - c#

I'm using Windows 7's Shell Libraries to overwrite an existing library and add new paths to it, using the managed wrapper available through the Windows API Code Pack 1.1.
Every now and then, I can't seem to reproduce this in any way, a COMException is thrown while adding the paths to the library:
System.Runtime.InteropServices.COMException (0x80070497): Unable to remove the file to be replaced. (Exception from HRESULT: 0x80070497)
at Microsoft.WindowsAPICodePack.Shell.IShellLibrary.Commit()
at ... (local code from here on out)
The code is quite straightforward. The error is thrown on the Add method.
using ( var activityContext = new ShellLibrary( LibraryName, true ) )
{
Array.ForEach( dataPaths, p => activityContext.Add( p.LocalPath ) );
}
Is there a certain scenario where this exception is to be expected which I can reproduce/test for?
Assuming this is a bug in the shell libraries, I could just catch the exception and retry doing the operation a couple of times, although I'm hoping for a cleaner 'solution'.

Related

CodecQuery.FindAllAsync crashes through try/catch when querying Audio codecs without subtype

Blank project repo with problematic code
I have the following code for querying all the supported Audio codec following this article using CodecQuery.FindAllAsync
try
{
var query = new CodecQuery();
var queryResult = await query.FindAllAsync(CodecKind.Audio, CodecCategory.Encoder, "");
var subTypes = queryResult
.SelectMany(q => q.Subtypes)
.ToHashSet();
// Other codes
}
catch (Exception ex)
{
Debug.WriteLine(ex);
throw;
}
As the documentation mentioned,
To specify that all codecs of the specified kind and category should be returned, regardless of what media subtypes are supported, specify an empty string ("") or null for this parameter.
For empty string "", it works for CodecKind.Video but not for Audio (for both CodecCategory of Encoder or Decoder). If I specify a subtype, then it does not crash, for example:
var queryResult = await query.FindAllAsync(CodecKind.Audio, CodecCategory.Encoder, CodecSubtypes.AudioFormatMP3);
What is strange about that is that even though I have a try/catch with generic Exception, the app just crashes through that one and show this instead:
I have tried restarting Windows, uninstall the UWP app and make a clean build. What is happening? How do I query all available audio codecs?
Update: after changing Debug setting, I could trace the error message:
Unhandled exception at 0x00007FFDCE5FD759 (KernelBase.dll) in ******.exe: 0xC0000002: The requested operation is not implemented.
After my testing, the content of this document is correct. When I set “” for the third parameter to find all audio codecs, the code works well. So there is not an error in this document.
You could choose the Debug options, and change Debugger type from Managed Only to Mixed. It won't fix your exception, but you can trace it with the debugger. You could refer to this reply to get more information.

Trying to call third party dll from Azure Function V2 I get an exception

I strictly follow this sample: https://odetocode.com/blogs/scott/archive/2018/02/14/pdf-generation-in-azure-functions-v2.aspx
I download the three files from the DinkToPdf repository
Problem is when I add either 32bit OR 64bit DLLs, I get the following error:
One or more errors occurred. (An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B))
on this code in particular:
private static byte[] BuildPdf(string html)
{
byte[] arr = null;
try
{
arr = pdfConverter.Convert(new HtmlToPdfDocument() { Objects = { new ObjectSettings { HtmlContent = html } } });
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
}
return arr;
}
My Azure Function V2 .net Core project is set to Any CPU with no option for other. I saw other posts on Stack Overflow about this error and I feel that this is different because other people are talking about two projects that have control over and there is some differences in the architecture, but here I just point a few binaries and no matter if they are 32 or 64 the error stays. Also I saw that some people change settings of the IIS and I don't have such. Any ideas? Thanks!
One or more errors occurred. (An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B))
This error is caused by using 64 bit dll. By default, VS works with 32 bit Function CLI hence the error is expected. The bit is not the problem, we can use x64 CLI with several steps.
Problem is one tricky error Qt: Could not initialize OLE (error 80070005).
Function hangs when our html content has some javascript tags or references. See the test done by Travis. When js is removed Function returns PDF successfully but the error message persists.(I assume it doesn't matter as we get a complete PDF as expected.)
If this restriction is not acceptable, install package OpenHtmlToPdf, change your code as below. Also you can try other packages.
private static byte[] BuildPdf(string html)
{
return Pdf.From(html).Content();
}
Note that this method doesn't work in Function on Consumption plan or Free App service plan.

IMAPI: COMException Internal file system error occurred [-1062555360 ]

I am writing CD/DVD using IMAPI with C#.NET windows application.
The data I write on CD contains one executable file (test.exe) which is also developed with C#.NET and virtualized (sandobx) using Turbo Virtualization Studio.
All data to be written on CD is placed in one folder (source path) on C drive.
Following is small code snippet: -
IStream stream = null;
try
{
System.Diagnostics.Debug.Print("Adding - " + thisFileItem.SourcePath);
if (thisFileItem.SourcePath != null)
Win32.SHCreateStreamOnFile(thisFileItem.SourcePath, Win32.STGM_READ | Win32.STGM_SHARE_DENY_WRITE, ref stream);
if (stream != null)
{
fileSystemImage.Root.AddFile(thisFileItem.DestPath + thisFileItem.DisplayName, stream);
}
}
finally
{
if (stream != null)
{
Marshal.FinalReleaseComObject(stream);
}
}
Call to "fileSystemImage.Root.AddFile" method while adding test.exe throws COMException -1062555360 "Internal file system error occurred." All other files add and write properly.
Exception Details: -
COMException -1062555360
Internal file system error occurred.
at ImapiInterop.IFsiDirectoryItem.AddFile(String path, IStream fileData)
at ImapiImplementation.CDWriter.objBackgroundWorker_DoWork(Object sender, DoWorkEventArgs e) in C:\.........\CDWriter.cs:line 405
If I put my source folder on some other location (Desktop or D drive), all writing process (including test.exe) happens fine without error.
I suspect the issue is due to virutalization but not sure.
Please help.
The error message returned by IMAPI is incorrect and that is why all confusion.
Refer following link.
social.msdn.microsoft.com
Following is the text copied from answer (from Dmitri) on above site: -
IMAPI supports the ISupportErrorInfo interface, and we are aware of
the issue of mismatching error messages in your scenario.
Internally, IMAPI creates rollback objects to undo add/remove file
actions. We've had an issue where the rollback action was created
prematurely, so after the return code for IFsiDirectoryItem::AddFile
was already set, the rollback action was to remove the file from the
image. Since the file hasn't been added, IMAPI_E_FSI_INTERNAL_ERROR
exception was thrown, which changed the IErrorInfo message to the one
you're seeing.
We are aware of this issue, and it will be fixed in the next release
of IMAPI. Unfortunately, it is not serious enough to be addressed in a
hotfix.

Getting MissingMethodException when using Manatee.trello to get list of users

I have the following code which is intended to fetch a list of all the user of an organisation.
public static IEnumerable<Member> ListTrelloUsers()
{
var serializer = new ManateeSerializer();
TrelloConfiguration.Serializer = serializer;
TrelloConfiguration.Deserializer = serializer;
TrelloConfiguration.JsonFactory = new ManateeFactory();
TrelloConfiguration.RestClientProvider = new RestSharpClientProvider();
TrelloAuthorization.Default.AppKey = ApplicationKey;
TrelloAuthorization.Default.UserToken = GrandToken;
var myOrganization = Member.Me.Organizations.FirstOrDefault().Id; //Exception thrown here.
var orgToAddTo = new Organization(myOrganization);
return orgToAddTo.Members.AsEnumerable();
}
But I'm getting a
System.MissingMethodException
thrown on
RestSharp.IRestRequest RestSharp.RestRequest.AddFile(System.String, Byte[], System.String)
So why is this exception thrown and what should the correctly working code look like?
Clarifications
I will also accept working C#/ASP.Net MVC code that isn't based on Manatee.Trello as an answer. (Including pure API-calls.)
I have tried using the Organisation ID directly as
var orgToAddTo = new Organization(OrganisationId);
but that just caused the same exception to be thrown later when I make a call to the method's returned object (e.g. using Count()).
UPDATE: I tried setting the build to Release instead of Debug and now the (same) exception is instead thrown at
TrelloConfiguration.RestClientProvider = new RestSharpClientProvider();
This is an issue with RestSharp that I reported quite some time ago, though they deny that it's a problem. If you're using .Net 4.5+, you can try the Manatee.Trello.WebApi package instead of Manatee.Trello.RestSharp.
TrelloConfiguration.RestProvider = new WebApiClientProvider();
Here's my Trello card for tracking the issue. This and this are the RestSharp issues I created.
I have been able to recreate this as well, but have received no help from them to resolve it.
Apperently, the class with missing method is located in an assembly, which differ from the one, which you used while compiling the project. Double check and make sure both at compiling and at execution you use the same assembly with the aforementioned class.
That is my best clue based on the info you've provided.
basically, check project references and make sure, you use correct ones for the class-holding assembly.

C# run piece of code under different credential

Referring to THIS QUESTION I was able to execute some code as different user.
Now I'm trying to execute a piece of code as a user with administrator privileges and I get a missing file error. The code is this:
using (new Impersonator("domainAdmin", "DOMAIN", "myStup1dPa$$w0rd"))
{
GetXAApplicationByName apps = new GetXAApplicationByName();
apps.BrowserName = new string[] { "*" };
IEnumerable<XAApplication> result = CitrixRunspaceFactory.DefaultRunspace.ExecuteCommand(apps);
// other code...
}
The error is thrown at last reported line, the one starting with IEnumerable<XAApplication> and is:
FileNotFoundException not handled C:\Windows\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\System.Management.Automation.dll
I don't report code for Impersonator class, the basic schema is reported on linked question (and it worked also in other applications).
Am I missing something?
Looks like there is no problem with impersonating but your code somehow tries to load the assembly System.Management.Automation.dll which is not in GAC , can you try registering this assembly in GAC and try it out again .

Categories

Resources