I am trying to implement a COM interface in a C# service. The interface is from MS and documented here: https://msdn.microsoft.com/en-us/library/hh948551.aspx. All appears fine until I add this one method, DownloadContent. After adding that, the client COM service crashes with 0xc0000005. This makes me believe that there is some type of mismatch.
Here is my C# Interface code.
[PreserveSig]
[return: MarshalAs(UnmanagedType.Error)]
int DownloadContent(
[In]
StringBuilder szContentId,
[In]
StringBuilder szContentVersion,
[In]
StringBuilder szRemotePath,
[In]
StringBuilder szLocalPath,
[In]
StringBuilder szNotifyEndpoint,
[In]
StringBuilder szNotifyData,
[In]
CCM_DTS_PRIORITY Priority,
[In]
int dwTimeoutSeconds,
[In]
int dwChunkSize,
[In]
int dwFlags,
[In]
StringBuilder szLocationOptions,
[In]
StringBuilder szFileManifest,
[In]
StringBuilder szOwnerSID,
[In]
[MarshalAs(UnmanagedType.Bool)]
bool bDeleteJobOnError,
[In]
StringBuilder szProviderData,
[In]
StringBuilder szPackageData,
[Out]
out Guid pJobID
);
Building a type library using regasm.exe /tlb I get the following IDL:
HRESULT DownloadContent(
[in] LPWSTR szContentId,
[in] LPWSTR szContentVersion,
[in] LPWSTR szRemotePath,
[in] LPWSTR szLocalPath,
[in] LPWSTR szNotifyEndpoint,
[in] LPWSTR szNotifyData,
[in] CCM_DTS_PRIORITY Priority,
[in] long dwTimeoutSeconds,
[in] long dwChunkSize,
[in] long dwFlags,
[in] LPWSTR szLocationOptions,
[in] LPWSTR szFileManifest,
[in] LPWSTR szOwnerSID,
[in] long bDeleteJobOnError,
[in] LPWSTR szProviderData,
[in] LPWSTR szPackageData,
[out] GUID* pJobID);
The documentation from Microsoft shows the method should be:
HRESULT DownloadContent(
LPCWSTR szContentId,
LPCWSTR szContentVersion,
LPCWSTR szRemotePath,
LPCWSTR szLocalPath,
LPCWSTR szNotifyEndpoint,
LPCWSTR szNotifyData,
CCM_DTS_PRIORITY Priority,
DWORD dwTimeoutSeconds,
DWORD dwChunkSize,
DWORD dwFlags,
LPCWSTR szLocationOptions,
LPCWSTR szFileManifest,
LPCWSTR szOwnerSID,
BOOL bDeleteJobOnError,
LPCWSTR szProviderData,
LPCWSTR szPackageData,
GUID *pJobID
);
The only difference I can see is that the C# method is using LPWSTR instead of LPCWSTR. Is there anyway to get a LPCWSTR in C# or does anyone else have any ideas as to why it would be crashing the COM client?