I have a c++/cli project and it’s a windows application. In debug mode we didn’t have any problems but after taking it to release mode this error start up. I searched and found some forum-answers but couldn’t help me solve this problem.
Please help me ….
Error :
An unhandled exception of type ‘System.TypeInitializationException’ occurred in Unknown Module.
Additional information: The type initializer for ‘Module’ threw an exception.
Updated 16-Nov-21 14:06pm
I had the same error and found that the class I was referencing was not the problem, but it had a static variable of another type declared that required another assembly to load. That assembly was built for a target platform of x86 (see Properties—>Build tab) however the main project was compiled for Any CPU. I rebuilt the older assembly for Any CPU… problem solved.
Here are some helpful steps for finding the root cause of this problem…
Click Debug—> Exceptions and check ON all the Thrown checkboxes. This will cause the debugger to stop on all first chance exceptions and will help you find the error under the Type Initializer error that you’re seeing. If it is related to another assembly, as mine was, you can use Microsoft’s Assembly Binding Log Viewer tool to help determine the problem.
Does the machine where the application is running has all the required dlls??
Maybe you are missing some interops in the local directory
I recently had the same problem, and it was because I was using Date.Parse on a missing element in the config file:
Date.Parse(System.Configuration.ConfigurationManager.AppSettings.Get(«frex»))
change your .net framework to lower 😉
In my case (so many different cases where this shows up) I was initializing some static fields in their declaration, like this:
public class MyHelperClass { readonly static SolidColorBrush BlueBrush = new SolidColorBrush(Colors.Blue); public static void ApplyBrush() { } }
When I moved the initialization into a static constructor, the exception was no longer thrown:
public class MyHelperClass { readonly static SolidColorBrush BlueBrush; static MyHelperClass { BlueBrush = new SolidColorBrush(Colors.Blue); } }
look the repository container in unity.config <pre><pre lang="xml"> <unity xmlns="http://schemas.microsoft.com/practices/2010/unity"> <alias type="App.Core.Interfaces.IRepositoryConfiguration, App.Core" alias="IRepositoryConfiguration" /> <alias type="App.Repository.Mappings.SqlServer.SqlRepositoryConfigurer, App.Repository.Mappings.SqlServer" alias="SqlRepositoryConfigurer" /> <container name="RepositoryContainer"> <register type="IRepositoryConfiguration" mapTo="SqlRepositoryConfigurer" > <lifetime type="singleton"/> </register> </container> </unity> </pre></pre>
I was making an assignment in a constructor that didn’t have an error handling.
fileInfo = My.Computer.FileSystem.GetFileInfo(logDirLoc & logFileName) writer = fileInfo.AppendText()
When I removed it the issue was solved.
tip: I looked through the error details and saw that a file couldn’t be found. That was it.
I faced the Same error that is «System.TypeInitializationException». This error is raised due to Static constructor .
Actually in my case i am accessing some value from the App.config and assigning that value in a static variable . The error is because of the App.config file . That means the app.config file is not well formed (I just missed some tag on app.config ). After putting the missing tag it works fine.
The type initializer for ‘Module’ threw an exception.
Just Run IISRESET
I had this problem also, but my solution wasn’t any of these. It was because I had an unmanaged class with a virtual function that returned a managed pointer.
class A { virtual ManagedType^ Foo(); };
Apparently the C++/CLI runtime can’t handle this. Removing the virtual fixed the problem (luckily for me the virtual wasn’t needed in my case).
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
Tried using System.Drawing.Common package for my .net core web api project. It runs fine under windows but on ubunto (which is my host server), it throws following errors:
This is the method i used to generate thumbnail:
public static bool CreateThumbnail(int Width, int Height, Stream filePath, string saveFilePath)
{
try
{
var byteArray = filePath;
var streamImg = Image.FromStream(byteArray);
Bitmap sourceImage = new Bitmap(streamImg);
using (Bitmap objBitmap = new Bitmap(Width, Height))
{
objBitmap.SetResolution(sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
using (Graphics objGraphics = Graphics.FromImage(objBitmap))
{
// Set the graphic format for better result cropping
objGraphics.SmoothingMode = SmoothingMode.HighQuality;
objGraphics.PixelOffsetMode = PixelOffsetMode.HighSpeed;
objGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
objGraphics.CompositingQuality = CompositingQuality.HighQuality;
objGraphics.DrawImage(sourceImage, 0, 0, Width, Height);
// Save the file path, note we use png format to support png file
objBitmap.Save(saveFilePath);
}
}
}
catch (Exception ex)
{
LogHelper.Log("Create Thumbnail: ERROR:" + ex.Message + "n" + ex.StackTrace);
return false;
}
return true;
}
ERROR:The type initializer for 'Gdip' threw an exception.
at System.Drawing.SafeNativeMethods.Gdip.GdipLoadImageFromDelegate_linux(StreamGetHeaderDelegate getHeader, StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, StreamCloseDelegate close, StreamSizeDelegate size, IntPtr& image)
at System.Drawing.Image.InitFromStream(Stream stream)
at System.Drawing.Image.LoadFromStream(Stream stream, Boolean keepAlive)
Already installed
sudo apt-get install libgdiplus
and did this too:
cd /usr/lib
sudo ln -s libgdiplus.so gdiplus.dll
So Any workaround or thoughts on this?
- Remove From My Forums
-
Question
-
Hi all.
I have a solution that has 3 projects. One of the is the DAL.
The solution is hosted in team foundation.
When i try update-database i got the error: «The type initializer for ‘System.Data.Entity.Migrations.DbMigrationsConfiguration`1’ threw an exception.»
All the console messages are bellow
update-database -StartUpProjectName ManagerBs.Core -verbose
Using StartUp project ‘ManagerBs.Core’.
Using NuGet project ‘ManagerBs.Core’.
Specify the ‘-Verbose’ flag to view the SQL statements being applied to the target database.
System.TypeInitializationException: The type initializer for ‘System.Data.Entity.Migrations.DbMigrationsConfiguration`1’ threw an exception. —> System.TypeInitializationException: The type initializer for ‘System.Data.Entity.Internal.AppConfig’ threw an
exception. —> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize —> System.Configuration.ConfigurationErrorsException: Unrecognized element. (C:inetpubwwwrootCRM_MVCManagerBSSolutionWebAppManagerManagerBs.Coretmp59F8.tmp
line 4)
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
— End of inner exception stack trace —
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.get_ConnectionStrings()
at System.Data.Entity.Internal.AppConfig..ctor()
at System.Data.Entity.Internal.AppConfig..cctor()
— End of inner exception stack trace —
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForAssembly(Assembly assemblyHint, Type contextTypeHint)
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForContext(Type contextType)
at System.Data.Entity.Migrations.DbMigrationsConfiguration`1..cctor()
— End of inner exception stack trace —
at System.Data.Entity.Migrations.DbMigrationsConfiguration`1..ctor()
at ManagerBs.Core.Migrations.Configuration..ctor() in c:inetpubwwwrootCRM_MVCManagerBSSolutionWebAppManagerManagerBs.CoreMigrationsConfiguration.cs:line 10
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Data.Entity.Migrations.Utilities.MigrationsConfigurationFinder.FindMigrationsConfiguration(Type contextType, String configurationTypeName, Func`2 noType, Func`3 multipleTypes, Func`3 noTypeWithName, Func`3 multipleTypesWithName)
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator()
at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
The type initializer for ‘System.Data.Entity.Migrations.DbMigrationsConfiguration`1’ threw an exception.I couldn’t sleep last nights because this problem.
Somebody have an idea to solve it?
PS: Sorry my amateur english. 😉
Answers
-
Hi, thanks for answer.
My problem was solved by disable and enable back migrations.
Márcio Alves Gonzalez Web programmer
-
Marked as answer by
Monday, March 10, 2014 1:18 AM
-
Marked as answer by
-
Marcio how do you disable and enable migration on visual studio 2013, my program throws the same error
-
Marked as answer by
MárcioGonzalez
Thursday, May 22, 2014 12:46 PM
-
Marked as answer by
-
-
Marked as answer by
MárcioGonzalez
Thursday, May 22, 2014 12:46 PM
-
Marked as answer by
-
Hi. I was wondering, How do you disable migrations cause i know how to enable them?
-
Marked as answer by
MárcioGonzalez
Thursday, May 22, 2014 12:45 PM
-
Marked as answer by