Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by aptus-naru · Jun 04, 2018 at 10:08 PM · crashdllthread

Error loading custom DLL with async for BLE

Hello! This is my first post here and first time developing with Unity so I would appreciate a walk through.

I'm trying to add BLE functionality to an existing Windows 10 Unity app. I'm using a BLE dongle to interface with a hardware device (custom designed and programmed board). I created a Visual Studio C# (.NET framework) project which uses Windows.Devices.Bluetooth (and therefore needs Windows.winmd). I couldn't get Unity to import Windows.winmd so I made a DLL with the functionality.

This DLL loads Windows.Devices.Bluetooth and uses async/await calls. Mainly this: // Function to connect to device with given address: addr private async void ConnectAndStartReading(ulong addr, string s_uuid, string c_uuid) { // Connect to device device = await BluetoothLEDevice.FromBluetoothAddressAsync(addr);

             // Get service async
             GattDeviceServicesResult s = await device.GetGattServicesForUuidAsync(Guid.Parse(s_uuid));
             service = s.Services[0];
 
             // Get characteristic async
             GattCharacteristicsResult c = await service.GetCharacteristicsForUuidAsync(Guid.Parse(c_uuid));
             characteristic = c.Characteristics[0];
 
             // Set config description value to notify
             GattCommunicationStatus status = await characteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);
 
             // Set characteristic value change callback
             characteristic.ValueChanged += Handler_CharacteristicValueChanged;
         }

In the Handler_CharacteristicValueChanged function, it sets 3 variables (roll, pitch and yaw) from the buffer. I'd like the Unity program to read the 3 public variables.

Again, this works fine on a non-Unity app. (Here are some snippets)

 namespace ARC_BLE_Interface_Test
 {
     class Program
     {
         public static BLE_Interface ble;
 
         static void Main(string[] args)
         {
             // Device specifications
             ulong dev_addr = 255782611406774;
 
             // Service UUID
             string data_stream_service_uuid = "0000fe84-0000-1000-8000-00805f9b34fb";
 
             // Characteristic UUID
             string data_stream_char_uuid = "2d30c082-f39f-4ce6-923f-3484ea480596";
 
             ble = new BLE_Interface(dev_addr, data_stream_service_uuid, data_stream_char_uuid);
 
             while (true)
             {
                 Console.WriteLine(ble.roll + "\t" + ble.pitch + "\t" + ble.yaw);
 
                 Thread.Sleep(50);
             }
         }
     }
 }

but not with Unity. I have an implementation like this:

 public BLE_Interface ble;
 
     void Start()
     {
         ble = new BLE_Interface(device_address, data_stream_service_uuid, data_stream_char_uuid);
     }
 
     void Update()
     {
         ConsoleController.HotMessage(ble.roll.ToString());
     }

I get the following errors: TypeLoadException: Could not find method due to a type load error Unloading broken assembly Assets/dll/ARC_BLE_Interface.dll, this assembly can cause crashes in the runtime

Any ideas?

Thank you very much! Let me know if you need any more information. I haven't really programmed in C# or Unity before yesterday.

Cheers!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

144 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity Editor crashes when loading managed Plug-in (external DLL) 1 Answer

x86 build don't work 0 Answers

Windows 10 Unity access violation 1 Answer

Try to load a DLL and I got System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded. 0 Answers

How to use DLLs 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges