"is not marked as serializable" error with Q8 for AnyCPU

Apr 3, 2015 at 8:40 AM
Hi All !

I'm French. So, sorry for my very bad English and please talk simply if you can.

I try to use MagickImage. I installed with Nuget Package Manager : Q8 version for AnyCPU. My project is a Web MVC 4 project with C#.
Then, my code :
                        MagickAnyCPU.CacheDirectory = Server.MapPath("~/Files");
                        MagickReadSettings settings = new MagickReadSettings();
                        settings.Density = new PointD(300, 300);
                        using (MagickImageCollection images = new MagickImageCollection())
                        {
                            images.Read(Path.Combine(path, fileName), settings); //"fileName" is declared before
                            using (MagickImage vertical = images.AppendVertically())
                            {
                                vertical.Write(Path.Combine(path, Path.GetFileNameWithoutExtension(fileName) + ".pdf"));
                            }
                        }
But i get an error :
Server Error in '/' Application.

Type 'Martin3D.Website.ApplicationIdentity' in Assembly 'Martin3D.Website, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Runtime.Serialization.SerializationException: Type 'Martin3D.Website.ApplicationIdentity' in Assembly 'Martin3D.Website, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

Source Error: 


Line 168:                        //Conversion en image et sauvegarde
Line 169:                        MagickAnyCPU.CacheDirectory = Server.MapPath("~/Files");
Line 170:                        MagickReadSettings settings = new MagickReadSettings();
Line 171:                        settings.Density = new PointD(300, 300);
Line 172:                        using (MagickImageCollection images = new MagickImageCollection())

Source File: d:\Developpement\Projets Visual Studio\Site Martin3D\site\Martin3D.Website\Controllers\ContactController.cs    Line: 170 

Stack Trace: 


[SerializationException: Type 'Martin3D.Website.ApplicationIdentity' in Assembly 'Martin3D.Website, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.]
   System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +11080899
   System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +336
   System.AppDomain.get_Id() +0
   <CrtImplementationDetails>.DoCallBackInDefaultDomain(IntPtr function, Void* cookie) +241
   <CrtImplementationDetails>.DefaultDomain.Initialize() +30
   <CrtImplementationDetails>.LanguageSupport.InitializeDefaultAppDomain(LanguageSupport* ) +46
   <CrtImplementationDetails>.LanguageSupport._Initialize(LanguageSupport* ) +504
   <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* ) +157

[ModuleLoadException: The C++ module failed to load while attempting to initialize the default appdomain.
]
   <CrtImplementationDetails>.ThrowModuleLoadException(String errorMessage, Exception innerException) +66
   <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* ) +219
   .cctor() +46

[TypeInitializationException: The type initializer for '<Module>' threw an exception.]
   System.Delegate.BindToMethodInfo(Object target, IRuntimeMethodInfo method, RuntimeType methodType, DelegateBindingFlags flags) +0
   System.Delegate.CreateDelegateNoSecurityCheck(Type type, Object target, RuntimeMethodHandle method) +109
   System.Reflection.Emit.DynamicMethod.CreateDelegate(Type delegateType) +53
   Fasterflect.Emitter.MethodInvocationEmitter.CreateDelegate() +451
   Fasterflect.Emitter.BaseEmitter.GetDelegate() +125
   Fasterflect.MethodExtensions.DelegateForCallMethod(Type type, Type[] genericTypes, String name, Flags bindingFlags, Type[] parameterTypes) +85
   Fasterflect.MethodExtensions.DelegateForCallMethod(Type type, String name, Type[] parameterTypes) +53
   Fasterflect.MethodExtensions.CallMethod(Object obj, String name, Type[] parameterTypes, Object[] parameters) +29
   ImageMagick.AssemblyHelper.LoadAssembly(String cacheDirectory, String tempFile) +186
   ImageMagick.AssemblyHelper.LoadAssembly() +151

[InvalidOperationException: Failed to load embedded x86 assembly: unable to initialize Magick.NET]
   ImageMagick.AssemblyHelper.get_Assembly() +162
   ImageMagick.Types.get_MagickReadSettings() +25
   ImageMagick.MagickReadSettings..ctor() +11
   Martin3D.Website.Controllers.ContactController.Step1(ContactStep1ViewModel model) in d:\Developpement\Projets Visual Studio\Site Martin3D\site\Martin3D.Website\Controllers\ContactController.cs:170
   lambda_method(Closure , ControllerBase , Object[] ) +104
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +28
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +48
   System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +57
   System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +223
   System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +48
   System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +24
   System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +102
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +43
   System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +57
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +47
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +47
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9651116
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34212
I tried to find a solution on this forum, without success.

Thank you by advance,
Coordinator
Apr 3, 2015 at 9:15 AM
Are you using Glimpse in your project? The user from the topic 'https://magick.codeplex.com/discussions/586289' reported something similar.
Apr 3, 2015 at 9:22 AM
Thanks for the quick answer.
I have already read this topic. But i not use Glimpse.
Coordinator
Apr 3, 2015 at 9:40 AM
Are you using any other packages in your project besides Magick.NET? Can you try disabling them and see if that solves the problem?
Apr 3, 2015 at 10:12 AM
Ok.
But if it's a package, what is the solution ?

I have many package in my project. I need a lot of time to do this.
Coordinator
Apr 3, 2015 at 10:21 AM
Edited Apr 3, 2015 at 10:22 AM
Just to be sure, did you install the VisualStudio C++ Redistributable 2012 as described in the documentation?
Apr 3, 2015 at 10:37 AM
Yes.

From this link : http://www.microsoft.com/fr-fr/download/details.aspx?id=30679
I installed the x64 and x86 version.
Apr 3, 2015 at 10:44 AM
Meanwhile, i added a "[Serializable]" to "ApplicationIdentity". And the error is different :
Server Error in '/' Application.

Unable to find assembly 'Martin3D.Website, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Runtime.Serialization.SerializationException: Unable to find assembly 'Martin3D.Website, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

Source Error: 


Line 168:                        //Conversion en image et sauvegarde
Line 169:                        MagickAnyCPU.CacheDirectory = Server.MapPath("~/Files");
Line 170:                        MagickReadSettings settings = new MagickReadSettings();
Line 171:                        settings.Density = new PointD(300, 300);
Line 172:                        using (MagickImageCollection images = new MagickImageCollection())

Source File: d:\Developpement\Projets Visual Studio\Site Martin3D\site\Martin3D.Website\Controllers\ContactController.cs    Line: 170 

Stack Trace: 


[SerializationException: Unable to find assembly 'Martin3D.Website, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.]
   System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +11080899
   System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +336
   System.AppDomain.get_Id() +0
   <CrtImplementationDetails>.DoCallBackInDefaultDomain(IntPtr function, Void* cookie) +241
   <CrtImplementationDetails>.DefaultDomain.Initialize() +30
   <CrtImplementationDetails>.LanguageSupport.InitializeDefaultAppDomain(LanguageSupport* ) +46
   <CrtImplementationDetails>.LanguageSupport._Initialize(LanguageSupport* ) +504
   <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* ) +157

[ModuleLoadException: The C++ module failed to load while attempting to initialize the default appdomain.
]
   <CrtImplementationDetails>.ThrowModuleLoadException(String errorMessage, Exception innerException) +66
   <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* ) +219
   .cctor() +46

[TypeInitializationException: The type initializer for '<Module>' threw an exception.]
   System.Delegate.BindToMethodInfo(Object target, IRuntimeMethodInfo method, RuntimeType methodType, DelegateBindingFlags flags) +0
   System.Delegate.CreateDelegateNoSecurityCheck(Type type, Object target, RuntimeMethodHandle method) +109
   System.Reflection.Emit.DynamicMethod.CreateDelegate(Type delegateType) +53
   Fasterflect.Emitter.MethodInvocationEmitter.CreateDelegate() +451
   Fasterflect.Emitter.BaseEmitter.GetDelegate() +125
   Fasterflect.MethodExtensions.DelegateForCallMethod(Type type, Type[] genericTypes, String name, Flags bindingFlags, Type[] parameterTypes) +85
   Fasterflect.MethodExtensions.DelegateForCallMethod(Type type, String name, Type[] parameterTypes) +53
   Fasterflect.MethodExtensions.CallMethod(Object obj, String name, Type[] parameterTypes, Object[] parameters) +29
   ImageMagick.AssemblyHelper.LoadAssembly(String cacheDirectory, String tempFile) +186
   ImageMagick.AssemblyHelper.LoadAssembly() +151

[InvalidOperationException: Failed to load embedded x86 assembly: unable to initialize Magick.NET]
   ImageMagick.AssemblyHelper.get_Assembly() +162
   ImageMagick.Types.get_MagickReadSettings() +25
   ImageMagick.MagickReadSettings..ctor() +11
   Martin3D.Website.Controllers.ContactController.Step1(ContactStep1ViewModel model) in d:\Developpement\Projets Visual Studio\Site Martin3D\site\Martin3D.Website\Controllers\ContactController.cs:170
   lambda_method(Closure , ControllerBase , Object[] ) +104
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +28
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +48
   System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +57
   System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +223
   System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +48
   System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +24
   System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +102
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +43
   System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +57
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +47
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +47
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9651116
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34212
Very strange... He can't find assembly "Website" but "Website" is the project where the code is...
Coordinator
Apr 3, 2015 at 12:09 PM
I am really starting to wonder if this is a Magick.NET issue. This looks like something in your project.