.Net Framework 4.6.1 app Error: Google.Protobuf Could not load file or assembly - protocol-buffers

I created a proof of concept standalone .Net Framework 4.6.1 console app to test a TLS with Google Protobuf comms protocol. It worked ok until I moved comms code into a .Net Class library (DLL .Net Standard 2.0) and tried to load it from my main WPF .Net Framework 4.6.1 app. I get this exception:
System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'Google.Protobuf, Version=3.21.9.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604' or one of its dependencies. The system cannot find the file specified.
Source=SrvComms
StackTrace:
at SrvComms.Master..ctor() in C:\src\SrvComms\Master.cs:line 22
at SrvCommsTest.MainWindow..ctor() in C:\src\SrvCommsTest\MainWindow.xaml.cs:line 27
What magic or evil is at play?
Many thanks in advance for ideas and hopefully solutions that do not involve migrating to later .Nets.
Steve

ok, so the DLL also needs to be .Net Framework 4.6.1. Thank you.

Related

ASP.Net Core 2.2: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information

I recently started with ASP.Net Core 2.2. I have a situation where I need to use legacy SAP Connector library within my application. After some reading I created my application to target full .Net Framework 4.6.1. I have a test class that references the SAP Connector library.
However, when I run my application, it breaks within Startup.cs right where it calls this line:
app.UseMvc();
Checking the LoaderExceptions property, it shows the error:
Could not load file or assembly 'sapnco, Version=3.0.0.42, Culture=neutral, PublicKeyToken=50436dca5c7f7d23' or one of its dependencies. An attempt was made to load a program with an incorrect format.
My hunch is that although ASP.Net Core supports full .Net Framework, the referenced assembly has to go as far back to particular version of .Net Framework and no less. Although I can't find any concrete info on that.
Please help!
For SAP Connector, I think you need to contact SAP Forum Support to confirm if the SAP Connector .NET Core version is available or will be available.
From the perspective of .Net Core, I am afraid there are no connectors and no plans to develop such connectors.

Supporting an .Net Framework Lib in .Net Core 2.0 WebAPI - Error

so basicly out complete company dataaccess is based in .Net Framework 4.6.
We are only on windows, so no problems here atm.
We have a new project in which I want to use .Net Core 2.0 and WebAPI but I have to use this "old" .net Framework lib.
When I add the reference and start my project I will get an error:
Could not load type 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.'
As far as I googled it and understand, the dataasccess lib will try to get the win auth but this isnt available in .net core (obvious) any more.
I found the nuget Microsoft.Windows.Compatilibity and after installing the error is gone.
But another one comes up:
Exactly this error:https://community.oracle.com/thread/4139377
And the only solution to this seems to be to remove the MS.Win.Comp package...
So a bit of a circle.
Any ideas?

Lightweight Oracle support in .NET core

I'm trying to connect to an Oracle database from a containerable dotnet core application, and haven't been able to find a solution that allows me to do this that fits all of these criteria:
Runs in .NET Core 2.0
Doesn't require extra installation on the machine running it (which would make it not Docker compatible)
Is free
I've tried many different solutions, and none of them actually connect. Most of the NuGet packages target .Net Standard or .Net Framework 4.6.1. The ones that I've found that are the most promising seem to have a different targeting issue and result in the following error:
System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
Any suggestions?
Thank you for your time.
Oracle is now publishing an official Data Provider for .NET Core on nuget.

Windows CE project with libraries problem

I am developing a Windows CE application which uses some libraries provided by other parts of our company.
When I deploy my application on "My Computer" (.NET compact application running on standard PC), everything works, but when I deploy to the device, the application hangs when trying to use methods from the library. The system also hangs. My Visual Studio 2008 sometime hangs, but sometime throws an exception "TypeLoadException: Could not load type from assembly Culture=neutral, PublicKeyToken=nu".
I couldn't include .NET Compact framework 3.5 because the image wouldn't compile, so I am using version 2.0. I use Visual Studio 2008 with deploy .NET framework option.
Most probably the problem is with version of the library you are using. Please cross check it.
Hope this link will help you.
I'm a bit confused.
First of all, what are the libraries "provided by other parts of [y]our company" build against? Are they Compact Framework assemblies (they must be)? What version of the Framework were they build against? Reflector can tell you this if you don't know.
Second, why can't you compile it with 3.5? What sort of errors are you seeing? The code should be 100% forward compatible, so if it won't build, there's a red flag going up.
Lastly, what version of the CF is installed on the target hardware? FOr example, are you trying to push a CF 2.0 app to a device with CF 3.5 already installed? If so, do you have an app.config file that provides the framework compatibility options so it knows it can run your assembly?
The problem was that libraries were compiled with for 3.5 target framework, and the application which uses them form 2.0 framework. In that case, 3.5 framework wasn't depoloyed and application would stop working as soon as call to the library methods was made.

Reference issues in .NET 4.0 project to .NET 2.0 dll/project

I just starting to use Visual Studio 2010 and .NET 4.0. I created a new WPF project a DLL built for .NET 2.0. When I build the project, I get a bunch of warnings like this one:
The referenced assembly
"MicroFour StrataFrame Business...processorArchitecture=MSIL"
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.
When I reference a project I created that targets 3.5, it can't find any of the namespaces (during compile), though they show up in the object browser and intellisense correctly shows them.
Is there something I'm missing that needs to be done to reference an older .NET assembly?
There is very little point in targeting the client profile for .NET 4.0. The download is 41MB, the full version is 48MB, only 15% bigger. Unfortunately it is the default in VS2010, just change it with Project + Properties, Application tab, Target framework combo.
The client profile does make a lot of sense if you target 3.5, the full install is ~350 MB. The huge difference is explained by the prerequisites, .NET 4.0 requires at least XP SP3 or Vista SP1. But 3.5 installs on any version of Windows > 2000. The 3.5 installer thus contains lots of the required updates for unmanaged Windows components used by .NET. The web installer lessens that blow considerably btw.
Your 2.0 assembly has a reference to System.Web. The reference is being automatically forwarded to your target framework, 4.0. So it is attempting to use System.Web, version 4.0.0.0. The problem is with 4.0 (actually this started with 3.5), there is now the notion of a client profile. The client profile has a smaller set of reference assemblies, anything web/server related has been removed. This is to make the .NET framework a smaller/simpler download for end users.
With VS 2010 and .NET 4, the client profile is being pushed a lot harder, MS really wants us to use it. So your .NET 4 project is targeting the client profile by default. Your referenced assembly wants System.Web, so in that case you need to switch to the full profile.

Resources