Consuming .NET Assembly in Classic ASP - c#

I have a classic asp site that needs to consume a .NET assembly. I have written a dll library that is COM-visible and the project is using a reference to a Paypal-SDK library. I have been successfully able to create the dll and consume it in a classic asp web page on my Windows 10 development machine. When I copy the web application to a Windows 2012 running IIS 7.x I get the following error
nDataConsulting.PaypalStub error '80070002'
Could not load file or assembly 'PayPal, Version=1.8.0.0, Culture=neutral, ?>PublicKeyToken=5b4afc1ccaef40fb' or one of its dependencies. The system cannot >find the file specified.
The COM visible assembly is using the Paypal.dll SDK which I believe it cannot find on the Windows 2012 server. I have tried placing the dll in the application BIN folder, tried regsvr32 etc but I have not been able to make my dll find the dependent dll. Kindly help me resolve this issue as this is a major show stopper right now

There is a program called Dependency Walker which shows basic information about a DLL, such as its methods, and also lists the dependents DLLs.
It was answered here:
https://stackoverflow.com/a/7378982/8419161
If you find any related DLLs, you must include them along with the Paypal one.

Related

System.BadImageFormatException: 'Could not load file or assembly' - C# / C++

I try to be as detailed as possible in explaining our situation, premising that we made several attempts in relation to other similar situations found on stackoverflow. Specifically, we have a project consisting of many libraries in c# that has been updated from net 4.7 to asp.netcore 6.0. Within the project there is also a library of classes in c++. This library generates a dll that is used within one of the projects c#. The project in c++ has not been updated, but we simply went to vary the target framework from net 4.7 to netcore 6.0 (and also we changed clr to clr:netcore) as explained in the Microsost guide for porting hybrid projects in C# and C++. All the project builds correctly but when the debugging of the webapp in C# referencing the dll in C++ I get the following error:
System.BadImageFormatException: 'Could not load file or assembly 'Tradante.MT4.Wrapper, Version=1.0.8369.22669, Culture=neutral, PublicKeyToken=null'. Format of the executable (.exe) or library (.dll) is invalid.'
Navigating through various issues similar to our case, we seemed to understand that the incompatibility problem could be related to having a project at x64 and another at x86. We tried to vary all possible combinations but the error remains the same. But we noticed something strange: we forced the build to x64 of the webapp in C# but in the compilation output (which we see as enabled debugging of the native code) we find the name of the webapp followed by (Win32) as if the machine continues to build at x86. I don’t know if this information can help you.

How would I implement this service/dll in a Unity project?

I'm using a service called JNBridge which is used to create proxies for Java files to be used in C#. The service works fine and I can easily create a C# solution in Visual Studio 2017 and call Java files from created proxies. I would like to use this in a Unity project however but I'm not sure how I would accomplish this.
In order to get this to work in Visual Studio 2017 I first create the proxies I want to use and build it into a dll. After that I create a console application and add the .dll as a reference (+ another .dll needed by the service). The service also needs to use an Application Configuration File and a non .NET .dll. These two files have to get copied to the build folder in order to run the application.
When I try recreating this in Unity I add the two .NET .dll files to the Assets folder and it seems to work since scripts autocomplete code from the .dlls. However in the Unity console I get a FileNotFoundException. I also have no idea how I would go about including the non .NET dll and the config file.
System.IO.FileNotFoundException: Could not load file or assembly 'DotNetToJavaProxies, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'DotNetToJavaProxies, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes()
I'm not that familiar with Unity so I'm asking, can I accomplish this? Using the config file and the .dll, and fixing the error.
JNBridgePro does not support Unity, so it is unlikely that this would work, although I have to say that we have never tried it. Starting with the new version 10, JNBridgePro does support .NET Framework and also .NET Core 3.0 (on Windows and Linux). Perhaps one of those scenarios would work for you. If you have additional questions, please contact JNBridge support.

could not load file or assembly 'System.Web.MVC, version 4.0.0.0,'

I am getting run time error from one of the projects which is not an MVC project. I recently upgraded .net framework from 4.0 to 4.5.2 and am building the solution for deployment using MS Build 12.0. The solution builds just fine but am seeing the above exception when I run the service which has no reference to the said assembly.
The project is run as a windows service which uses windows workflow foundation to run some rules. I don't have IIS enabled on the target server and the web related dlls haven't been deployed as well
You could try to check Windows service assemblies by this tool to understand what assembly requires MVC:
Could not load file or assembly or one of its dependencies

Reference a native dll from an asp.net 5 project

I am trying to reference a native dll from an asp.net 5 project using pinvoke. The recommended solution is to wrap the dll in a nuget package and reference that. However I am also developing the native dll, so it is impractical to constantly create new nuget packages when I make changes.
If I have the native dll location in the path variable it is found through pinvoke and works fine. But I would like a solution which is contained in the Visual Studio solution so that other developers could download the VS solution and have it work without changing the path variable.
I tried using the bin syntax as described in this topic:
How do you add references to locally created NON ASP.Net 5 dlls to an ASP.Net 5 project
but that seems to only work for managed assemblies as I get an error stating that the assembly manifest cannot be found.
Thanks

Use Of Same dll file in all .Net Applications

I have ConsoleApplication01, ConsoleApplication02, ConsoleApplication03 and using "Mydll.dll" for accessing database.
I want to keep all "exes" of all Console Applications in one folder to run using windows service. So problem is that, Its asking to replace "Introp.Mydll.dll" into my destination folder.
Will it work by Replacing this file "Introp.Mydll.dll".
If its exactly the same dll (same binary) than there is no problem.
If you are using different versions for each application (and there is a good chance you should, or at least be able to, to allow upgrading the version only for a single service), you can use GAC mechanism.
GAC is sort of a centralized storage of a lot of dll's used by .net, and its uniqueness is that you can publish a lot of dll's with the same name that will have different versions or different globalization culture. That way your C# services will find the dlls and load them automatically from GAC, and if you will require to upgrade the dll just for one service, you will only change this reference to point to the new specific version.
You can read about GAC here:
https://msdn.microsoft.com/en-us/library/yf1d93sz(v=vs.110).aspx
and how to install assembly (dll) into GAC here:
https://msdn.microsoft.com/en-us/library/dkkx7f79(v=vs.110).aspx

Categories

Resources