Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. InterlockedExchange64 and .NET assembly permission issues.

InterlockedExchange64 and .NET assembly permission issues.

Scheduled Pinned Locked Moved Managed C++/CLI
csharphelpsecurityjsonperformance
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mikanu
    wrote on last edited by
    #1

    I've been working on a .NET component for some time and I recently ran into an issue I could'n find any documentation for so far. Basically the .NET assembly should compile into a mix-mode DLL. That is, the assembly contains a managed class that wraps up a __nogc class that performs some time-sensitive operations on the serial port. The __nogc class spawns a thread that monitors the serial port and that writes to a buffer. In order to make sure that the rest of the program, that sits in a different thread, doesn't conflict with the monitor thread when competing for access to the buffer, I'm using the InterlockedExchange64 and InterlockedExchangeAdd64 functions in the unmanaged class. That seems to prevent the assembly from further beeing accessible to c# .NET applications. When open in the Object Explorer, the assembly shows up fine but when included in the project and instantiated a System.IO.FileLoadException is thrown by the system. It almost looks like there is a permission issue with the asssembly. But that is not the case, I've made sure that all the security policies are reset to default and tried loading the assembly in the "Evaluate Assembly" tool. That didn't work. The "Evaluate Assembly" tool shows an error message saying that the assembly could not be loaded.:confused: So, I'd like to know what is the reason that I can't use Interlocked methods in the unmanaged class or if there is a way around that. Keep in mind that i'm trying to optimize for speed. Feel free to ask for more details.

    M 1 Reply Last reply
    0
    • M mikanu

      I've been working on a .NET component for some time and I recently ran into an issue I could'n find any documentation for so far. Basically the .NET assembly should compile into a mix-mode DLL. That is, the assembly contains a managed class that wraps up a __nogc class that performs some time-sensitive operations on the serial port. The __nogc class spawns a thread that monitors the serial port and that writes to a buffer. In order to make sure that the rest of the program, that sits in a different thread, doesn't conflict with the monitor thread when competing for access to the buffer, I'm using the InterlockedExchange64 and InterlockedExchangeAdd64 functions in the unmanaged class. That seems to prevent the assembly from further beeing accessible to c# .NET applications. When open in the Object Explorer, the assembly shows up fine but when included in the project and instantiated a System.IO.FileLoadException is thrown by the system. It almost looks like there is a permission issue with the asssembly. But that is not the case, I've made sure that all the security policies are reset to default and tried loading the assembly in the "Evaluate Assembly" tool. That didn't work. The "Evaluate Assembly" tool shows an error message saying that the assembly could not be loaded.:confused: So, I'd like to know what is the reason that I can't use Interlocked methods in the unmanaged class or if there is a way around that. Keep in mind that i'm trying to optimize for speed. Feel free to ask for more details.

      M Offline
      M Offline
      mikanu
      wrote on last edited by
      #2

      Well... it seems that not a lot of people took interest in this post, nonetheless have I got an answer. Anyway, I found the answer on another forum and thought to complete this post with the explanation and some thoughts. Basically, the problem was using the InterlockedExchange64 instead of the regular InterlockedExchange. Some say that the InterlockedExchange64 is designed for 64bit OSes and that's the reason it was making my assembly not load. That sounds interesting, but what's even more interesting is that the DLL was compiling without problems with the 64bit version of the function. It's a mistery. Also it's interesting that the IntelliSense is picking up InterlockedExchange64 but not the regular one... definetly something odd. :wtf: Enough said, I can now load the assembly in the Evaluate Tool and it looks good so I'm on to further testing it.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups