Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use the SDK in an MVC Application (.net framework 4.5.2) #33

Closed
victorjonsson opened this Issue Feb 12, 2019 · 1 comment

Comments

Projects
None yet
1 participant
@victorjonsson
Copy link

victorjonsson commented Feb 12, 2019

The code below works well when running in a console app. But it ends up in an exception when the same code gets executed in an MVC app. The message states ,that the "file" doesn't exist, which file is it referring to?

SafeNativeMethods.IpcInitialize();
SafeNativeMethods.IpcSetAPIMode(APIMode.Server);

var tempFile = "C:\\Users\\vikjon03\\source\\repos\\somewher\\bild.jpg";

var fileExists = File.Exists(tempFile); // this variable is set to true when debugging
Stream inStream = File.OpenRead(tempFile);
Stream outStream = new MemoryStream();
SafeFileApiNativeMethods.IpcfEncryptFileStream(  // this method call triggers the exception
 inStream,
 tempFile,
 RmsTemplateId,
 SafeFileApiNativeMethods.EncryptFlags.IPCF_EF_FLAG_KEY_NO_PERSIST,
 ref outStream
);

Exception (for some reason translated to swedish?)

{"Message":"An error has occurred.","ExceptionMessage":"Det går inte att hitta filen. HRESULT: 0x80070002","ExceptionType":"Microsoft.InformationProtectionAndControl.InformationProtectionException","StackTrace":"   vid Microsoft.InformationProtectionAndControl.SafeNativeMethods.ThrowOnErrorCode(Int32 hrError) i C:\\Users\\vikjon03\\source\\repos\\e.umea.se\\Umea.se.BlobService\\IpcManagedAPI\\SafeNativeMethods.cs:rad 2238\r\n   vid Microsoft.InformationProtectionAndControl.SafeFileApiNativeMethods.IpcfEncryptFileStream(Stream inputStream, String inputFilePath, String templateId, EncryptFlags flags, Stream& outputStream, SafeIpcPromptContext ipcContext) i C:\\Users\\vikjon03\\source\\repos\\e.umea.se\\Umea.se.BlobService\\IpcManagedAPI\\SafeFileApiNativeMethods.cs:rad 279\r\n   vid Umea.se.BlobStorage.InformationProtection.AIP.Encrypt(Stream inputStream) i C:\\Users\\vikjon03\\source\\repos\\e.umea.se\\Umea.se.BlobService\\InformationProtection\\AIP.cs:rad 67\r\n   vid Umea.se.BlobStorage.Controllers.BlobController.<Put>d__0.MoveNext() i C:\\Users\\vikjon03\\source\\repos\\e.umea.se\\Umea.se.BlobService\\Controllers\\BlobController.cs:rad 41\r\n--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---\r\n   vid System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   vid System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__1`1.MoveNext()\r\n--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---\r\n   vid System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   vid System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext()\r\n--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---\r\n   vid System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   vid System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()\r\n--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---\r\n   vid System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   vid System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()"}

@victorjonsson

This comment has been minimized.

Copy link
Author

victorjonsson commented Feb 12, 2019

I found my problem. The exception was thrown due to an invalid template id.

For future updates to this library I would, most humbly, suggest having an error message that is understandable and not misleading. Something like "Invalid/unknown template id".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.