Answered by:

WinRT does not support #using of a managed assembly

Question

Hello I am trying to read text from .txt file and print it to textbox, but I cant... It stops at marshal_as... This is Visual Studio 2013 -> Windows Store application

1 error C1114: 'c:\windows\microsoft.net\framework\v4.0.30319\mscorlib.dll' : WinRT does not support #using of a managed assembly2 IntelliSense: an ordinary pointer to a C++/CX mapping ref class or interface class is not allowed

If anyone know how to fix this or any other method for reading .txt file please tell me...

All replies

C++/Cx is not a managed language and so cannot directly call managed assemblies. If your managed assembly is valid for Windows Store apps you can wrap it in a Windows Runtime Component and reference the component instead

I'm on my phone and can't get a link, but you should be able to find it by searching for "Windows Runtime Componeny" in the search box at the top right of the page. Also check out the App Architecture links.

Hey, I tried with example 5 and used code below... This one executes else statement and print "Does not exist"... I think something is wrong with path or file != nullptr in if statement... But still don't know how to fix it...

Your app doesn't have permission to read from the desktop. You can read files outside of the app's install and data directories only with user permission, either through declared capabilities or explicitly from the file picker.

In VS 2013, in Solution Explorer, first make sure that the "test.txt" file is included in the project. Then, in Solution Explorer, right-click on test.txt and choose "Properties". In the text.txt properties, change the Configuration to "All Configurations"
and the Platform to "All Platforms", then for "Content" make sure it is "Yes" and for "Item Type" make sure it is "Text" ("Excluded From Build" should be either blank or set to "No". Click on Apply then click on OK.

Now Rebuild the project in "Debug" configuration for "Win32" (you can set these either from the drop down menus in the toolbar area or by choosing "Configuration Manager" from the "BUILD" menu). When that is done, open up the root folder of the solution
(where the .sln file is). There should be a folder there called "Debug". Open that. Inside "Debug" should be a folder with the name of your app. Open that folder and then open the folder called "AppX" that is inside the app folder. Verify that "test.txt" is
there (this should be the same folder that the .exe file for your app is in so if you don't see your app's exe then you need to make sure your project was successfully built and then try "Rebuild Solution" in the "BUILD" menu).

Try running your app now. It should work. If not, try going to the Start Screen, finding your app in the All Apps section, right clicking it, and uninstalling it. Then go back to Visual Studio and try debugging it again so that it deploys the updated version.
That should work. If not, make sure you followed all the steps above and if so, report back.

Like Mike says, make sure that the text.txt file is actually getting packaged and installed with the app. It needs to be marked as Content and to copy to the output directory. Check for it in the created appxpackage to make sure it's there. Look for a directory
%project%\bin\debug\Appx

1. How is copy/paste working with Windows Store apps... I would like to read a text outside of app folder but because of restrictions I can't... So I tought maybe I could copy file which is outside of app folder and paste it into app folder and then read
it... Is that possible or there are restrictions about that as well???

2. Can I GetFile even if I don't know the full name of that file??? That file is made of date.filename... Date = is changing, filename = is permanent... So could I somehow set it to find just part of the file name and open it??? To search only for filename???
Example: 25-10-2013.myfile.txt -> Can I make it somehow recognize file only by myfile.txt and open/read/copy it???

1. I'm not sure what you mean. Copy/Paste is a user gesture that isn't available to apps. Can you create a new thread for the new topic and explain what you mean in more detail? If you mean to programmatically copy a file from one directory to another then
you can do that with StorageFile::CopyAsync(IStorageFolder) so long a the app has appropriate permissions to read the original file and to write to the target folder.

2. Not directly. You could query the file names and then examine the results to find the one you want, then open that file.