How to show PDF from .net maui app on Windows - maui

I am just trying to show a PDF file from my .NET MAUI application on Windows and it is giving me the error below.
"System.ComponentModel.Win32Exception: 'An error occurred trying to start process 'C:\Users<username>\Documents\helpfile.pdf' with working directory 'C:\WINDOWS\system32'. The specified executable is not a valid application for this OS platform.'"
My code is below. It has worked in a WPF app but won't work here.
Process.Start("C:\\Users\\<username>\\Documents\\helpfile.pdf"); // removed the username here and above in error message
also tried: (getting helpfile.pdf from install directory)
string _asmPath = Assembly.GetExecutingAssembly().Location;
int lastIndex = _asmPath.LastIndexOf('\\');
string helpfilePath = $"{_asmPath.Substring(0, lastIndex)}\\helpfile.pdf";
ProcessStartInfo startInfo = new ProcessStartInfo(helpfilePath);
Process.Start(startInfo);
and I get a similar error:
"System.ComponentModel.Win32Exception: 'An error occurred trying to start process 'C:\Projects\SnapSignalTel\bin\Debug\net6.0-windows10.0.19041.0\win10-x64\AppX\helpfile.pdf' with working directory 'C:\WINDOWS\system32'. The specified executable is not a valid application for this OS platform.'"
How can I open this PDF document (helpfile.pdf) in a MAUI app on Win10?
Thanks for any help!

use Launcher
await Launcher.Default.OpenAsync(new OpenFileRequest("Some Title", new ReadOnlyFile(filepath)));

Related

Trouble reading file in xcode command line app

I am having trouble reading a file within a command line tool project in Xcode 11.6.
Steps:
Create a new command line tool project using the template in the mac os section.
In main.swift:
import Foundation
let fileURL = URL( fileURLWithPath: "/Users/ausom4/Desktop/myTest.txt" )
var rawDataString: String
var errorString: String?
do {
rawDataString = try String( contentsOf: fileURL, encoding: .utf8 )
print(rawDataString)
} catch let error as NSError {
errorString = error.description
rawDataString = ""
print(rawDataString)
}
This will build successfully in Xcode however will always print a null string in the console.
However if I go to the location of my product in terminal and run the build I get the contents of the file.
I do not have sandboxing enabled. Sandboxing is also not enabled by default in this xcode template. I have also given xcode full disk access.
I can run this code in a playground.
What could be the issue here?
It is not sandbox - it is macOS Security & Privacy system.
On first launch you had to get alert asking something like “TestFileReading” would like to access files in your Desktop folder. so you grand access for this application.
If you did not grant access then (or for some reason macOS forgot to ask that) there is possibility to grant access manually in System Preferences at any time:
With all this passed your code snippet works as expected - tested with Xcode 12 / macOS 10.15.6

Vs Code : Error: could not open `C:\Users\folder-name'

I was trying to implement a Spring boot application on vs code and came up with this error when I tried to run the code (Screenshot below). I am not clear what this error indicates and did not know what exactly to look for on the internet. could anyone tell me how I can resolve this error?
edit:
as I was told to copy-paste the error message as text, here it is.
PS D:\study material\java code\springbootdemo> cd 'd:\study material\java code\springbootdemo'; & 'c:\Users\manjeet arneja\.vscode\extensions\vscjava.vscode-java-debug-0.27.0\scripts\launcher.bat' 'C:\Program Files\AdoptOpenJDK\jdk-11.0.6.10-hotspot\bin\java.exe' '-Dfile.encoding=UTF-8' '#C:\Users\manjeet' 'arneja\AppData\Local\Temp\cp_9w87n9v9bnokxm9i3k10qtvnm.argfile' 'com.explore.springbootdemo.DemoApplication'
Error: could not open `C:\Users\manjeet'

Internal /bin/cp command failed. xCode compiler error

I'm working in Xcode trying to build a simple calendar app. As I tried to build and run I get this error
/Users/Zach/Downloads/Xcode-beta.app/COnonts/Developer/Toolchains/XcodeDefault.xctoolchain/
usr/bin/bitcode_strip: internal /bin/cp command failed.
Task Failed with exit 1 signal 0 {
All I know is that it gives me the error when this line is typed... It goes away when I comment it out.
let ce = NSKeyedUnarchiver.unarchiveObject(with: eventObject as Data) as! CalenderEvent
UPDATE:
I just tried to recompile and was given a new error.
"libswiftCore.dylib" couldn't be copied to "(A Document Being Saved BY Xcode)".
It appears like something is wrong with the swift std library. It randomly switches between the two errors.
I get this same error when I run low on disk space. Try moving the project to a different location, with more space, clean the project, and re-build.

Warning: DOMDocument::load() [domdocument.load]: I/O warning : failed to load external entity

I was using this piece of php script in a application running under over XAMPP on my local machine:
$dom = new DomDocument();
$filename = "library.xml";
if (!$dom->load($filename))
die("Could not parse iTunes XML file: ".$filename);
Then i tried to move this application to a WampServer without success, with the following warning:
Warning: DOMDocument::load() [domdocument.load]: I/O warning : failed to load external entity "file:///C:/wamp/www/parser/library.xml" in C:\wamp\www\parser\includes\libs\itunes_xml_parser.lib.php on line 111
This line in the error is exactly the load line, which worked flawlessly in earlier versions of XAMPP and isn't working now on XAMPP 1.7.7
As per this why don't you try using an absolute path for your filepath.
Also i see that this php file is located at C:\wamp\www\parser\includes\libs and library.xml is being searched at C:/wamp/www/parser/. Is this correct?
It could also be possible that you had turned off warnings/errors in your earlier xampp installation.So check this also.

How to create NTEventlogAppender.dll as required for logging event in the eventlog using log4cplus

First, Let me thank for the log4cplus source code.
I am facing one issue as follows:
What I am trying to do?
I want to log the messages to event log on windows.
What did I do?
I could get the event logging enabled by in including following .h
#include <log4cplus/nteventlogappender.h>
And creating the appender as follows:
SharedAppenderPtr append_3(new NTEventLogAppender(LOG4CPLUS_TEXT("127.0.0.1"), LOG4CPLUS_TEXT("log"), LOG4CPLUS_TEXT("source")));
append_3->setName(LOG4CPLUS_TEXT("ToEventlog"));
Logger to_eventlog = Logger::getInstance(LOG4CPLUS_TEXT("to_eventlog"));
to_eventlog.addAppender(append_3);
to_eventlog.setLogLevel(log4cplus::ALL_LOG_LEVEL);
And logging as
Logger to_eventlog = Logger::getInstance(LOG4CPLUS_TEXT("to_eventlog"));
LOG4CPLUS_FATAL(to_eventlog, “Test Message.”);
When I log the message, I get following in the event log:
The description for Event ID 4096 from source source cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.
If the event originated on another computer, the display information had to be saved with the event.
The following information was included with the event:
Test Message.
the message resource is present but the message is not found in the string/message table
I tried to create a dll with name NTEventLogAppender.dll with string table resource and a string with id 4096 (as hardcoded in the nteventlogappender.cxx file in log4cplus) and compiled it with resource only dll (/NOENTRY) but I still keep getting above error.
I already tried question to log4cplus-devel#lists.sourceforge.net but did not get any answer yet.
Any help on how to create this dll would be greatly appreciated.
Thanks.
This is how I resolved this issue:
comipiled NTEventLogAppender.mc file using commands:
mc -U NTEventLogAppender.mc
rc -r NTEventLogAppender.rc
link -dll -noentry -out:NTEventLogAppender.dll NTEventLogAppender.res
where NTEventLogAppender.mc has following contents
MessageIdTypedef=DWORD
SeverityNames=(Success=0x0:STATUS_SEVERITY_SUCCESS
Informational=0x1:STATUS_SEVERITY_INFORMATIONAL
Warning=0x2:STATUS_SEVERITY_WARNING
Error=0x3:STATUS_SEVERITY_ERROR
)
FacilityNames=(System=0x0:FACILITY_SYSTEM
Runtime=0x2:FACILITY_RUNTIME
Stubs=0x3:FACILITY_STUBS
Io=0x4:FACILITY_IO_ERROR_CODE
)
LanguageNames=(English=0x409:MSG00409)
; // The following are message definitions.
MessageId=0x1000
SymbolicName=SVC_TEST
Language=English
A message for something.
.
; // A message file must end with a period on its own line
; // followed by a blank line.
copied the NTEventLogAppender.dll to c:\windows\system32
and ran the above mentioned test program and found that event log found the message resource correctly.
you need to register this dll by copying following in .reg file and running the same
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\log\source]
"EventMessageFile"="C:\\windows\\system32\\NTEventLogAppender.dll"
"CategoryMessageFile"="C:\\windows\\system32\\NTEventLogAppender.dll"
"TypesSupported"=dword:00000007
"CategoryCount"=dword:00000005