NGEN'd assemblies not being loaded - visual-studio-2010

I'm trying to measure the performance impact of NGENing my assemblies versus not but I am unable to get my executable to load the NGEN assemblies. I ran the following from the VS2010 command prompt:
ngen install MyApp.exe
This completed without any issues and I verified that all my dependency assemblies had been created in the C:\Windows\assembly\NativeImages_v4.0.30319_32\MyCompanyName# directory.
I then launched my app and looking at Process Explorer, it was loading all my assemblies from the local binaries directory instead of loading the *.ni.dll files from the NativeImages_x folder. I logged the bindings using fuslogvw. Here is a sample log entry:
*** Assembly Binder Log Entry (6/29/2011 # 10:14:04 AM) ***
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable C:\Path\To\My\Binaries\MyCompanyName.MyApp.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = username
LOG: DisplayName = MyCompanyName.MyAssembly, Version=1.0.2.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Path/To/My/Binaries/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyCompanyName.MyApp.exe
Calling assembly : MyCompanyName.AnotherAssembly, Version=1.0.2.0, Culture=neutral, PublicKeyToken=null.
===
LOG: Start binding of native image MyCompanyName.MyAssembly, Version=1.0.2.0, Culture=neutral, PublicKeyToken=null.
WRN: No matching native image found.
LOG: IL assembly loaded from C:\Path\To\My\Binaries\MyCompanyName.MyAssembly.dll
Does anyone have any thoughts on what is going on here? I verified that the native assembly in question exists at:
C:\Windows\assembly\NativeImages_v4.0.30319_32\MyCompanyName#\3a041121abf7fbdce89836c32f2d217e\MyCompanyName.MyAssembly.ni.dll
Why isn't it binding it correctly? FWIW, the application uses MEF quite a bit; I don't know if that would affect the loading of the assemblies.

It's because of using MEF. NGEN is only able to follow assembly references. But if you use MEF then you probably don't refer all the assemblies because MEF is responsible to load them dynamically at runtime.
Your approach is the right one. Call all assemblies with NGEN.
ngen install c:\myfiles\MyLib.dll /ExeConfig:c:\myapps\MyApp.exe
In this case you need to remove these assemblies manually from the cache when the application is uninstalled.
ngen uninstall c:\myfiles\MyLib.dll /ExeConfig:c:\myapps\MyApp.exe
See also: http://msdn.microsoft.com/en-us/library/6t9t5wcf(v=vs.100).aspx

I don't know what the actual issue was but the solution was to write a batch file that simply NGEN'd every binary in the directory. I guess there were binaries that were not being NGEN'd when running just the ngen install command on the top-level exe.

Related

CLR is attempting to load an assembly from the wrong location for .sqlproj

I recently moved from VS 2017 to VS 2019. Since upgrading I've been unable to open any .sqlproj projects in VS as they all refuse to load with the error -
Could not load file or assembly
'Microsoft.SqlServer.Management.SqlParser, Version=15.100.0.0,
Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its
dependencies. The system cannot find the file specified.
Here's the interesting part. The Fusion Log shows me -
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.SqlServer.Management.SqlParser, Version=15.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///c:/program files (x86)/microsoft visual studio/2019/enterprise/common7/ide/extensions/microsoft/sqlcommon/130/Microsoft.SqlServer.Management.SqlParser.dll.
LOG: Assembly download was successful. Attempting setup of file: c:\program files (x86)\microsoft visual studio\2019\enterprise\common7\ide\extensions\microsoft\sqlcommon\130\Microsoft.SqlServer.Management.SqlParser.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: Microsoft.SqlServer.Management.SqlParser, Version=13.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: The assembly reference did not match the assembly definition found.
I read this as :
I need to load version 15 of this dll
It's not in the GAC
I am going to look under the ...sqlcommon\130 directory
I've found the dll
It's the wrong version, 13 not 15
I can see the dll under the c:\program files (x86)\microsoft visual studio\2019...\sqlcommon\150 directory which (I think) should be the correct version. Anyone have any idea why is it probing the 'wrong' directory and how can I get it to look in the correct one?
Any pointers in the right direction whould be hugely appreciated.

TFS2015 Visual Studio Test: Could not load file or assembly

I have an "old" XAML Build Definition, made in Visual Studio; which builds a solution and following runs unit tests.
Now I've tried to make the same in the new TFS 2015 web surface.
I've created a build task, following Visual Studio Test.
But now the Test-Task exit with code 1 and gives me a lot of
"System.IO.FileNotFoundException: Could not load file or assembly" errors.
And also "Warning: MSTestAdapter failed to discover tests in class ..."
All the DLLs are where they have to be, the new definition has the same directory structure like the old one, but the test-task says there are missing assemblys.
Any ideas?
Update:
No, I still have the same error messages:
Warning: Unable to load types from the test source 'J:\xyz-Tests.dll'. Some or all of the tests in this source may not be discovered. If you are running unit tests for Windows Store apps and referencing custom WinMD type then please visit http://go.microsoft.com/fwlink/?LinkId=238340 for more info. Error details: System.IO.FileNotFoundException: Could not load file or assembly 'xyz_Commons, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
System.IO.FileNotFoundException: Could not load file or assembly 'xyz_Processing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
System.IO.FileNotFoundException: Could not load file or assembly 'xyzCommons, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
This should exactly be the issue mentioned in below article, please try following the workaround to fix it:
Running Coded UI Tests built using Visual Studio 2013 with Team Foundation Server 2015
Test execution is failing in this scenario because test execution
engine is not able to resolve the old version binaries while executing
tests in a 14.0 environment (TFS 2015).
So, you need to update the projects to reference the new versions of the assemblies (VS 2015 in this scenario) using the assembly bindings in the test projects config file.
As a workaround to this issue, add an ‘app.config’ file to your
solution (See how to add app.config
https://msdn.microsoft.com/en-in/library/ms184658.aspx) and update the
contents of the file with the shared on OneDrive . The updated
configuration files contain assembly redirects from version 12.0 to
14.0, which will make sure that the test agent machine is able to resolve the framework assemblies. Check-in the updated configuration
file into the source control repository and run the BDT scenario once
again. The tests should run fine this time. If the test execution
again throws an error complaining version mismatch for some other
assembly, add the assembly to the app.config file and retry.
You can also reference this article :
http://www.dotnetcatch.com/2015/10/01/tfs-2010-to-2015-upgrade-codedui-feature-test-builds/

System.IO.FileNotFoundException: Could not load file or assembly 'Oracle.DataAccess, ... when running unit tests

I'm trying to run some unit tests that perform execute some SQL commands directly to an Oracle database and I get the following exception when the unit tests are started:
Testmethod1 threw exception:
System.IO.FileNotFoundException: Could not load file or assembly 'Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. The system cannot find the file specified.
I have Oracle.DataAccess in the project references (added through NuGet) and I have I have the Oracle Data Provider installed.
I even have some other projects using Oracle.DataAccess that run in this machine without problems. It seems that only Microsoft.Net Unit Test Framework (MSTest) is not able to load the assembly.
This is the log taken from Fusion Log Viewer:
*** Assembly Binder Log Entry (23/08/2013 # 04:50:07 p.m.) ***
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\QTAgent32_40.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = ...
LOG: DisplayName = Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342
(Fully-specified)
LOG: Appbase = file:///...C:/<solution_folder>.../TestResults/.../Out
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = QTAgent32_40.exe
Calling assembly : ...<project_name>..., Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\...<solution_folder>...\TestResults\...\Out\...<project_name>....DLL.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/...<solution_folder>.../TestResults/.../Out/Oracle.DataAccess.DLL.
LOG: Attempting download of new URL file:///C:/...<solution_folder>.../TestResults/.../Out/Oracle.DataAccess/Oracle.DataAccess.DLL.
LOG: Attempting download of new URL file:///C:/...<solution_folder>.../TestResults/.../Out/Oracle.DataAccess.EXE.
LOG: Attempting download of new URL file:///C:/...<solution_folder>.../TestResults/.../Out/Oracle.DataAccess/Oracle.DataAccess.EXE.
LOG: All probing URLs attempted and failed.
It states the assembly was not found in the GAC, but I did found it: C:\Windows\Microsoft.NET\assembly\GAC_64\Oracle.DataAccess\v4.0_4.112.3.0__89b483f429c47342\Oracle.DataAccess.dll\
It's also worth noting is that the above log shows QTAgent32_40.exe even though I have selected in Visual Studio menu TEST -> Test Settings -> Default Processor Architecture -> X64. Before doing so I was getting a BadImageFormatException instead.
Additional notes:
The Oracle Data Provider that I have installed is the 64 bit version.
The reference already has Copy Local=True
Found the problem.
There was a .testsettings file forcing the tests to be run in 32 bit mode regardless of me selecting TEST -> Test Settings -> Default Processor Architecture -> X64.
The weird thing is that if I select X86 I get the proper BadImageFormatException at runtime, while if the architecture is forced in the .testsettings file I get FileNotFoundException, which is a little misleading.

Cannot open VSTO 2005/Excel 2003 customization files after migrated to VSTO2010

I have a Excel Document level customization project that was build using VSTO 2005 that uses Excel 2003 template (xlt). Now I have migrated to VS2010 (.NET4) and Excel 2007 environment.
My application is a reporting tool that users can create Excel reports using the customization. So currently they have number of existing *.xls and *.xlsx reports.
My problem is after I have migrated my solution to VSTO2010, I cannot open previously created reports. It givesthe error,
Could not load file or assembly 'MyApp.BusinessAnalytics, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=ff90f512e10aef0d' or one of its dependencies. This
assembly is built by a runtime newer than the currently loaded runtime and cannot be
loaded.
I am using MSI in order to install the application.
When I compared the application reports that created using VS2005 version and VS2010 version I have noticed the '_AssemblyName', '_AssemblyLocation' and 'Solution ID' is different in 2 versions. For an example, 2005/Excel 2003 version has * for _AssemblyName but 2010 has '4E3C66D5-58D4-491E-A7D4-64AF99AF6E8B'.
I have enabled the assembly binding log. and observed the assembly binding exception using fuslogvw.exe
The entry in Assembly binding log:
*** Assembly Binder Log Entry (8/3/2011 # 11:57:28 AM) ***
The operation failed.
Bind result: hr = 0x8013101b. No description available.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.EXE
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = CORPNET\vohelk
LOG: DisplayName = Ifs.Application.BusinessAnalytics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ff90f512e10aef0d
(Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/IFS Applications/IFS Business Analytics/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : (Unknown).
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Program Files (x86)\IFS Applications\IFS Business Analytics\Ifs.Application.BusinessAnalytics.dll.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework \v2.0.50727\config\machine.config.
LOG: Post-policy reference: Ifs.Application.BusinessAnalytics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ff90f512e10aef0d
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/IFS Applications/IFS Business Analytics/Ifs.Application.BusinessAnalytics.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Program Files (x86)\IFS Applications\IFS Business Analytics\Ifs.Application.BusinessAnalytics.dll
LOG: Entering download cache setup phase.
ERR: Error extracting manifest import from file (hr = 0x8013101b).
ERR: Setup failed with hr = 0x8013101b.
ERR: Failed to complete setup of assembly (hr = 0x8013101b). Probing terminated.
Do you have any clue on this. Greatly appreciate your help regarding this.
Notice that in your fushion log the assembly manager is still from v2.0 (This is where the message comes from since it is trying to load a v4 assembly inside the v2 runtime)
Upgrading requires a bit more work than simply opening it in vs2010 especially if you move to framework V4. A quick workaround for you could also be to target framework 3.5 instead of 4
How and what you need to change depends on where you are coming from and what you are using. Have a look at these two msdn documents on upgrading and review those steps carefully for your scenerio. It's a bit of a read but I experienced it as pretty complete and useful.
Upgrading and Migrating Office Solutions
and
Migrating Office Solutions to the .NET Framework 4

Error building project with XNAnimationPipline.dll and XNA3.1

I have a model with 2 animations, created in Blender and exported to fbx.
Referencing the XNAnimation.dll works, however when I reference the XNAnimationPipline.dll in the Content project I get a build error.
The "BuildContent" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load file or assembly 'XNAnimationPipeline, Version=0.7.0.0, Culture=neutral, PublicKeyToken=0c21691816f8c6d0' or one of its dependencies.
The system cannot find the file specified.
File name: 'XNAnimationPipeline, Version=0.7.0.0, Culture=neutral, PublicKeyToken=0c21691816f8c6d0'
I have recently upgraded to XNA3.1 and am using the latest XNAnimation library.
Any ideas?
Thanks
Rebuilding the source code sorts it out
This explains

Resources