d3dcompiler_47.dll, ILMerge failing. Also wont add to GAC. Any Idea? - c#

Goal: I need all the files in my bin to be grouped into a single dll. or added to the GAC
I am using CefSharp To run chromium in a windows form.
We are using some software that will only allow me to add one dll (no other files).
I have access to the GAC on all machines. And I have been using ILMerge to attempt to bundle the files with the dll.
I have been able to get all the files to bundle except for. d3dcompiler_47.dll
When I try to add to GAC it tells me it has a bad manfiest.
When I try to bundle d3dcompiler_47.dll with my dll, it says
"System.BadImageFormatException: Could not load file or assembly
'd3dcompiler_47.dll' or one of its dependencies. The module was
expected to contain an assembly manifest. File name:
'd3dcompiler_47.dll' ---> System.BadImageFormatException: Could not
load file or assembly 'd3dcompiler_47.dll' or one of its dependencies.
The module was expected to contain an assembly manifest. File name:
'd3dcompiler_47.dll'"
(I have reviewed this but found that its 2 versions of d3d... do not work with CefSharp)
api-ms-win-core-libraryloader-l1-2-0.dll missing when d3dcompiler_47.dll is redistributed
Is there anyway to add d3dcompiler_47 (from CefSharp) to bundle or be added to the GAC?

As Hans said, you can't use ILMerge for unmanaged dlls.
Fody Costura however should work, at least it says so in its features.

Related

Assembly's dependent Assemblies are not copied

I have a scenario where i have library say for example : SomeLibrary.dll which references to System.Net.Http and System.Net.Http.Formatting just an example with Copy Local flag true, and that assembly is actually consuming some types of these two dlls.
Then i create a new Project and i add reference to SomeLibrary.dll with Copy Local flag true, when use methods of this dll which are internally using the above 2 libraries, the runtime error comes saying:
Could not load file or assembly 'System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
What i was expecting was it should have dependent assemblies on which SomeLibrary.dll depends should also be in the bin folder copied, which is not happening.
Am i missing something here?
UPDATE:
For your information, i am able to make it work by adding reference seperateely to those 2 dlls but wondering why i need to add seperately if i have reference to SomeLibrary.dll which is dependent on those 2 dlls.
I just had a very similar sounding problem, where I had assembly A depending on assembly B, and B depended on System.Net.Http.Formatting.dll. For some reason on my build server it wasn't copying System.Net.Http.Formatting.dll so it was missing in the final package it created (though in my case it wasn't in either projects' output folder). It worked fine locally on my development machine and I verified the assembly existing in the same place on the build server as it did on my machine (C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies).
I worked-around the problem with this answer to the related question, which was to switch to using the Microsoft.AspNet.WebApi.Client NuGet package to pull in that assembly explicitly. Unfortunately I'm still not sure what the problem was.

How can I load assemblies that are placed in the project (portable class library) folder?

I have a .dll file in my project folder and would like to load it via Assembly.Load().
AssemblyName name = new AssemblyName("Portable.Store, Version=0.1.0.0, Culture=neutral, PublicKeyToken=12ay62c33eocf6uf");
Assembly assembly = Assembly.Load(name);
However this would throw a FileNotFoundException due to not specifying a path. And I am unable to use Assembly.LoadFrom() or Assembly.LoadFile() because Portable Class Libraries only support Assembly.Load()
Is there a way to do this inside a pcl? Any help is appreciated, thank you!
Edit #1: Would it matter if the assembly I'm trying to load is a non PCL? I know that this defeats the purpose of the PCL however there are a few libraries that are not included in the PCL. Therefore using conditional compilation, depending on the platform, I will load platform specific assemblies.
Edit #2: Found some more information on where the dll should be placed: https://stackoverflow.com/a/6440406/2464165
As of now I just placed it inside my project folder, with the .sln file and what not Where exactly would be the app probing path?
Edit #3: I was able to get my dll file placed inside the Resources Folder of a .dll file. So I have MyPCL.dll and inside that is where I have the ResourcesFolder/Portable.Store. How could I tell the Assembly.Load to look in specific folders instead of just the main AppX root directory?
I'm making the assumption that you are running the portable library in a Windows Store application (based on the assembly name you are trying to load).
There are two places that store apps find their assemblies, either in GAC if it is a framework assembly or the Appx package if it is a user assembly.
As "Portable.Store" (which I assuming is from my PclContrib project) is a user assembly, it must be loaded from the AppX package. To ensure that both assemblies end up in the AppX package, simply make sure that the Windows Store project containing the AppxManifest references both of them. That's it.
If Assembly.Load still cannot find the assembly, check to make sure that the strong name you are passing to Assembly.Load is correct.

Could not load file or assembly 'log4net'

I am attempting to deploy a Crystal Reports desktop application, but the application is not able to find my log4net assembly, even though I have verified that my installer is registering the log4net DLL in the GAC. Below is the exception and stack trace.
Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral,
PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system
cannot find the file specified.
at CrystalDecisions.Shared.SharedUtils..cctor()
I am honestly completely lost as to why this isn't working... The versions are the same and everything. Do I need to configure log4net before this will work?
Editing: I am using InstallShield 2012 to install my application assembly to the GAC. The only other things I am installing are a very small exe that references my dll, and a few files in Program Files folder to handle configuration.
Turns out I was using the same version of the dll, but the one I was using had a different PublicKeyToken. After I fixed that, it worked.
Setting platform to x86 worked for me. Previous was AnyCPU
Assuming that the dll is already in the application folder, go to the properties of the project, click on Application Files and change the dll from "prerequisite" to "include", and save it. It would then be in GAC.

How to add assembly manifest to a C# .NET class library project in Visual Studio 2008?

I'm having a similar problem to what Paul had a year ago (see How to add manifest to a .NET DLL?). That is, I have a C# class library project in Visual Studio 2008, which outputs a dll. The dll references some private assemblies, so I want to add an assembly manifest to the dll that specifies those other referenced assemblies.
I know how to do this for an executable, it's just appName.exe.manifest, and when the file is included in the project, you can then just select it as the manifest in the project properties.
According to the answer that Ruben gave Paul (in the above Stack Overflow thread), a manifest only applies to exes. However, the Microsoft documentation on manifests seems to suggest otherwise (correct me if I'm wrong), MSDN Assembly Manifests:
An assembly manifest is an XML file
that describes a side-by-side
assembly. Assembly manifests describe
the names and versions of side-by-side
assemblies, files, and resources of
the assembly, as well as the
dependence of the assembly on other
side-by-side assemblies. Correct
installation, activation, and
execution of side-by-side assemblies
requires that the assembly manifest
always accompany an assembly on the
system.
Because of the way side-by-side
searches for private assemblies, the
following naming restrictions apply
when packaging a DLL as a private
assembly. A recommended way of doing
this is to put the assembly manifest
in the DLL as a resource. In this
case, the resource ID must equal 1 and
the name of the private assembly may
be the same as the name of the DLL.
For example, if the name of the DLL is
Microsoft.Windows.mysample.dll, the
value of the name attribute used in
the assemblyIdentity element of the
manifest may also be
Microsoft.Windows.mysample.
An alternate way is to put the
assembly manifest in a separate file.
In this case, the name of the assembly
and its manifest must be different
than the name of the DLL. For example,
Microsoft.Windows.mysampleAsm,
Microsoft.Windows.mysampleAsm.manifest,
and Microsoft.Windows.Mysample.dll
So I created an assembly manifest assemblyName.manifest as a separate file, and included it in the class library project. But when I go to the properties for the project, I get the same result that Paul did, the option to use your own manifest is disabled.
Am I doing something wrong? How do I add my manifest to the assembly?
What you quoted is quite inappropriate for .NET assemblies. The Windows side-by-side cache is for unmanaged DLLs, the exact equivalent in .NET is the GAC. Furthermore, the compiler already embeds references to the dependent assemblies in the assembly manifest. You can see it if you run Ildasm.exe on your assembly. Double-click the manifest, you'll see the .assembly directives listed.
Fwiw, embedding your own Windows manifest in a class library is not a problem. Just use Project + Add New Item and select the Application Manifest File template item. The auto-generated content is completely wrong for a DLL of course but it does get embedded in the DLL. You can see that by using File + Open + File and selecting your assembly. You'll see the RT_MANIFEST with resource ID 2. Just to reiterate: don't do this for a managed DLL unless you want to enter reg-free COM directives.

Deploying assembly normally in the GAC with my project?

I built a web application that uses the J# libraries which works fine in my cpu, however, when I deploy it to my shared server. I get an error message: Parser Error Message: Could not load file or assembly 'vjslib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
So basically, the server doesn't have visual j# installed. The problem is they wont install it because it is a shared server.
Is there a way I can deploy the J# assemblies with my project so that it will work on the shared server without it being registered in the GAC?
Thanks for your help!!
Simplest solution: Try to copy the assemblies your application needs into the same folder where your application resides.
The following MSDN article explains How the Runtime Locates Assemblies.
Also, you may find more options (including copying all J# related dlls into a subfolder of the application folder if needed) in the following link when the runtime cannot find the assembly in the GAC: Locating the Assembly through Codebases or Probing
Without knowing anything about J# I can only suggest that you try just distributing the required libraries along with your program (place them in the same directory), I believe if it can't find the library in the GAC it will revert to look in the current directory.

Categories

Resources