How to load assembly into default load context without adding into GAC? - assembly-loading

I tried to load the assembly in Assembly Resolve event. Also I got the hook up and loaded the assembly in the app domain using Assembly.LoadFrom.
But when I access a method from the assembly in the same app domain I got assembly not found error as below,
Could not load file or assembly......
LOG: This bind starts in default load context.
It tries to load using default load context. Please help me to load the assembly in default load context without putting in GAC.

Related

Acumatica Publishing with DLL resulting in System.BadImageFormatException

I am trying to add some external DLLs to the Acumatica Customisation project but upon publishing it results in "System.BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid."
Error Image:
I already have added multiple DLLs to the Customisation. And was using the method specified here: Acumatica unable to publish the Customization Package to skip over the errors, but in this case it does not seem to be working.
The first step should be identifying which DLL is the culprit. I suggest you create an empty project and put the files in there one by one with the ignore rules. Maybe you missed to add ignore rule for one of the files.
This error happens because Acumatica attempts to parse the DLL as a .Net framework assembly. If you add non .Net assembly such as native x86/x64 compiled libraries you need to add the ignore rule so Acumatica doesn't attempt to parse it.
If the error is coming from a DLL you compiled, make sure it was compiled in Any CPU platform. This prevents any incompatibility related to 32 bit/64 bit mismatch.

Load Log4net custom appender from a library outside the application folder

I have a C# custom appender library which needs to be used by several applications in different solutions which run in the same server. I have an addon installer solution that creates all the folders and stuffs which includes the custom appender library, which the other projects needs to use. Instead of adding this library into all the application's directory, I just want to let the each application's App.Config to point to this single custom appender library.
I have built a custom appender call MyCustomAppender in a library call MyCustomLibrary.dll.
Here is the xml code of one of the App.Configs:
<appender name="MyCustomAppender" type="MyCustomerLibrary.MyCustomAppender, C:\Users\Admin\Libraries\MyCustomLibrary">
It is not possible for me to put the path of the library because Log4net doesn't work this way. Is there a walk around for each application to point to C:\Users\Admin\Libraries\MyCustomLibrary.dll? to use the MyCustomAppender? The other applications needs to have 0 code changes, only their App.Config can be modified due the the reason this process needs to have minimal changes.
You can add the dll to the GAC on the machine your application is runnen. This will allow all programs to find the dll. BTW, coping the dll into the bin directory of the application will not change the code of the application.

Unable to create a fakes assembly for a SharePoint project

I've found that when trying to create a fakes assembly for a SharePoint project that references certain SharePoint libraries that I get errors similar to:
Failed to load properly Derived method 'RequiresWebPartClientScript' in type 'Microsoft.Office.Server.Search.WebControls.ScriptWebPart' from assembly 'Microsoft.Office.Server.Search, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' cannot reduce access.
This commonly occurs where the SharePoint project references libraries that are not in the GAC such as: Microsoft.SharePoint.ApplicationPages and Microsoft.ApplicationPages.Administration
It seems that this problem is caused by the fakes generator being unable to resolve the reference when attempting to create fakes. The issue can be worked around by adding a reference to the offending library to the project that will contain the fakes assembly.
For example, if I have a project 'My.SharePoint.Stuff' and I want to run tests in a project 'My.SharePoint.Stuff.Tests' then I would generate a fakes assembly for My.SharePoint.Stuff in My.SharePoint.Stuff.Tests.
Where this fails as described above, the solution is to add a reference to the assembly that is described in the error message to the My.SharePoint.Project.Tests project and then recreate the fake.

How to take binding information from outside App.config in C# console application?

I have an App.config fiel in which i defined some binding information.
I want this information in some external file so that user can change it whenever required.
Anyone have an idea about how to implement it?
Thanks in advance
Assuming we're talking about assembly binding redirects...
The runtime is going to use your App.exe.config file to locate the binding redirects. I don't believe you can do anything about this in a normal managed application because the runtime is already initialized by the time you can run any code.
If you had an unmanaged "shim" (an exe in C++ for example) that used the CLR hosting API's, you can tell it the name of a config file to use when you set up the AppDomain. But I don't believe you can make your binding redirects separate from the main application config.
Your only other option would be to handle the AppDomain.AssemblyResolve event to handle binding failures. But this is potentially expensive as the runtime will exhaust all of its options for probing the assembly before raising this event.

Does GHC API dynamic loading work only with modules from installed packages?

I try to follow the way described in the answer to this question.
I have ExampleModule.o and ExampleModule.hi files in the working directory and I try to load ExampleModule.f function. But I get error message (with verbosity level set to 3):
Failed to load interface for `ExampleModule':
locations searched:
ExampleModule.hs
ExampleModule.lhs
The packageIdString (thisPackage dynflags) is "main".
I suppose that's because I can only load modules from installed packages. Am I right? Is there a way to load a function dynamically from standalone object file, just like load function from plugins does, but with GHC API?

Resources