Why can't I reference the project I created earlier from my wcf service class library? - asp.net

Warning 1 The referenced assembly "C:\Users\rzv\Desktop\CompanyAnalyse1.0\AnalyserModel\bin\AnalyserModel.dll" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project.
Why do I get this? AnalyserModel is a class library that uses Entity framework code first 5 to save data in a database. I tryed to create a new WCF service application that uses the methods in AnalyserModel. What is wrong?

You need to change the target framework from 4.0 client profile to 4.0.
you can do this on the projects properties page.

Related

GetType.Equals(typeof(Type)) return false in .Net Core but not in .Net Framework

Ola,
just migrated to .Net Core and Type.Equals seem to return false even though the types are equal.
The debugger gives the following info:
The First Instance:
typeof(ExcelImportLoaderConfig): {Name = "ExcelImportLoaderConfig" FullName = "DatenMeister.Excel.Helper.ExcelImportLoaderConfig"}
typeof(ExcelImportLoaderConfig).Assembly {DatenMeister.Excel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null}
typeof(ExcelImportLoaderConfig).Assembly.Location
"...\netcoreapp3.0\DatenMeister.Excel.dll" - same path
The Second Instance:
configuration.GetType() {Name = "ExcelImportLoaderConfig" FullName = "DatenMeister.Excel.Helper.ExcelImportLoaderConfig"}
configuration.GetType().Assembly {DatenMeister.Excel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null}
configuration.GetType().Assembly.Location "...\netcoreapp3.0\DatenMeister.Excel.dll" - same path
The Comparison
(configuration is ExcelImportLoaderConfig): false
THIS WAS TRUE IN .NET FRAMEWORK and is now false in .Net Core 3.0
Is there a change between .Net Framework and .Net Core?
[EDIT]:
m_cache and m_handle are different between (configuration.GetType() and typeof(ExcelImportLoaderConfig))...
MetadataToken is the same...
Further Information:
configuration is created via 'configuration = new ExcelImportLoaderConfig(); (with reference to the .Net Standard assembly below)
typeof(ExcelImportLoaderConfig) is called within a .Net Standard assembly
[EDIT 2]
Same problem with .Net Core 3.1
.dll creating the instance of ExcelImportLoaderConfig is a .Net Standard 2.0 (netstandard2.0) .dll
The .dll checking the instance is also a .Net Standard 2.0 which also contains the declaration of ExcelImportLoaderConfig.
Got it!
The file was referenced in the main project but the type was not used.
There is a PluginLoader which loads all assemblies via 'Assembly.LoadFile' within the directory.
So, this happened:
The PluginLoader loads the Assembly directly via Assembly.LoadFile. The check now included the type checking of to the explicitly loaded assembly. #1
Later, within the application, a function uses the referenced assembly which uses the reference assembly (even though, it has the file). But internally, the assembly seems to be loaded twice. #2
The application creates an instance of the class via #2 and calls a function within the explicitly loaded assembly #1. ExcelImportLoaderConfig, loaded via Assembly.LoadFile #1, is not the same as loaded via ProjectReference #2...
This behavior is different between .Net Core and .Net Framework
Further information given under
https://github.com/dotnet/runtime/issues/36787
Assembly Loading via ProjectReference and Assembly.LoadFile upon same file leads to two instances #36787

Getting 'could not load file or assembly' error in .NET Core 2.0

I am getting the below error:
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.'
What I did:
Created new project in .NET Core 2.0.
Added project reference of class library built out in .Net framework 4.6.1.
Access function from class library which is using System.Data.OracleClient for database connection.
But it's failing while invoking function with above error.
How do we support accessing old .NET libraries built out earlier with lot of internal references in .NET Core project?
Unfortunately, you cannot.
Your project built with .NET Core must have only libraries built for .NET Core. You can't use the one built for .NET Framework.
Here is a quote from the book ASP.NET Core in Action when deciding to develop with .NET Core rather than .NET Framework:
The largest obstacle you’re likely to come across is a third-party
library holding you back, either because they only support older
ASP.NET features, or they haven’t been converted to work with .NET
Core yet.

Could not load type 'System.Data.Common.DbProviderFactories' from assembly 'System.Data'

First of all some context: my project exists out of a common project that contains all the DAL stuff and a web project. Now the common project is written in .NET framework 4.5 while the web project is written in .NET Core 2.0.
When trying to acces the repositories of the DAL project I get following error:
Could not load type 'System.Data.Common.DbProviderFactories' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Now I'm not sure what to do now. I have added the System.Data.Common nuGet package to my web project, but without succes. How can I slove this problem preferably without altering the common DAL project? Thanks in advance.

Type.GetCustomAttributesData() not defined in .NET Core

What is the new equivalent for Type.GetCustomAttributesData() in .NET Core?
I can't access this method when porting a project from .Net Framework. It doesn't become available with any of the Reflection NuGets.
This turned into Type.GetTypeInfo().Assembly.CustomAttributes. One would see this and think it is a property that, similar to GetCustomAttributes() returns IEnumerable<Attribute>, but it returns IEnumerable<CustomAttributeData>.
According the APIsOf.Net, MemberInfo.GetCustomAttributes method will be available in .Net Core 2.0, assembly System.Runtime, Version=4.2.0.0, PublicKeyToken=b03f5f7f11d50a3a
For now you can try the MemberInfo.CustomAttributes property in assembly System.Reflection, Version=4.1.0.0, PublicKeyToken=b03f5f7f11d50a3a

Why is my project failing to reference the System.ComponentModel assembly?

My project is set to .NET Framework 4.5. I get the following error when attemping to use SimpleIOC (from MVVM Light) in my WPF project:
Error 3 Reference required to assembly 'System.ComponentModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' containing the implemented interface 'System.IServiceProvider'. Add one to your project.
I can't figure out why it's giving me this error. From what I understand, this is a mscorlib class so I'm not sure where it is getting System.ComponentModel from.
I can write Dim test As IServiceProvider without the compiler complainging. Is there some kind of version issue?
It seems like a possible Visual Studio bug. I created a new WPF project and was able to find the System.ComponentModel.dll in the list of .Net Framework assemblies. For my current project, I ended up browsing to it to add a reference to it. All is well now.

Resources