using dynamic keyword with Unity 3D [duplicate] - unity3d

I am trying to implement GraphQL into Unity3D (version 2017.1.0f3 Personal). I am using .NET 4.6 (Experimental), but despite this, Unity does not support dynamic keyword. Which is odd, since .NET 4.0 it is the part of .NET. Except in Unity. I was googling for some solution how to get it work, but no solutions to the dynamic keyword. The error is this:
Severity Code Description Project File Line Suppression State
Error CS1980 Cannot define a class or member that utilizes 'dynamic'
because the compiler required type
'System.Runtime.CompilerServices.DynamicAttribute' cannot be found. Are you
missing a reference? skiing-prototype (1) D:\skiing-prototype
(1)\Assets\Scripts\GraphQL.cs 62 Active
That is the only caveat of using GraphQL C# client. Has anyone tried it yet to get it work? I hadn't found any greater efforts to get it up and running yet.
EDIT:
I am using this client here: https://github.com/bkniffler/graphql-net-client
Also this is an error from visual studio, but in Unity console it shows errors too, will update what exactly momentarily
Assets/Scripts/GraphQL.cs(80,16): error CS1980: Dynamic keyword requires
`System.Runtime.CompilerServices.DynamicAttribute' to be defined. Are you
missing System.Core.dll assembly reference?
this is the unity editor error, which seems to be the same that in visual studio

The first step is to check if Unity recognizes these 2 basic C# 6 features from MS site.
1.Try "Index Initializers" feature:
private Dictionary<int, string> webErrors = new Dictionary<int, string>
{
[404] = "Page not Found",
[302] = "Page moved, but left a forwarding address.",
[500] = "The web server can't come out to play today."
};
2. then "String Interpolation" feature:
private string FirstName = "";
private string LastName = "";
public string FullName => $"{FirstName} {LastName}";
If they give you error then the problem is not just the dynamic keyword but a problem that Visual Studio cannot recognize the .NET version being set by Unity.
From the comment section your Unity failed to compile the first example.
Go through the steps one by one for a possible fix. Do not skip of them.
1.Go to Edit --> Project Settings --> Player --> Other Settings --> Configuration --> Scripting Runtime Version --> Experimental (.Net 4.6 Equivalent).
2.Go to Edit --> Project Settings --> Player --> Other Settings --> Configuration --> Api Compatibility Level --> .NET 4.6
3.Restart Unity Editor and Visual Studio. You must restart both.
Test both C# features above. If they work then the dynamic keyword should as-well. If they don't then move on to #4.
4.Update Visual Studio. This is very important. Update the visual Studio to the latest version/patch.
5.If you can't still get both C#6 features above to compile then Re-install both Visual Studio and Unity then perform step #1 and #2 again as some files are missing.
6.Finally, if you get both C#6 features working but the dynamic keyword is still not working then update from Unity 2017.1 to Unity 2017.2. This version fixed many .NET issues.
Note that I am using Unity 2017.2 with the dynamic keyword without any issue. Also, GraphQL is working fine.

I seem to have found a solution
Navigate to Edit > Project Settings > Player > Other Settings > Configuration > API Compatibility Level and change from .NET Standard 2.0 to .NET 4.x
This immediately removed the compiler error and allowed me to run code using the dynamic keyword.
Let me know if that was useful

Related

Compiler Problems on MAUI RC1

I have an app that I started using the out of the box MAUI project template. I have been running it on both a local Android emulator and a remote Mac emulator. It had been working on both, and then today after running it on Android for a while, I changed the debugger to use the Mac emulator. It immediately refused to compile, and listed every Android class reference as "type or namespace [blah] could not be found". After playing with several things, I found that if I commented out the "using Java.Net" on the default MainPage.xaml.cs, all of the compiler errors went away. If I uncomment it again, then all 20 something compiler errors show up again. This is the out of the box MainPage.xaml that came with the project template, plus one click event handler that I added - is there some known issue here?
As I said, it was working fine for nearly two weeks, and then just went bananas on me today. Haven't added any nuget packages or anything like that - just been writing code.
Thanks.
You've described the issue in your question:
using "Java.Net" on the default MainPage.xaml.cs.
That won't compile for any platform except Android.
It doesn't exist on the default MainPage.xaml.cs (which you could have verified by creating a new project).
My recommendation: Start over with a fresh project. Add again whatever you added, and see if that using appears again. If it does, you've added something Android specific. Which doesn't make sense, on a cross-platform page.
If using does appear again, and you don't understand why, then add to your question the exact code which, when added to page, causes using Java.net; to appear.
If you were following some example, also add a link to the example web page.
UPDATE
I have a theory about how that using got there:
I bet you added a reference to some class which exists in Java.net namespace.
So Visual Studio gave you an option to add a "using".
If that happens again, and a "using" mentions Android or Java, DON'T add the using, UNLESS you are in a file inside your project's Platforms/Android folder.
Some class names exist both in an Android or Java namespace, and in a .Net or Maui namespace. In cross-platform code, pick the cross-platform using, not the platform-specific one. If they are in different namespaces, they are different classes - even if the names are the same.

HoloLens2 Application made with unity throws Exception "Could not create a device for ''Hand - Right (XRInputV1)"

Since I updated my HoloLens2 Unity Project to Unity 2020.3 my deployed HoloLens2-Application (in Unity Editor they never happen) always throws the following Exceptions :
Could not create a device for 'Hand - Right (XRInputV1)'
(Exception: System.ArgumentException: Expected control positionAccuracy to be of type 'AxisControl' but is of type 'IntegerControl' instead;)
at UnityEngine.InputSystem.InputControll
Could not create a device for 'Hand - Left (XRInputV1)'
(Exception: System.ArgumentException: Expected control positionAccuracy to be of type 'AxisControl' but is of type 'IntegerControl' instead;)
at UnityEngine.InputSystem.InputControll
Does anybody know, how to get rid of those Exceptions?
I am using the MixedRealityToolkit 2.7.3 HoloLens2 default Configuration and noticed this problem at Unity Versions 2020.3.8, 2020.3.22 and 2020.3.26.
Firstly, please double check the MRTK Input profile setting. You can easily configure the project in Unity Menu: Mixed Reality > Toolkit > Utilities > Configure Project for MRTK
Then, please check out your XR setting, Since you are using Unity 2020.x, you can use OpenXR plugin, see Choosing an XR configuration.
If the issue is still there, this may also be caused by your hand control code. Here is discussion with the same exception as yours, see WikkidEdd's reply in this github issue. In their case, they need to use IntegerControl instead of AxisControl.
OK I fixed the Error-Problem by updating to OpenXR plugin. It fixed basically every problem I had so far within my project. By coincidence I came across the plugin as a tarball file while downloading this sample-project from Github.
I´d wish to find a place where I can get all the plugins which can be installed via Microsoft FeatureTool on one place as manual download! Maybe someday it will exist. :)

Team Foundation Servcices (TFS) Diff tool not working

Our team is migrating our tfs build to vNext. There is a new capability that automatically version controls the build definitions, which can be seen in the History Tab (see below). I am trying to view differences between versions of the build definition using the "Diff tool". I keep getting a mixed content error when trying to look at the differences between build definitions. I tried in IE and Chrome and am getting the same error. I also allowed mixed content in IE with no luck. Anyone has a workaround? Thanks.

Project referencing Portable Class Library gives error in Visual Studio Code

I create a console application in Visual Studio 2015 RC and add Automapper 3.3.1 using nuget to the project.
If I then add the following snippet to my project:
public class Class1
{
public void Test()
{
AutoMapper.Mapper.Map<B>(new A());
}
}
And then open the same project in Visual Studio Code preview on Windows 10 then I get a red squiggly on the Map function.
The error message says:
The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'.
My project is configured to use .NET 4.52 and there are absolutely no errors or warnings when building the same project using visual studio 2015 RC or using MSBuild from the command line.
Automapper is portable class library and this is what seems to trigger the problem.
Is this a known issue with Visual Studio Code or Omnisharp?
Are there any way to suppress these error messages?
Update:
I have now tested with VS Code version 0.3 and it is still not fixed.
To make it even simpler to reproduce I have also verified that the problem also exist for a ClassLibrary project containing only the 3 classes: Class1 as shown and class A and class B, which are just two dummy classes used to have something to map.
It does not matter which version of Visual Studio is used to create the project. The same problem exist if I create the class library project using VS 2013.
Maybe you added the reference in both dnx451 and dnxcore50 in project.json file.
I think the problem is Automapper did not support .NET Core 5.0, please refer this article for more detail about .NET core 5.0 and .NET framework 4.6.
http://blogs.msdn.com/b/cesardelatorre/archive/2014/11/18/what-is-net-core-5-and-asp-net-5-within-net-2015-preview.aspx.
This might be the limitation of multi-environment in .NET Core 5.0 when using available libraries. You should write by yourself or waiting for other libraries update if you want to use, otherwise, please remove dnxcore50 in project.json.
Happy coding!
This is actually a known issue with the OmniSharp-roslyn server which powers VS Code, see: https://github.com/OmniSharp/omnisharp-roslyn/issues/265
I suspect you might have better luck using the yeoman ASP.NET 5 generator to generate an ASP.NET 5 Console application.
See: http://docs.asp.net/en/latest/client-side/yeoman.html
And http://docs.asp.net/en/latest/dnx/console.html

Eclipse #ifdef error using JNI, Android NDK and Vuforia

With Vuforia's ImageTargets sample application, I tried using OpenGL ES 1.1 by setting USE_OPENGL_ES_1_1 to true in jni/Android.mk and uncommenting and changing the corresponding line in AndroidManifest.xml (). After converting the project so that it has a C++ perspective and associating ndk-build and the proper include directories, I could successfully run the application on my Android device.
However, the problem is that once I open up jni/ImageTargets.cpp, I get several errors from Eclipse, all from places where OpenGL ES 2.0 code would execute, the first one being:
Description Resource Path Location Type Symbol 'vertexHandle' could
not be resolved ImageTargets.cpp /ImageTargets/jni line 402 Semantic
Error
Sure enough, vertexHandle is defined at the top of the ImageTargets.cpp, inside the "#ifdef USE_OPENGL_ES_2_0" block. Because USE_OPENGL_ES_2_0 is not defined (per Android.mk), the code should be able to compile successfully, and sure enough, ndk-build does not report any problems. So it seems that only Eclipse reports the problems and when I run the project, Eclipse says, "Your project contains error(s), please fix them before running your application." And thus, I cannot run my application anymore. In a sense, it's kind of strange that this never occurred until I opened ImageTargets.cpp and Eclipse "discovered" the errors.
The best work-around I've found so far is to just delete or comment out those lines (that should not be causing problems because USE_OPENGL_ES_2_0 is not supposed to be defined)... Is there a better way to deal with this problem? Did I miss a setting in Eclipse that should solve this?
I've found a solution: go to the project properties -> C/C++ Build -> Discovery Options -> Check "Automate discovery of paths and symbols"