.NET 4 vs .NET 3.5 C# application. Could not load file or assembly 'x' or one of its dependencies. The specified module could not be found - visual-studio-2010

I have a C# WPF application built in VS 2010 with Target Platform set to x86. This exe calls on a Managed DLL with target platform ANYCPU. The Managed DLL has a reference to a C++ DLL which is compiled with Common Language Runtime Support (/clr) option.
On .NET 3.5 the app works perfectly with on any OS. It works fine on Win 7 as well, on both 32bit and 64 bit.
Now that I have converted the application and its DLLs to target .NET 4. If it is run on a .NET less than 4, it throws an error that .NET 4 is required which is the expected result.
The converted app works fine on my development system and on any system that has .NET 4 + .NET 3.5. So far so good!
However, on systems with ONLY .NET 4 (ie Win 8) or win 7 without .NET 3.5, I get the error:
Could not load file or assembly 'x' or one of its dependencies. The specified module could not be found.
'x' is the C++ dll compiled with Language Runtime Support (/clr) option.
So, in short the problem only happens on systems with .NET 4 only.
Any advice would be appreciated.
Thank you,
- Kam

.NET 4 has back compatibility with all previous versions. So it doesn't seem the problem is in the platform version. Might it be folder's security? Try to check its permissions.

There was a change in native code loading policies since .NET 4. To resolve this, please add the App.config file to your .exe project with the following contents:
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
</startup>
</configuration>
This discussion may also help: What does 'useLegacyV2RuntimeActivationPolicy' do in the .NET 4 config?

Related

FSharp.Core for Windows Phone 7.1 and F# 3.0

The F# 2.0 distribution had a version of FSharp.Core compiled for WindowsPhone 7.1/Silverlight 4, but F# 3.0 doesn't, and the portable version only supports Silverlight 5 or Windows Phone 8. Has anyone been able to compile a version of FSharp.Core for F# 3.0 targeting Silverlight 4 or Windows Phone 7.1 from source? What are the defines required?
Edit:
On the fsharp compiler github repo, there's a target named portable-net4+sl4+wp71+win8, but in reality that's portable class library Profile47, which supposedly only support .NET 4.5, Silverlight 5.0 and Windows Store apps. It's the same as what's installed with VS2012. If you try to use it with a WP 7.1 project, it will fail at runtime complaining about missing IStructuralEquatable. It should really be named portable-net45+sl5+win8. There's a wp7 target also in the proj files, but it's currently not compiling
I managed to compile it, but since I don't normally use F#, I don't know how to test it. Have you followed the instructions for compiling? Just type the following commands in the VS Developer Prompt
cd src
msbuild fsharp-proto-build.proj
msbuild fsharp-library-build.proj
msbuild fsharp-compiler-build.proj
msbuild fsharp-library-build.proj /p:TargetFramework=portable-net4+sl4+wp71+win8
Note that I did it with Visual Studio 2012 Professional. If you want, I can send you compiled dll and you can try it.
Got both the wp7 target and Portable88 target compiling from F# source after a couple of changes https://github.com/ovatsus/fsharp
Still need to thoroughly test at runtime, though

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.

Visual Studio 2010 managed c++ targets .NET 2.0 PROBLEM

For someone who's been down this road, please share your breadcrumbs.
I have old VS2005 solution. Most of the parts are c# but I have one c++ managed project. Dev machine: Windows XP. Target framework version: 2.0
I moved the project to the Windows 7 64 BIT, VS 2010, did the project conversion. First thing I noticed were build errors - projects depending on one what is in c++ complained that project referenced has target 4.0 and I want to use it in project that (properly) targets 2.0.
OK, so I used some tips and set my project target to .NET 2.0. NOW: VS2010 complains that it cannot load the project because I need to install framework 2.0. OK, so I try to install it, and nothing - since installer detects .NET 2.0 as a part of the operating system.
WTF?
Admins, please create WTF tag for me here :)
It is not the .NET version that's the problem. The C++ build system currently does not directly support building for pre-.NET 4.0 targets. It requires VS2008 to be installed so it can use its tool chain. Sounds like you don't have it.
This blog post explains the workaround. You can upvote this feedback article if you're unhappy with that. No idea if this is slated to be fixed in SP1, this is not drawing a lot of votes.

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.

Warning - Targets a different processor than the application

My .NET 3.5 WPF application has started showing a bunch (14) of the the following warning (with different dlls):
Referenced assembly 'C:\WINDOWS\assembly\GAC_32\Microsoft.TeamFoundation
\9.0.0.0__b03f5f7f11d50a3a\Microsoft.TeamFoundation.dll'
targets a different processor than the application.
I am running on a 32 bit machine. The only project in my solution is set to compile to "Any CPU". (A rebuild all does not fix it.)
I would rather not recreate my solution. Does anyone else know another fix/workaround for this issue?
NOTE: I am using Visual Studio 2008 SP1 and Windows XP 32 bit.
Haven't seen that one specifically but the download samples for C++ by default build for Itanium - did you install the wrong version of those libs?

Resources