Search Unity

Dll problems using plugins

Discussion in 'Scripting' started by angelsin, Jun 7, 2015.

  1. angelsin

    angelsin

    Joined:
    Dec 29, 2012
    Posts:
    19
    ok im having some issues, and have been stumped for a few days here. I am trying to access azure blob storage. I couldnt make heads or tails of the rest api, so I decided to try a native plugin. I have pro so i thought why not. But the plugin I wrote relies on another dll which in turn relies on another dll. unity doesn't seem to like this.
    I have tried everything i could find on the web so far. I have placed the other dlls in the same folder, in the project folder, in the editor root folder, system32, and systemWOW64. When i made a test function that removed the need for the other dlls unity could magically find it but when i have the other functions required then it says "
    Failed to load 'Assets/Plugins/x86_64/AzureSGPlugin.dll' with error 'The specified module could not be found.
    ', GetDllDirectory returned ''. If GetDllDirectory returned non empty path, check that you're using SetDirectoryDll correctly."


    I would love some help.
     
  2. chubbspet

    chubbspet

    Joined:
    Feb 18, 2010
    Posts:
    1,220
    You don't state anywhere if you have placed your dll in the Plugins folder in your Unity project and since that is a requirement, I wanted to make sure about that first. And Plugins with a capital "P";)
     
  3. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    External DLLs don't have to be in the plugins folder. They will work fine in any folder as long as they're not actually "plugins" or editor extensions.

    My guess here is that that AzureGSPlugin.dll is built against .NET 4.0 or 4.5 which means it won't load. You can only use assemblies that target .NET 3.5 and below (and even then those assemblies may have other dependencies or dependencies that aren't available under the correct .NET version).
     
  4. angelsin

    angelsin

    Joined:
    Dec 29, 2012
    Posts:
    19
    it's actually its a c++ plugin so no .net issues. And it is in the plugin folder. I can get it to work if I remove the dependency on the second all, but then I can't get the function I need from it
     
  5. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Oh yeah, if its c++ then it needs to be in the plugins folder. Something with that second DLL is incompatible then. It may require a reference to a resource Unity doesn't have access to.
     
  6. angelsin

    angelsin

    Joined:
    Dec 29, 2012
    Posts:
    19
    so the chain of things is my azure plugin requires wastorage.dll, which requires cpprest120_2_6.dll. I think that there is some sort of linking issue, because even dependancywalker seems to have issue with it. it says that my azure plugin requires cpp but it cannot be found. :(
    i think im going to ditch the plugin idea all together and just do some serverside php
     
  7. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    eww PHP. Although using a server proxy is a good idea anyway. You don't want to be exposing your Azure credentials inside your game code. Blob Storage I believe supports a RESTful API as well. Also have a look at the new Azure DocumentDB. It's quite nice and RESTful as well. And you can story binary data as Attachments which uses Azure Blob Storage as the backing.

    http://azure.microsoft.com/en-us/services/documentdb/

    $25 / hr gets you 10 GB of storage and 250 request units / second
    http://azure.microsoft.com/en-us/pricing/details/documentdb/
     
  8. angelsin

    angelsin

    Joined:
    Dec 29, 2012
    Posts:
    19
    Yea the first thing i tried to do was the rest api, I couldnt manage to get it to work. I was having issues getting the uri correct. I ran into issues creating the sas portion. I am not at all familiar with building a uri, and all of the tutorials i could find used .net 4.0 features. :/
    I have just been trying to store map data. I built a runtime level editor for my game im working on, and I wanted players to be able to share them.
     
  9. angelsin

    angelsin

    Joined:
    Dec 29, 2012
    Posts:
    19
  10. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    I can help you look at it. I have free azure resources with my msdn. I could answer any of your Uri questions as well.
     
  11. angelsin

    angelsin

    Joined:
    Dec 29, 2012
    Posts:
    19
    I have some azure resources through msdn too, that's why I thought of using it. So first off, thank you, I really appreciate it.
    I have never really dealt with rest through httprequests so I had followed what this guys was doing after trying on my own for a few days
    Code (CSharp):
    1. public class DatabaseClient : MonoBehaviour {
    2.     string accessKey = "myAccessKeyFromAzureStorageManageAccessKey==";
    3.     string accountName = "accountName";
    4.     string container = "test"; //Storage container created on azure portal called "test"
    5.     // Use this for initialization
    6.     void Start () {
    7.         GetBlob_Test();
    8.     }
    9.  
    10.     // Update is called once per frame
    11.     void Update () {
    12.  
    13.     }
    14.     // GetBlob_Test
    15.     void GetBlob_Test()
    16.     {
    17.         Debug.Log ("Attempting to GET from server");
    18.         DateTime dt = DateTime.UtcNow;
    19.         string stringToSign = String.Format("GET\n"
    20.                                             + "\n" // content md5
    21.                                             + "\n" // content type
    22.                                             + "x-ms-date:" + dt.ToString("R") + "\nx-ms-version:2012-02-12\n" // headers
    23.                                             + "/{0}/{1}\ncomp:list\nrestype:container", accountName, container);
    24.         string authorizationKey = SignThis(stringToSign, accessKey, accountName);
    25.         string method = "GET";
    26.         string urlPath = string.Format("https://{0}.blob.core.windows.net/{1}?restype=container&comp=list", accountName, container);
    27.         Uri uriTest = new Uri(urlPath);
    28.         HttpWebRequest request = (HttpWebRequest)WebRequest.Create (uriTest);
    29.         request.Method = method;
    30.         request.Headers.Add("x-ms-date", dt.ToString("R"));
    31.         request.Headers.Add("x-ms-version", "2012-02-12");
    32.         request.Headers.Add("Authorization", authorizationKey);
    33.         Debug.Log ("Authorization: " + authorizationKey);
    34.         using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
    35.         {
    36.             Debug.Log("Response = " + response);
    37.         }
    38.     }
    39.     private static String SignThis(String StringToSign, string Key, string Account)
    40.     {
    41.         String signature = string.Empty;
    42.         byte[] unicodeKey = Convert.FromBase64String(Key);
    43.         using (HMACSHA256 hmacSha256 = new HMACSHA256(unicodeKey))
    44.         {
    45.             Byte[] dataToHmac = System.Text.Encoding.UTF8.GetBytes(StringToSign);
    46.             signature = Convert.ToBase64String(hmacSha256.ComputeHash(dataToHmac));
    47.         }
    48.      
    49.         String authorizationHeader = String.Format(
    50.             CultureInfo.InvariantCulture,
    51.             "{0} {1}:{2}",
    52.             "SharedKeyLite",
    53.             Account,
    54.             signature);
    55.      
    56.         return authorizationHeader;
    57.     }
    58. }
    even though they had said they were having trouble with it, I figured that I might be able to fix whatever problem they were having and then make something usable.

    I need to be able to do three things with the blob storage. I need to be able to upload files, they are just xml files, but I dont know if that matters. I need to be able to list the blobs in a container. And I need to be able to download a blob. All from c#. I have read through all of the documentation on msdn on interacting with blob storage through rest, but to be honest it didn't make much sense to me. I know that I need to have the base URL along with a verb, such as GET, and the shared access signature. I just don't know how to correctly format it into a URI that works.
     
  12. angelsin

    angelsin

    Joined:
    Dec 29, 2012
    Posts:
    19
    got it. I will post the final .cs files to get it to work so that no one else has to deal with this
     

    Attached Files:

    LaireonGames, Sryall812 and csoe like this.
  13. csoe

    csoe

    Joined:
    May 12, 2014
    Posts:
    1
    Hey @angelsin,

    thank you very much for providing your script! Just wanted to ask where I can find the "SerializeHelper" class? Can't solve that error atm ...
     
  14. angelsin

    angelsin

    Joined:
    Dec 29, 2012
    Posts:
    19
    I'm out of the house right now, but the serialize helper was just the class I wrote to handle serializing objects to xml strings and back. You could put whatever solution for generating a string from an object you want there. If you want I could post some of that too, but I got it mainly from msdn
     
  15. kor

    kor

    Joined:
    Oct 29, 2009
    Posts:
    122
    Thanks @angelsin for your scripts!
    Big help.

    Just a side project but been confused by this for a while.