locked
Loading XML file from Application storage

    Question

  • It's a simple task, but it seems so difficult with C++. I'm just trying to load some XML content into an instance of  XmlDocument. The code below compiles, but when I run it I get the error  "An invalid parameter was passed to a function that considers invalid parameters fatal".

    	Uri^ u = ref new Uri("ms-appx:///Assets/Data/XMLData.xml");
    
    	auto task = create_task([u]
    	{
    		return XmlDocument::LoadFromUriAsync(u);
    	});
    
    	this->Catalog = task.get();

    Tuesday, October 09, 2012 3:14 AM

Answers

  •  I ended up using the synchronous file I/O code from the MarbleMaze project to load my configuration data. In hindsight, it did not make any sense to use async routines to do a one time loading of data. I'm sure async is fine and all, but sometimes its more hassle then it's worth.

    Wednesday, October 10, 2012 3:16 AM

All replies

  •  I ended up using the synchronous file I/O code from the MarbleMaze project to load my configuration data. In hindsight, it did not make any sense to use async routines to do a one time loading of data. I'm sure async is fine and all, but sometimes its more hassle then it's worth.

    Wednesday, October 10, 2012 3:16 AM
  • I had a try at figuring out what went wrong with the LoadFromUriAsync, but failed.  It sure would be nice if the "

    An invalid parameter was passed to a function that considers invalid parameters fatal

    message could communicate exactly which function reported the error.  But I have some new information anyhow.  I was able to use async to get a XML document, but not going directly from URI to XMLDocument.

    void BlankApp::MainPage::FetchUriClick(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
    {
    	using namespace concurrency;
    	using namespace Windows::Data::Xml::Dom;
    	using namespace Windows::Storage;
    
    	auto uri= ref new Windows::Foundation::Uri( L"ms-appx:///MainPage.xaml" );
    	bool generateError= true;
    
    	if ( generateError ) {
    
    		// Attempt to get a XMLDocument directly from the URI.
    		//
    		// This logic gives the error: Unhandled exception at 0x5DC18AE3 (msvcr110d.dll) in BlankApp.exe:
    		// An invalid parameter was passed to a function that considers invalid parameters fatal
    		// CAll Stack
    		//		msvcr110d.dll!_invoke_watson(const wchar_t * pszExpression, const wchar_t * pszFunction, const wchar_t * pszFile, unsigned int nLine, unsigned int pReserved) Line 131	C++
    		//		vccorlib110d.dll!__abi_FailFast() Line 18	C++
     		//		BlankApp.exe!?__abi_Windows_Foundation_?$AsyncOperationCompletedHandler@P$AAVXmlDocument@Dom@Xml@Data@Windows@@___abi_IDelegate____abi_Invoke@?Q__abi_IDelegate@?$AsyncOperationCompletedHandler@P$AAVXmlDocument@Dom@Xml@Data@Windows@@@Foundation@Windows@@234@U$AAGJP$AAU?$IAsyncOperation@P$AAVXmlDocument@Dom@Xml@Data@Windows@@@34@W4AsyncStatus@34@@Z(Windows::Foundation::IAsyncOperation<Windows::Data::Xml::Dom::XmlDocument ^> ^ __param0, Windows::Foundation::AsyncStatus __param1)	C++
    		//
    		task< XmlDocument ^ > getDocTask ( XmlDocument::LoadFromUriAsync( uri ) ); 
    		getDocTask.then( [] ( XmlDocument^ xmlDoc ) 
    		{	
    			Platform::String ^ nodeName= xmlDoc->NodeName;
    		});
    
    
    	} else {
    		// This logic works, even though it also reads the MainPage.xaml as a XML file.
    		// The difference is that it gets a StorageFile from the URI, 
    		// and then gets a XMLDocument from the StorageFile.
    		//
    
    		task< StorageFile ^ > getStorageTask ( StorageFile::GetFileFromApplicationUriAsync( uri ) ); 
    		getStorageTask.then( [] ( StorageFile ^ storageFile ) 
    		{	
    			Platform::String ^ name= storageFile->DisplayName;
    				
    			task< XmlDocument ^ > getDocTask ( XmlDocument::LoadFromFileAsync( storageFile ) ); 
    			getDocTask.then( [] ( XmlDocument^ xmlDoc ) 
    				{	
    					Platform::String ^ nodeName= xmlDoc->NodeName;
    				}
    			);
    
    		});
    
    
    	}

    If generateError is false, I can break and see:    nodeName 0x03620d58 L"#document" Platform::String ^

    So the results are still unexplained.  But I suspect it has something [This seems rather JavaScript specific though] to do with the discussion at

    http://msdn.microsoft.com/en-us/library/windows/apps/hh781215.aspx which says:

    "Use the "ms-appdata:" scheme to refer to app data or one of the other schemes described in the previous section to refer to packaged resources. You can't reference resources that aren't app data or packaged resources unless you obtain an IStorageItem and then use URL.createObjectURL to obtain a URL."   

    and

    "App data

    Sometimes it is useful to refer to resources you have downloaded from the Internet to your app’s local ApplicationData storage (via Windows Runtime APIs). To refer to such content, you must use the scheme "ms-appdata:", with the path to the file within your ApplicationData local storage. Note that, for security reasons, you cannot navigate to HTML you have downloaded to this location and you cannot run any executable or potentially executable code, such as script or CSS. It is intended for media such as images or videos and the like. "

    • Edited by Andrew7Webb Wednesday, October 10, 2012 3:26 PM
    Wednesday, October 10, 2012 1:38 PM
  • This is still not fixed in Win 8.1 The XmlDocument cannot handle ms-appx URI. It should clearly state that in the docs!
    Thursday, February 20, 2014 3:09 PM