How do I reference another project in a Unity C# script - c#

Hi I have some C# code in a .NET class library that I wrote a while back. If I want to reference that code in a Unity script (Unity 2018.4.19f1 if that matters), how do I go about that?
If I add a project reference to my Unity Assembly-CSharp project in Visual Studio, it doesn't seem to work. I get;
Script.cs(3,7): error CS0246: The type or namespace name
'other-project-namespace' could not be found (are you missing a using
directive or an assembly reference?)
Does the class .NET class library need to be target a particular framework/platform? Ideally I'd like to use the same library across platforms if possible.

you need to build it, then it gave you a DLL file
import that in unity and use it

Related

error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)

I am trying to go through this tutorial for on making sounds with waves using C#:
https://www.codeguru.com/dotnet/making-sounds-with-waves-using-c/
The first sample code it has you run is this, which is supposed to play a .wav file:
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.Devices;
namespace MyApp
{
class Program
{
static Audio myAudio = new Audio();
static void Main()
{
myAudio.Play("m:\\crooner2.wav",
AudioPlayMode.WaitToComplete);
}
}
}
In my code, the filepath and name of the .wav file was replaced with a different one, but otherwise the code is identical. However, I get an error regarding the second line of code: error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)
Without the Microsoft.VisualBasic.Devices call working, I have no way of running even the first exercise in the tutorial, and definitely no way of further progressing in using C# for sound manipulation.
I was expecting the code to run and play the .wav file. However, I got the error message instead.
As part of debugging, I came across this post on the Microsoft website:
https://learn.microsoft.com/en-us/dotnet/core/compatibility/visualbasic#types-in-microsoftvisualbasicdevices-namespace-not-available
I'm not sure what to make of it. It seems like it's saying it could be solved by upgrading to .Net 5 or higher, but I'm already using .Net 5. It also seems like it saying that Microsoft.VisualBasic.Devices was made obsolete with .Net Core 3.0, so I'm not sure how upgrading would make it easier to use something that was made obsolete.
It also says that certain functionality in Microsoft.VisualBasic.Devices has equivalent functionality that can be called by other means. It gives specific replacement calls for Microsoft.VisualBasic.Devices.Clock and Microsoft.VisualBasic.Devices.Ports, but nothing for Microsoft.VisualBasic.Devices.Audio, which is what I want to use in my code.
I have tried this in both Visual Studio and Visual Studio Code and get the same errors either way.
With .NET Core, you generally add references via NuGet packages. There is no NuGet package for Microsoft.VisualBasic.Forms.dll, which the documentation clearly states that type is declared in. To get that assembly reference, I believe that you need to replace this line in your project file:
<TargetFramework>net5.0</TargetFramework>
with these lines:
<TargetFramework>net5.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
After doing that, you should see Microsoft.WindowsDesktop.App.WindowsForms added under Dependencies -> Frameworks in the Solution Explorer and the relevant assembly is listed under that.
You have to use reference to "Microsoft.VisualBasic" in your project.
You have two way for do that :
1st way :
Right click on project references, select "Assemblys" => "Framework" and you can search (at top right) "basic" keyword, and select "Microsoft.VisualBasic" item.
After that you can compile your project and normally its works !
Screen for add references
2nd way :
Comment or delete "using Microsoft.VisualBasic.Devices;" instruction.
The class "Audio" should be underline to red, hover with your mouse and you have option by IDE which let you "using Microsoft.VisualBasic.Devices;".
References should be automatically added in project.
And now you can compile your project.

The type or namespace "Toolkit" does not exist in the namespace "Microsoft.MixedReality" with MRTK3

So I made a new Unity Project with the MXTK3 and Unity Version 2021.3.6f1 (LTS). My goal is to track an QR Code, show a small Window with Data (What URL does the CR Code Contain) and then a Button to open the Link in the Endge Browser with the HoloLens 2.
Sadly I can't access CameraCache as I can't import the Toolkit because I got the following error:
Assets\Scripts\SpatialGraphNodeTracker.cs(2,30): error CS0234: The type or namespace name 'Toolkit' does not exist in the namespace 'Microsoft.MixedReality' (are you missing an assembly reference?)
I used the Tool to install following Packages from MRTK3:
MRTK Core Definitions
MRTK Graphic Tools
MRTK Input
MRTK Spatial Manipulation
MRTK Standard Assets
MRTK UX Components
MRTK UX Core Scripts
Beside that just The one XR Thing from Plattform. Any ideas what I can try?
VS shows the packages but not the imports
Got my solution from here:
https://forum.unity.com/threads/unity-removes-project-reference-to-packages.1324617/#post-8374734
If your code is in a .asmdef assembly, you have to locate the asmdef
file for QRCodeSample and set the appropriate references in its
Inspector view. Seeing as you get a VS project for
Microsoft.MixedReality.Toolkit.Core, that assembly seems to be a
.asmdef assembly itself (as opposed to precompiled), which means you
should add that asmdef in the "Assembly Definition References" section
of your .asmdef Inspector.
If your code is just going to Assembly-CSharp or similar, then you're
going to want to either modify the package itself to mark the asmdef
for Microsoft.MixedReality.Toolkit.Core "Auto Referenced" or add a
.asmdef for your code and set up the required asmdef references
yourself.
Thanks again to cyriaca

Can't find namespace in Global

I have the job of getting a legacy project working again. This project was done many years ago using Silverlight and C# Class Library's.
The error I am getting is to do with a namespace inside the project file called Silverlight.Business:
Code
using Tcx = global::MapTools.Xml;
Error:
The type or namespace name "MapTools" could not be found in the global namespace (are you missing an assembly reference?)
MapTools is a C# Class Library and Silverlight.Business is a Silverlight Library. Due to this I can't add a reference to MapTools inside the Silverlight project file.
The silverlight project does have a WCF RIA Service's Link but that does not connect to anything.
I am now wondering how the person that wrote the code has managed to call that namespace? I have tried researching how to add the MapTools.dll to the Global namespace but have not found anything.
Anyone have any ideas?
To do that there should be an some tool been used .
We had used in our projects a Portable library which allowed us to communicate through cross type of projects , below is the link :
https://msdn.microsoft.com/library/gg597391(v=vs.100).aspx

Implement IValueConverter in class library project

I have a solution with about 12 projects, one is set as the startup project and this contains the main window. At the moment all of my IValueConverters are inside this project.
I now want to move them into a separate project that will hold only converters. This way I will be able to reuse them across all the projects, not just the main window.
I have created a new project (class library)
I have imported WindowsBase
I have Included a reference to System.Windows.Data
I am using Visual Studio 2010 Express with .NET 4
I get the error:
"Error 3 The type or namespace name 'IValueConverter' could not be found (are you missing a using directive or an assembly reference?)
"
You need to add a reference to PresentationFramework.dll, that's where IValueConverter is actually defined.
Looking at the documentation you can find that information at the top:
Namespace: System.Windows.Data
Assembly: PresentationFramework (in PresentationFramework.dll)
Please have a look here. I'm sure you're missing the library PresentationFramework.dll in your project.

Referenced class lib doesn't seem

I have a class lib and I referenced it to another windows project. I added its namespace to my Form.cs (using SaglikNetClassLib;). they are seem unknown when I want to access to classes. I can see their properties and methods. But the complier says "Error 7 The type or namespace name 'SaglikNetClassLib' could not be found (are you missing a using directive or an assembly reference?), Do you have any suggestion?
KR,
Çağın
Are you targeting the .net Client Framework? Visual Studio let's you add references to incompatible assemblies, but then gives exactly that error.
Check your project settings to make sure you're targeting the full .net framework.
Also, check that the Ilalcar class is public and not internal (which is the default if it's only declared as class without any modifier)
You probably need an using statement to put the class into scope.
using SaglikNetClassLib;
C# won't auto suggest it if the project has not been rebuild. Also make sure the class library project has been build before using it in code.
Intellisense seems to lag behind a bit at times. Simply pressing f5 (run) sometimes rebuilds the project completely and simply runs or gives a better error message.

Categories

Resources