public static CriticalAllocHandle FromPnrpBlob(object input)
                {
                    BlobSafe blob = new BlobSafe();
                    if (input != null)
                    {
                        if (input.GetType() == typeof(PnrpInfo))
                        {
                            int blobSize = Marshal.SizeOf(typeof(PnrpInfoNative));
                            blob.pBlobData = CriticalAllocHandle.FromSize(blobSize + Marshal.SizeOf(typeof(BlobNative)));

                            //write the BlobSafe fields first,
                            BlobNative nativeBlob;
                            nativeBlob.cbSize = blobSize;
                            nativeBlob.pBlobData = (IntPtr)(((IntPtr)blob.pBlobData).ToInt64() + Marshal.SizeOf(typeof(BlobNative)));
                            Marshal.StructureToPtr(nativeBlob, (IntPtr)blob.pBlobData, false);
                            PnrpInfo pnrpInfo = (PnrpInfo)input;
                            pnrpInfo.dwSize = blobSize;
                            PnrpInfoNative nativeInfo = new PnrpInfoNative();
                            PnrpInfo.ToPnrpInfoNative(pnrpInfo, ref nativeInfo);
                            Marshal.StructureToPtr(nativeInfo, (IntPtr)nativeBlob.pBlobData, false);
                            blob.cbSize = blobSize;
                        }
                        else if (input.GetType() == typeof(PnrpCloudInfo))
                        {
                            int blobSize = Marshal.SizeOf(input.GetType());
                            blob.pBlobData = CriticalAllocHandle.FromSize(blobSize + Marshal.SizeOf(typeof(BlobNative)));

                            //write the BlobSafe fields first,
                            BlobNative nativeBlob;
                            nativeBlob.cbSize = blobSize;
                            nativeBlob.pBlobData = (IntPtr)(((IntPtr)blob.pBlobData).ToInt64() + Marshal.SizeOf(typeof(BlobNative)));
                            Marshal.StructureToPtr(nativeBlob, (IntPtr)blob.pBlobData, false);
                            PnrpCloudInfo cloudInfo = (PnrpCloudInfo)input;
                            cloudInfo.dwSize = Marshal.SizeOf(typeof(PnrpCloudInfo));
                            Marshal.StructureToPtr(cloudInfo, (IntPtr)nativeBlob.pBlobData, false);
                            blob.cbSize = blobSize;
                        }
                        else
                        {
                            throw Fx.AssertAndThrow("Unknown payload type!");
                        }
                    }
                    return blob.pBlobData;

                }
 public PnrpRegisteredIdState enNameState; // state of registered name
 public static void ToPnrpInfoNative(PnrpInfo source, ref PnrpInfoNative target)
 {
     target.dwSize = source.dwSize;
     target.lpwszIdentity = source.lpwszIdentity;
     target.nMaxResolve = source.nMaxResolve;
     target.dwTimeout = source.dwTimeout;
     target.dwLifetime = source.dwLifetime;
     target.enResolveCriteria = source.enResolveCriteria;
     target.dwFlags = source.dwFlags;
     if (source.saHint != null)
     {
         target.saHint.lpSockAddr = source.saHint.lpSockAddr;
         target.saHint.iSockaddrLength = source.saHint.iSockaddrLength;
     }
     else
     {
         target.saHint.lpSockAddr = IntPtr.Zero;
         target.saHint.iSockaddrLength = 0;
     }
     target.enNameState = source.enNameState;
 }