'System.Runtime.InteropServices.Marshal' does not contain a definition for 'StringToHGlobalAnsi'

Help
ecabigting
2013-09-16
2013-09-18
  • ecabigting

    ecabigting - 2013-09-16

    Has anyone experience this before? I'm using the MediaInfoDLL.cs, I added it to my Silverlight project. Then I get this following error 'System.Runtime.InteropServices.Marshal' does not contain a definition for 'StringToHGlobalAnsi'. I check from where it was coming from. It seems that the class made using the MSCORLIB for .net and but when loaded to a silverlight project, it uses the MSCORLIB lib for silverlight which is the StringToHGlobalAnsi. Been stuck here for a while, any help would greatly be appreciated.

    Thanks,
    eric

     
  • Jerome Martinez

    Jerome Martinez - 2013-09-16

    I don't know exactly about the issue with Silverlight, StringToHGlobalAnsi is expected to exist everywhere, but in your case, Windows only, you can remove any reference to StringToHGlobalAnsi in MediaInfoDLL.cs. I use it only because I have some issues with unicode on non-windows platforms (e.g. unicode is 4-byte long on Linux but C is with 2-byte long unicode)

    Remove any instance of:

                if (MustUseAnsi)
                {
                    (...)
                }
                else
    
     
  • ecabigting

    ecabigting - 2013-09-17

    ok Cool thanks :D :)

     
  • ecabigting

    ecabigting - 2013-09-17

    Ok so, your suggestion was great. Now I have another problem.

    System.Runtime.InteropServices.GCHandle GC = System.Runtime.InteropServices.GCHandle.Alloc(From_Buffer, System.Runtime.InteropServices.GCHandleType.Pinned);
    IntPtr From_Buffer_IntPtr = GC.AddrOfPinnedObject();

    the lines from above are from your sample app that runs on .net C#, problem is, when you run that line on Silverlight, it would throw an exception something like this

    Attempt by security transparent method 'IntizializeFromBuffer()' to access security critical method 'System.Runtime.InteropServices.GCHandle.Alloc(System.Object, System.Runtime.InteropServices.GCHandleType)' failed.

    The use of GCHandle.Alloc in silverlight is really not advisable as it was mark as SECURITY CRITICAL on Silverlight. Please refer to this link http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.gchandle.alloc(v=vs.95).aspx

    Im sorry for having so many question. But, I really wanted this to work. Thanks so much.

    PS.
    Im not that familiar with memory allocation.

     
    Last edit: ecabigting 2013-09-17
  • Jerome Martinez

    Jerome Martinez - 2013-09-17

    the lines from above are from your sample app that runs on .net C#, problem is, when you run that line on Silverlight, it would throw an exception something like this

    Theses lines are for an example with buffers. If you don't need using the interface with buffers instead of file names, remove completely ExampleWithStream() code.
    Don't forget that it is only an example, if you don't need some functionnalities, you are not forced to use the corresponding example code.
    If you want to use buffers, this is a problem with Silverlight, not me, I can not do something forbidden by the editor of the compiler. There is no plan to find a workaround on my side (main developer).

     
  • ecabigting

    ecabigting - 2013-09-18

    ok got it thanks.. :)

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks