Library .NET version exception [duplicate] - c#

This question already has answers here:
What 'additional configuration' is necessary to reference a .NET 2.0 mixed mode assembly in a .NET 4.0 project?
(17 answers)
Closed 8 years ago.
Im trying do my first steps in Winforms development with C# and .NET framework.
I want to make a little users CRUD application. I have the SQLite db populated with test data.
So, i create a blank project solution, and added a "Class library" project called "DataBundle".
In the DataBundle, have the entity class for the database, mapped with Entity Framework.
Also, i created a console application for test my DataBundle. The app build correctlly, but when try run querys the application throw an exception.
This is my code:
Console.WriteLine("Testeando el DataBudnle ...");
mainContext _dao = new mainContext();
Zone city = new Zone
{
name = "Ensenada"
};
Console.WriteLine("Existen {0} ciudades registradas ...", _dao.Zones.Count());
Console.ReadLine();
And the exception message is:
The mixed-mode assembly is compiled with 'v2.0.50727' version of the
runtime and can not be loaded in the 4.0 runtime without additional
configuration information.
Im using Visual Studio 2010 Ultimate, Windows 7 Professional with .NET 4 Framework installed.
Any ideas ?

As Steve suggested there, add this in the console application App.config file
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>

Related

Dealing With Very Long Paths with .NET Framework

Problem: I am working on a program to take the output of tree and re create the directory structure on a different system. My code works for test sets of files that I have created at random. However when dealing with Systems with detailed/long folder names I run into a
System.IO.IOException '(the filename or extension is too long) on this code
String path = #".\" + PreviousDirectory + #"\";
int errorCheck = path.Length;
Directory.SetCurrentDirectory(path, PathFormat.LongFullPath);
Attempted Solutions:
I have found this thread which describes several options. I have tried many of these I am currently not using System.IO I am using AlphaAeonis.Win32.Filesytem which supposedly has support for 32,000 chars in a path however my error occurs on a path that is 282 chars long.
I am also attempting to use .Net Framework 4.6.2 or higher which removed the path limit. I changed my target framework to 4.6.2 in Visual Studio 2017 which I am using I also have .NET SDK 6.0.0 installed. My app.config file which controls how Visual studio runs the code this looks like this
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
<runtime>
<AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false"/>
</runtime>
If I change to anything except version = v"4.0" I am asked to install that version of .NET despite having higher version frameworks installed. I assume that the v4.0 is what is actually running.
Questions:
a. How can I ensure that all Directory functions use the Override from the imported Alphaleonis Library?
b. How can I ensure a minimum .Net Version upon Runtime?
c. What else could I set to allow long Paths?
The Solution was switching from .NET Framework to .Net Core.
Thank You to pcalkins

Winform images (ResourceManager) not visible on Windows 10

I have a Windows form application that works fine on Windows 7, but when opened in Windows 10, image files using ResourceManager don't show up. Application is using .Net 3.5 framework. Following is a bit of code:
static readonly System.Resources.ResourceManager rm = new System.Resources.ResourceManager("ImageResources", Assembly.GetExecutingAssembly());
rm.GetObject("ImageName");
Following is the error:
Could not find any resources appropriate for the specified culture or
the neutral culture. Make sure was correctly embedded or linked into
assembly at compile time, or that all the satellite assemblies
required are loadable and fully signed.
System.Resources.MissingManifestResourceException:
Is it due to some kind of incompatibility or Windows 10 is somehow restricting ResourceManager class to use all those images?
Try to check value of Environment.Version (with some MessageBox for example) on the target machine.
If you get 4.0 then you need to change configuration file as was proposed by Dr. Stich.
If you don't have configuration file then create it like described there:
How to: Add an Application Configuration File to a C# Project
And change it content to something like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727" />
</startup>
</configuration>
Runtime version you can get on supportedRuntime Element page
This issue was eventually resolved by adding CultureInfo.CurrentCulture in rm.GetObject method parameter i.e.
rm.GetObject("ImageName", CultureInfo.CurrentCulture);

Connect to Firebird database with c# asp.net throws type initializer exception

I am trying to open a connection to a Firebird database in my c# asp.net web application. It throws an error "The type initializer for 'FirebirdSql.Data.Common.TimeoutHelper' threw an exception."
I am new to Firebird.
In web.config I have:
<add name="FireBirdConnectionString" connectionString="Server=localhost;User=SYSDBA;Password=masterkey;Charser=NONE;Database=D:\data\SAMPLE.fdb" providerName="FirebirdSql.Data.FirebirdClient"/>
I have installed FirebirdSql.Data.FirebirdClient-4.5.1.0 and have added a namespace of
using FirebirdSql.Data.FirebirdClient;
I am opening the connection like below:
using (FbConnection con = new FbConnection(conString))
{
con.Open();
}
But this shows me an error as The type initializer for 'FirebirdSql.Data.Common.TimeoutHelper
What am I doing wrong?
I need to open the connection.
Even in connection string
and I have that path in my desktop too
Thank You..!
As I commented earlier, you are probably using the .NET 4.5 version in a .NET 4 project. You either need to switch your project to .NET 4.5 (which requires Visual Studio 2012 or 2013), or you need to replace the FirebirdSql.Data.FirebirdClient library with the .NET 4 version.
I'd suggest you use NuGet to install it, as this will verify - install time - which variant you need. Otherwise you need to pick the second link from http://www.firebirdsql.org/en/additional-downloads/ (iirc the first link only installs and includes the .NET 4.5 version).

Microsoft.Dynamics.BusinessConnectorNet mixed mode assembly error

"FileLoadException was unhandled by user code"
(Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information)
as the matter above.i got exception when try to execute
Axapta axapta;
AxaptaRecord axaptaRecord;
List<Vendor> vendors = new List<Vendor>();
public void Submit(Vendor vendor)
{
axapta = new Axapta();
axapta.Logon(null,null, null, null);
using (axaptaRecord = axapta.CreateAxaptaRecord("IDS_Pelajar"))
{
axaptaRecord.Clear();
axaptaRecord.InitValue();
axaptaRecord.set_Field("TenteraPolisNo", vendor.VendorAccount);
axaptaRecord.set_Field("Poskod", vendor.InvoiceAccount);
axaptaRecord.set_Field("Keturunan", vendor.Name);
axaptaRecord.Insert();
}
axapta.Logoff();
vendors.Add(vendor);
i already try to add this line of code in app.config
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
but still it doesn't work.
i have no problem to execute that block of code in console..the exception only pop up when i'm try to execute that block of code in WCF services library
sorry for trouble but i really loss now..Tq 4 help
Check if any of the below help you
Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information - Release Build
Handling Mixed Mode Assembly Error in WCF Service Host
Being WCF, I feel the 2nd link might prove useful. The config file for WCF Service host is located at C:\Program Files (x86)Microsoft Visual Studio 10.0Common7IDEWcfSvcHost.exe.config and hence making the change in this config file should fix it.
Hope this helps.

Tessnet2 error in C#

I am using Tessnet2 ocr in C# by following codes:
tessnet2.Tesseract ocr = new tessnet2.Tesseract();
ocr.SetVariable("tessedit_char_whitelist", "0123456789");
ocr.Init(Application.StartupPath + #"D:\\Program Files (x86)\\Visual Studio 2010\\Projects\\AForgeTest2\\AForgeTest2\\tessdata\\", "eng", true);
List<tessnet2.Word> result = ocr.DoOCR(numberTest, Rectangle.Empty);
string code = result[0].Text;
testBox1.Text = code;
but when I run the debug it shows the error message in the 5th line:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());//the line with error
}
FileLoadException was Unhandle:
Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.
Do you know how to solve this problem?
Kind Regards
Gav
Try adding
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
to your App.config.
This enables you to reference that DLL without having to change your entire project's framework version.
I think changing the target framework of your project from 4.0 to 2.0 will help.
See: Changing the Target .NET Framework Version or Profile for an Existing Project

Categories