Just starting out with C# (using VS2008) - am an experienced Java, C++, VC++, VB programmer.
I downloaded an assembly (I guess) from codescales.com; it's a dll.
In my (new) C# project, I added this dll as a Reference -- by browsing to it. I got intellisense working for it, and coded-up a simple example to test it, but everytime I hit the VS "Debug", I get the following Exception. Do I need to "register" or do something to this downloaded DLL to use it properly in my project? (VS seems to copy it to the output dir automatically on build.)
Thanks in advance,
AJ
System.IO.FileNotFoundException was
unhandled Message="Could not load
file or assembly 'CodeScales.Http,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' or one of its
dependencies. The system cannot find
the file specified."
Source="ocrTest1"
FileName="CodeScales.Http,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null" FusionLog="===
Pre-bind state information ===\r\nLOG:
User = CAPTURESDK-VM\XXXXX\r\nLOG:
DisplayName = CodeScales.Http,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null\n
(Fully-specified)\r\nLOG: Appbase =
file:///C:/Documents and
Settings/XXXXX/My Documents/Visual
Studio
2008/Projects/ocrTest1/ocrTest1/bin/Debug/\r\nLOG:
Initial PrivatePath = NULL\r\nCalling
assembly : ocrTest1, Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=null.\r\n===\r\nLOG:
This bind starts in default load
context.\r\nLOG: No application
configuration file found.\r\nLOG:
Using machine configuration file from
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.\r\nLOG:
Policy not being applied to reference
at this time (private, custom,
partial, or location-based assembly
bind).\r\nLOG: Attempting download of
new URL file:///C:/Documents and
Settings/XXXXX/My Documents/Visual
Studio
2008/Projects/ocrTest1/ocrTest1/bin/Debug/CodeScales.Http.DLL.\r\nLOG:
Attempting download of new URL
file:///C:/Documents and
Settings/XXXXX/My Documents/Visual
Studio
2008/Projects/ocrTest1/ocrTest1/bin/Debug/CodeScales.Http/CodeScales.Http.DLL.\r\nLOG:
Attempting download of new URL
file:///C:/Documents and
Settings/XXXXX/My Documents/Visual
Studio
2008/Projects/ocrTest1/ocrTest1/bin/Debug/CodeScales.Http.EXE.\r\nLOG:
Attempting download of new URL
file:///C:/Documents and
Settings/XXXXX/My Documents/Visual
Studio
2008/Projects/ocrTest1/ocrTest1/bin/Debug/CodeScales.Http/CodeScales.Http.EXE.\r\n"
There's a name mismatch, not sure how that happened. Remove the assembly reference. Rename the DLL you downloaded from CodeScales.Http.V0.14.dll to CodeScales.Http.dll. Then add the reference back.
You need to change Framework. Go to 'Properties' and the change '.Net Framework 4 Client profile' to '.Net Framework 4'.
Related
I've already been through this answer on S.O. but it really doesn't seem to solve my issue - this is not a complex multi-project web solution.. it's much smaller and doesn't really need binding redirects as there aren't multiple projects vying for the same DLL reference.
For the project in question: we own the source code, we have the Visual Studio Project files, the DLLs in question here are wholly owned and wholly known.. we have access to the history of the code in SVN.
In short, I wanted to upgrade a DLL that we once-upon-a-time would drop into another project, manually.. I want to turn it into a NuGet on our private feed. I've done this a hundred times.. no big deal.
The DLL is a fairly simple .NET 4 framework code and has no other dependencies
But when I 'nugetize' the project and then reference it in another project, it cannot be 'found' successfully at run time. I get this error when we go to invoke the class contained within it:
Could not load file or assembly 'MyCorp.DataAccessLayer, Version=1.3.0.0, Culture=neutral, PublicKeyToken=e5ee1faf2523c727' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
If I go into debug mode, visual studio shows this in the FusionLog property of the error intellisense:
=== Pre-bind state information ===
LOG: DisplayName = MyCorp.DataAccessLayer, Version=1.3.0.0, Culture=neutral, PublicKeyToken=e5ee1faf2523c727
(Fully-specified)
LOG: Appbase = file:///C:/MyCorpRepository/MyCorp.AttachmentManager/Trunk/MyCorp.AttachmentManager.Tests/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : MyCorp.DefaultAttachmentManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\MyCorpRepository\MyCorp.AttachmentManager\Trunk\MyCorp.AttachmentManager.Tests\bin\Debug\MyCorp.AttachmentManager.Tests.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: MyCorp.DataAccessLayer, Version=1.3.0.0, Culture=neutral, PublicKeyToken=e5ee1faf2523c727
LOG: Attempting download of new URL file:///C:/MyCorpRepository/MyCorp.AttachmentManager/Trunk/MyCorp.AttachmentManager.Tests/bin/Debug/MyCorp.DataAccessLayer.DLL.
WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
What do I need to look at to pinpoint the problem?
I've created a .NET standard library 2.0 which uses Microsoft.Data.SqlClient Version=1.12.20106.1. I'm referring to this library in the console application (.NET Framework 4.7.2). While making call, I'm getting the error shown below, even though I've added an assembly reference. Can anyone help please?
Could not load file or assembly 'Microsoft.Data.SqlClient, Version=1.12.20106.1, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5' or one of its dependencies. The system cannot find the file specified.":"Microsoft.Data.SqlClient, Version=1.12.20106.1, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5"}
Chances are that in the full error you will see something like
The located assembly's manifest definition does not match the
assembly reference. (Exception from HRESULT: 0x80131040)
When I experience a similar problem and run a unit test in the debugger then I see this sort of thing in the unit test output Pre-bind state information
Pre-bind state information
LOG: DisplayName = Microsoft.Data.SqlClient, Version=2.0.20168.4, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5
(Fully-specified)
LOG: Appbase = file:///C:/Dev2/MyApp/UnitTests/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : MyApp, Version=1.0.0.2, Culture=neutral, PublicKeyToken=c.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Dev2\myapp\UnitTests.dll.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 2.0.20168.4 redirected to 1.12.20106.1.
LOG: Post-policy reference: Microsoft.Data.SqlClient, Version=1.12.20106.1, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5
LOG: Attempting download of new URL file:///C:/Dev2/MyApp/UnitTests/bin/Debug/Microsoft.Data.SqlClient.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
The issue is an assembly binding issue the answer here may help. Don't worry that it mentions VB6 the actual issue is independent of that.
This answer is only useful if your netstandard2.0 library has referenced Microsoft.Data.SqlClient as a NuGet package and the referred assembly is not copied over on build.
You may have to use dotnet publish to have the Microsoft.Data.SqlClient assembly copied. It's something that I stumbled upon lately and that I had to fix using a custom resolver. You shouldn't use that resolver but you should check if publishing your application and library helps the issue.
I've updated my Visual Studio Code this morning, after doing update it restarted it self. I did not get any options(i.e. "Goto Definition", "Rename Symbol")when I right click on any variable, method, class name. After searching for a while I found that Opening View > Output might help me to know what's going on. and I found Omniserver is not running and below is the error which I got in Output window.
Starting OmniSharp server at 4/17/2019, 2:42:04 PM
Target: d:\projects\Division\Division.sln
OmniSharp server started.
Path: C:\Users\Unity3\.vscode\extensions\ms-vscode.csharp-1.19.0\.omnisharp\1.32.18\OmniSharp.exe
PID: 7508
System.IO.FileNotFoundException: Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
File name: 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
at OmniSharp.Stdio.Driver.Program.<>c__DisplayClass0_1.<Main>b__1()
at OmniSharp.HostHelpers.Start(Func`1 action)
=== Pre-bind state information ===
LOG: DisplayName = netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
(Fully-specified)
LOG: Appbase = file:///C:/Users/Unity3/.vscode/extensions/ms-vscode.csharp-1.19.0/.omnisharp/1.32.18/
LOG: Initial PrivatePath = NULL
Calling assembly : Microsoft.Extensions.Logging.Abstractions, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Unity3\.vscode\extensions\ms-vscode.csharp-1.19.0\.omnisharp\1.32.18\OmniSharp.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
LOG: Attempting download of new URL file:///C:/Users/Unity3/.vscode/extensions/ms-vscode.csharp-1.19.0/.omnisharp/1.32.18/netstandard.DLL.
LOG: Attempting download of new URL file:///C:/Users/Unity3/.vscode/extensions/ms-vscode.csharp-1.19.0/.omnisharp/1.32.18/netstandard/netstandard.DLL.
LOG: Attempting download of new URL file:///C:/Users/Unity3/.vscode/extensions/ms-vscode.csharp-1.19.0/.omnisharp/1.32.18/netstandard.EXE.
LOG: Attempting download of new URL file:///C:/Users/Unity3/.vscode/extensions/ms-vscode.csharp-1.19.0/.omnisharp/1.32.18/netstandard/netstandard.EXE.
[ERROR] Error: OmniSharp server load timed out. Use the 'omnisharp.projectLoadTimeout' setting to override the default delay (one minute).
I had the same problem with Omnisharp v1.19.0 after updating VSCode. I ended up resolving it by rolling back the C# extension to an earlier version that worked for me (1.18.0). Right click the extension and select Install Another Version... Hope this helps!
The rollback to 1.18.0 worked for me, but be sure to set the preference "extensions.autoUpdate" to false or it will just reinstall 1.19.0
It looks like that the depencencies of VSCode C# plugin were missing.
When you reinstall C# plugin, the dependencies will be re-downloaded. May solve this problem.
Latest OmniSharp requires .NET 4.7.2 to be installed, see https://github.com/OmniSharp/omnisharp-roslyn/blob/master/CHANGELOG.md#13214---2019-04-08
Disclaimer, this solution worked for Ubuntu Linux v20.04
I installed mono-devel from Here and everything worked.
I have an MVC login page, and I'm trying to use some .DLLs which I've already created for other purposes. These .DLLs are really plugins and they are located in a /CorePlugins folder in my webpage and loaded dynamically at run time via PreApplicationStartMethod. Here is how I'm loading these .DLLs:
var corePluginAssemblyFiles = CorePluginsFolder.GetFiles("*.dll", SearchOption.AllDirectories);
foreach (var assemblyFile in corePluginAssemblyFiles)
{
var assembly = Assembly.LoadFile(assemblyFile.FullName);
System.Web.Compilation.BuildManager.AddReferencedAssembly(assembly);
}
Now, among these plugins, I'm actually able to reference back and forth any which way I want and everything works fine. But, when trying to use one from my login page LoginController (which is in the /bin folder and not the /CorePlugins folder) it says that it cannot find the .Dll in question:
Could not load file or assembly 'Core.API.UserMgmt, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The network path was not found.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'Core.API.UserMgmt, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The network path was not found.
Source File: C:\svn\HomeCenter_DEV\HomeCenter\HomeCenter.Core\Controllers\LoginController.cs Line: 202
Assembly Load Trace: The following information can be helpful to determine why the assembly 'Core.API.UserMgmt, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' could not be loaded.
=== Pre-bind state information ===
LOG: DisplayName = Core.API.UserMgmt, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/svn/HomeCenter_DEV/HomeCenter/HomeCenter.Core/
LOG: Initial PrivatePath = NULL
Calling assembly: HomeCenter.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\svn\HomeCenter_DEV\HomeCenter\HomeCenter.Core\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: The same bind was seen before, and was failed with hr = 0x80070035.
So just for giggles I placed a copy of the .DLL in the /bin folder as well, and low and behold it said it can't load the assembly because its already loaded. So now I'm thinking what the hell. So using some test code I printed out the loaded assemblies from System.Web.Compilation.BuildManager.GetReferencedAssemblies() and from AppDomain.CurrentDomain.GetAssemblies() and I do in fact see the .DLL I'm trying to use Core.API.UserMgmt, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. So whats going on here? Why can't it find the DLL that has clearly already been loaded. If I place the .dll in the /bin folder and remove it out of the /CorePlugins folder, it works, but then everything else that I have set up breaks. I need the .dll to be in the /CorePlugins folder.
I can't quite remember which post I found that lead me to solving this, but essentially adding a probing element to assemblyBinding section in my Web.Config is what solved this for me.
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="folder\subFolder1;folder\subFolder2;folder\subFolder3" />
<!-- Other stuff -->
</assemblyBinding>
I had to add the root folder of every DLL I wanted to include because I couldn't figure out how to get it to recursively traverse the directory.
I have a COM object that is referenced in my project. When I build the project with target framework 4.5 everything works. However if I change the target framework to 3.5 (or 2.0), the code throws an exception when trying to instantiate the class using DLLName.exe (I presume it is an ActiveX EXE)
The following is the error (I translated it from a foreign language so it may not be exact):
System.BadImageFormatException: Could not load file or assembly 'Interop.DLLname, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
File name: 'Interop.DLLname, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
....
Assembly loaded from: C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under file execution C:\Users\Admin\Documents\Visual Studio 2012\Projects\....t\bin\Debug\EXEname.vshost.exe
#NAME?
=== Pre-bind state information ===
LOG: User =
LOG: DisplayName = Interop.DLLname, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Users/Admin/Documents/Visual Studio 2012/Projects/............/bin/Debug/
LOG: Initial PrivatePath = NULL
Assembly calls : EXEname, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
....
LOG: Using computer file configuration from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
....
ERR: Failed to complete assembly definition (hr = 0x8013101b).
I have tried to remove interop.DLLname.dll from the bin/obj folders, I have checked that all the projects in the build are targeting Framework 2.0
Am I missing something else?
You are getting this error because the com wrapper dll (interop.DLLname.dll) was generated for .net 4.5, obviously it can not be used in earlier versions of .net due to the different CLR version. You need to get the wrapper for .net 2.0 and reference it. Here is link on how to generate a com wrapper http://msdn.microsoft.com/en-us/library/ms404285%28v=vs.80%29.aspx
The only solution that worked in this case was to install Visual Studio 2008 and create the interop there.