Error after switching from .NET 3.5 to 4
Application.Run(开发者_运维技巧new Main());
This line gives TypeInitializationException was unhandled after I switched from 3.5 to 4 framework.
Why is this?
Edit: Forgot to mention this is a Winforms C# application.
Okay so I have SQLite .NET referenced. I tried this on a project created on .NET 4 by default and didn't give me any error so I assumed it wasn't about SQLite .NET http://sqlite.phxsoftware.com/
Please note v2.0.50727 this is the runtime version of the DLL which seems to be causing the problem.
- Thrown: "A assemblagem de modo misto foi criada com base na versão 'v2.0.50727' do tempo de execução e não é possível carregá-la no tempo de execução 4.0 sem informações de configuração adicionais." (System.IO.FileLoadException) Exception Message = "A assemblagem de modo misto foi criada com base na versão 'v2.0.50727' do tempo de execução e não é possível carregá-la no tempo de execução 4.0 sem informações de configuração adicionais.", Exception Type = "System.IO.FileLoadException"
Seems he can't run the DLL on v4 with/ extra configuration.
Look at the InnerException to get the reason that the static constructor of the Main class failed. It is usually caused by static variable initializers throwing an exception.
Update: my Portuguese is quite rusty, but it looks like you are using an assembly that was written in C++/CLI and built targeting the .NET 2.0 version of the CLR. SqlLite fits that description. Other than getting an update for that assembly, you need to tell the CLR that it is okay to load the assembly with the .NET 4.0 version of the CLR. Project + Add New Item, select Application Configuration File. Make it look like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
精彩评论