Unity Hololens (UWP) build generates errors that Standalone builds do not? - c#

Alternative titles:
Unity References Bug for Hololens Windows UWP Builds (10.0.10586.0)?
or..... Unity Hololens Builds have access to Standalone Build DLL references?
Quick pre-text: I'm designing an app to run on the Hololens. The game plays perfectly fine inside of Unity. It builds perfectly fine to the PC, Mac & Linux Standalone platforms without error.
However, errors from "missing" references arise when building to the Windows Store platform. (Missing is in quotes because I've thoroughly checked and rechecked that I'm using the right references and that they are located where they should be).
Initial error on trying to build is:
Error building Player because scripts had compiler errors
error: The type or namespace name 'FileSystemEventArgs' could not be found (are you missing a using directive or an assembly reference?)
private void PrototypeFileWatcher_Created(object sender, FileSystemEventArgs e)
{
...
}
When this error is corrected by commenting out the aforementioned function and associated code, and building is attempted again, these errors come forth:
error: The name 'Console' does not exist in the current context
catch (Exception e)
{
Console.WriteLine(e.Message);
}
error: Argument 1: cannot convert from 'string' to 'System.IO.Stream'
using (StreamReader sr = new StreamReader(path))
{
...
}
error: The type or namespace name 'BufferedStream' could not be found (are you missing a using directive or an assembly reference?)
using (BufferedStream bs0 = new BufferedStream(f0))
{
...
}
References are stored at the appropriate location:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Unity Full v3.5\System.Core.dll
References are listed in the heading of the scripts:
using UnityEngine;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Threading;
With all that said. I've tried:
-Changing Api Compatibility Level*
-Changing the project solutions net framework
-#if NETFX_CORE using x = WinRTLegacy.x; #else
-#if WINDOWS_UWP using System; #endif
-Trashing the project entirely and rebuilding from scratch
-And lots more
Struggling with this issue for over a full day now. I've NuGet pkgs, VS tools for Unity (otherwise known as VSTU), I'm using VS2015.
I'm at a complete loss right now. I'm not understanding if I can't build this to the Windows Store Platform as it can't use some of the DLLs that Unity standalone builds can?

HoloLens applications are constrained to using only what is a available in a UWP app. Some things will work in the Unity editor that do not work in a HoloLens Applications because the unity editor builds with mono instead of .net. You should constrain yourself to just things that work in UWP and they will work fine within the editor as well. Even the full set of UWP API's are not yet available to work with on HoloLens.
The full documentation for UWP is here:
https://learn.microsoft.com/en-us/uwp/api/
The subset added specifically for HoloLens is at the bottom of this page:
https://developer.microsoft.com/en-us/windows/mixed-reality/development
Unfortunately there isn't a place that highlights what isn't available. The Visual Studio compiler will help you understand what is there and what is not.

Related

Namespace name "Device" does not exist in the namespace

I have a problem using System.Device and can't find a solution
I'm developing a software and want to get the position of the device. By referencing the .NET Framework I want to use the GeoCoordinateWatcher.
In my code I included System.Device.Location and added two packages to the project (GeoCoordinate and System.Device.Location.Portable). While running and debugging the code in monodevelop no error occurs, but when I compile the code with mcs the error mentioned in the title occurs:
Namespace name "Device" does not exist in the namespace
Im using a RasPi for coding and compiling.
Any idea what the problem is?
System.Device is not supported by Mono:
https://github.com/mono/mono/tree/master/mcs/class

C#/.net Unable to use bitmap with "using System.Drawing" and reference to System.Drawing [duplicate]

Ok, so I'm on this bug for the last 4 hours and I dont know what to do..
I'm using Visual Studio Community 2017 and I opened Consol App(.net core) project. also I'm working on windows 8.1 OS.
I wanted to use Image from the System.Drawing namespace and it keeps giving me that error:
"the type or namespace name 'Image' could not be found (are you missing a using directive or an assembly reference?)"
I downloaded the System.Drawing.dll from https://www.dllme.com/dll/files/system_drawing_dll.html
(to the desktop) and then right click on the right project->add->Reference..->Browse..->System.Drawing.dll->OK
then I saw in the project (in the Solution Explorer) in the project dependencies->Assemblies->System.Drawing so I guess it works right?!
I'm still getting the same error and can't use the System.Drawing namespace, any suggestions?
using System;
using System.Net.Sockets;
using System.Drawing;
namespace client2
{
class Program
{
static void Main(string[] args)
{
try
{
//read image
Image image = new Image("C:\\image\\amir.jpg");
}
}
}
}
System.Drawing is not part of the cross-platform parts of .NET (Core). It depends on GDI+ which is part of Windows. There are plenty of alternatives out there.
Aside: Never download DLLs from an untrusted source.

can't add System.Drawing.dll reference

Ok, so I'm on this bug for the last 4 hours and I dont know what to do..
I'm using Visual Studio Community 2017 and I opened Consol App(.net core) project. also I'm working on windows 8.1 OS.
I wanted to use Image from the System.Drawing namespace and it keeps giving me that error:
"the type or namespace name 'Image' could not be found (are you missing a using directive or an assembly reference?)"
I downloaded the System.Drawing.dll from https://www.dllme.com/dll/files/system_drawing_dll.html
(to the desktop) and then right click on the right project->add->Reference..->Browse..->System.Drawing.dll->OK
then I saw in the project (in the Solution Explorer) in the project dependencies->Assemblies->System.Drawing so I guess it works right?!
I'm still getting the same error and can't use the System.Drawing namespace, any suggestions?
using System;
using System.Net.Sockets;
using System.Drawing;
namespace client2
{
class Program
{
static void Main(string[] args)
{
try
{
//read image
Image image = new Image("C:\\image\\amir.jpg");
}
}
}
}
System.Drawing is not part of the cross-platform parts of .NET (Core). It depends on GDI+ which is part of Windows. There are plenty of alternatives out there.
Aside: Never download DLLs from an untrusted source.

Cannot access Interface defined in the Code Sharing Project from within UWP project

I am just a newbie in Xamarin, so I tried creating the simple Phoneword application available at Xamarin on-line guides.
The solution created in Visual Studio comprises 4 distinct Projects:
A portable class library (PCL) project that holds all of the shared code
A project that holds Android specific code
A project that holds iOS specific code
A project that holds Universal Windows Platform (UWP) specific code
This is how the solution structure looks like:
Now inside the first project an interface has been declared:
namespace Phoneword
{
public interface IDialer
{
bool Dial(string number);
}
}
I now try to use this interface from within the UWP project:
using Phoneword.UWP;
using System;
using System.Threading.Tasks;
using Windows.ApplicationModel.Calls;
using Windows.UI.Popups;
using Xamarin.Forms;
[assembly: Dependency(typeof(PhoneDialer))]
namespace Phoneword.UWP
{
public class PhoneDialer : IDialer
{
...
Building the solution ends successfully. But when I try to Deploy
the UWP project I get this error:
The type or namespace name 'IDialer' could not be found (are you
missing a using directive or an assembly reference?)
Can anyone give me hint on what could be the source of this error?
Update
There was one more error I was getting when I tried to deploy:
Error DEP0700: Registration of the app failed. [0x80070005] error
0x80070005: Opening file from location: AppxManifest.xml failed with
error: Access is denied.
I closed the solution, exited Visual Studio started and loaded again and the first error disappeared. So, it seems, there is nothing wrong in consuming an interface, declared in the Code Sharing Project, from within the UWP Project.
The actual error I was getting was due to access rights restrictions of the folder were the project was being deployed.
You are not referencing the Phoneword in your PhoneDialer.cs file. Add this to the top:
using Phoneword; // <== Add this
using Phoneword.UWP;
using System;
using System.Threading.Tasks;
using Windows.ApplicationModel.Calls;
using Windows.UI.Popups;
using Xamarin.Forms;
I had a similar issue. The way to fix it is just to restart Visual Studio or reload the solution.
I had the same problem, Add this to your code at the top
using static Phoneword.MainPage;
and it should work fine
The reason it was not working is because you didn't have a reference to it. For some reason the Assets that you import for that course do not have this reference in it.
Had the same problem.
You need to right click on the Phoneword project in the Solution Explorer and click build to build it on it's own.
Then add the using statement for the Phoneword project to your PhoneDialer file.
The reference to IDialer then becomes available.

Creating a shared library (.NET Assembly) in Matlab and using it in C#

I've created a .NET assembly in Matlab (2014a) using the Application Compiler, and I'm trying to use it under C#.
The matlab module has only 1 function:
function [ val ] = AnalyzePicture( arg1 )
val = 5;
end
The exported .NET DLL is named AnalyzePicture.dll and exports Class1 (as defined in the Matlab application compiler).
However, when I try to initialize it, I get an exception saying:
The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWArray' threw an exception
With the inner exception saying:
An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
Here's the code
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AnalyzePicture;
using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;
namespace Analyzer
{
public class MatlabWrapper
{
AnalyzePicture.Class1 analyzer = null;
public MatlabWrapper()
{
try
{
// The exception is raised here
analyzer = new AnalyzePicture.Class1();
}
catch (System.Exception ex)
{
MessageBox.Show("f");
}
}
...
My project references MWArray (8.3, the current version) and the AnalyzePicture dll (and DirectShowLib-2010).
I tried to find solutions online but i couldn't find a decent example on how to properly use a Matlab .NET Assembly in C#. I did exactly as described in this article besides that my assembly does not start with com.
Any ideas on what could be causing the problem?
Any code examples will be greatly appriciated
(I'm using Windows 7 64bit, with Matlab 2014a 8.3 64bit)
Just in case someone else will encounter the same issue.
I had this problem some time ago, so I figured out complete solution to this.
You need to set project settings to use .Net Framework 4.0 (instead of 4.5 VS 2013 sets as default version) and change target platform to x64. This set works beautifully on Win 8.1 (x64), MatLab R2013a (x64, runtime version 8.1) and Visual Studio 2013.
IF you published matlab 64 bit dll , Change your VS Project Build Settings Any CPU and uncheck the "Prefer 32-Bit" property

Categories