Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity Error CS0246 NuGet Package MQTT not found, despite installed with no Visual Studio Errors

Discussion in 'Editor & General Support' started by myCookieDough99, Apr 27, 2022.

  1. myCookieDough99

    myCookieDough99

    Joined:
    Mar 8, 2022
    Posts:
    4
    Hello,

    I am having an issue with both Unity 2017.2.4f1 and Visual Studio 2017(2) 15.9.44. The situation is I need to install a MQTT plugin and I did so via NuGet and while Visual Studio is showing me no errors, warnings while building successfully, Unity is erroring. The error, is it seems to think the namespaces of: ‘uPLibrary’, ‘MqttClient’ and ‘MqttMsgPublishEventArgs’ is could not be found with error CS0246. I tried the following links for troubleshooting: https://support.unity.com/hc/en-us/articles/206116726-What-is-CS0246- and https://stackoverflow.com/questions/1421862/metadata-file-dll-could-not-be-found (the latter links was from a .NET framework issue where I had to set Unity from ‘Stable 3.5 Equivalent’ to ‘Experimental 4.6 Equivalent’.


    I am not sure what to do anymore. My goal is simply to get a MQTT plugin so my Unity VR project will receive data. May I please have some help? I am not sure what else to do.


    Thank you for your time.

    Code (text):

    Code (CSharp):
    1. using System;
    2.  
    3. using System.Collections;
    4.  
    5. using System.Collections.Generic;
    6.  
    7. using UnityEngine;
    8.  
    9. using uPLibrary.Networking.M2Mqtt;
    10.  
    11. using uPLibrary.Networking.M2Mqtt.Messages;
    12.  
    13.  
    14.  
    15. public class MQTTClient : MonoBehaviour
    16.  
    17. {
    18.  
    19.  
    20.  
    21.     // Create instance.
    22.  
    23.  
    24.     MqttClient mqttClient = new MqttClient("localhost");
    25.  
    26.  
    27.  
    28.     public void start()
    29.  
    30.     {
    31.  
    32.         // Register message to recieve.
    33.  
    34.         mqttClient.MqttMsgPublishReceived += client_recievedMessage;
    35.  
    36.  
    37.         string clientID = Guid.NewGuid().ToString();
    38.  
    39.  
    40.         mqttClient.Connect(clientID);
    41.  
    42.  
    43.         Debug.Log("Subscriber: MachineData/");
    44.  
    45.  
    46.         mqttClient.Subscribe(new string[] { "MachineData/" }, new byte[] { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE });
    47.  
    48.  
    49.  
    50.     }
    51.  
    52.  
    53.  
    54.     static void client_recievedMessage(object sender, MqttMsgPublishEventArgs e)
    55.  
    56.     {
    57.  
    58.         //Handle message recieved.
    59.  
    60.         var message = System.Text.Encoding.Default.GetString(e.Message);
    61.  
    62.         Debug.Log(":Message recieved: " + message);
    63.  
    64.     }
    65.  
    66.  
    67. }

    Images:

    code image .jpg NuGet References Image.jpg Other settings Image.jpg Unity Error Image.jpg code image .jpg NuGet References Image.jpg Other settings Image.jpg Unity Error Image.jpg
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
    Pretty sure that absolutely nothing you do in Visual Studio matters.

    Unity is the compiler here, not Visual Studio.

    If you need a package in Unity, the Unity Package Manager is the way to get it into your Unity game.
     
  3. myCookieDough99

    myCookieDough99

    Joined:
    Mar 8, 2022
    Posts:
    4
    Hello Kurt-Dekker,

    Thank you for your response. Ahh I see. I really did not want to risk the possible issue(s) of updating everything to then try and add assets, but I think there may be no other option at this stage. This is a project I have inherited that is why the versions are so old. Is there really no other option to troubleshoot this? I did find this asset:

    https://assetstore.unity.com/packages/tools/network/best-mqtt-209238

    But I am totally new to the world of MQTT.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
    Risk?! in the year 2022?! My goodness, nobody should have to worry about stuff like that!!! Are you not using source control properly? If you use it, there is zero risk.

    Please consider using proper industrial-grade enterprise-qualified source control in order to guard and protect your hard-earned work.

    Personally I use git (completely outside of Unity) because it is free and there are tons of tutorials out there to help you set it up as well as free places to host your repo (BitBucket, Github, Gitlab, etc.).

    You can also push git repositories to other drives: thumb drives, USB drives, network drives, etc., effectively putting a complete copy of the repository there.

    As far as configuring Unity to play nice with git, keep this in mind:

    https://forum.unity.com/threads/prefab-links-keep-getting-dumped-on-git-pull.646600/#post-7142306

    Here's how I use git in one of my games, Jetpack Kurt:

    https://forum.unity.com/threads/2-steps-backwards.965048/#post-6282497

    Using fine-grained source control as you work to refine your engineering:

    https://forum.unity.com/threads/whe...grammer-example-in-text.1048739/#post-6783740

    Share/Sharing source code between projects:

    https://forum.unity.com/threads/your-techniques-to-share-code-between-projects.575959/#post-3835837

    Setting up an appropriate .gitignore file for Unity3D:

    https://forum.unity.com/threads/removing-il2cpp_cache-from-project.1084607/#post-6997067

    Generally setting Unity up (includes above .gitignore concepts):

    https://thoughtbot.com/blog/how-to-git-with-unity

    It is only simple economics that you must expend as much effort into backing it up as you feel the work is worth in the first place.

    "Use source control or you will be really sad sooner or later." - StarManta on the Unity3D forum boards
     
  5. myCookieDough99

    myCookieDough99

    Joined:
    Mar 8, 2022
    Posts:
    4

    Hello again Kurt,

    Oh no! I am sorry, I should of elaborated properly. I am very familiar with GIT and I am indeed using it. ( #GitLabs : P). I just hate trying to resolve errors. I was simply told to only consider updating the project if absolutely necessary by my Project Co-Ordinator and it seems it is now the case. I do appreciate your effort and time into adding all of the links just in case I was not familiar. I do wholeheartedly agree with the quote you shared.
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
    That's like cleaning up your kitchen after you cook a meal. You pretty much HAVE to do it.

    You are welcome to keep hating it, or you may wish to consider moving up the food chain and becoming an expert at problem solving. If you have any aspirations to professional software development, debugging WILL be a big part of your life.