Azure Functions - Could not load file or assembly Microsoft.IdentityModel.Extensions - azure

I'm trying to create a Azure Function that references 'Microsoft.IdentityModel.Extensions'.
I have a helper library dll, that includes code to provisioning a SharePoint Online site. This dll uses Microsoft.IdentityModel.Extensions.
I have put this helper library in the bin folder and reference it from run.csx using the #r syntax, but I keep getting this error in the log:
Exception while executing function: Functions.ATPCreateSiteFunction. mscorlib: Exception has been thrown by the target of an invocation. ATP.SiteProvisioning.Cloud: Could not load file or assembly 'Microsoft.IdentityModel.Extensions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=69c3241e6f0468ca' or one of its dependencies. The system cannot find the file specified.
I have tried the following approaches to get Azure Functions to find the Microsoft.IdentityModel.Extensions assembly:
Include the Microsoft.IdentityModel.Extensions.dll in the bin folder and reference in run.csx with this: #r "../bin/Microsoft.IdentityModel.Extensions.dll"
Trying to include as Nuget package by referencing "Microsoft.Identity.Model.Extensions": "2.0.1459.0" in project.json (same Nuget used in the helper library itself)

I don't think you need to reference the file path to the DLL. Instead of #r "../bin/Microsoft.IdentityModel.Extensions.dll", try #r "Microsoft.IdentityModel.Extensions.dll".

Related

Metadata file could not be opened -- PE image doesn't contain managed metadata

In azure functions I uploaded private dll's to bin folder using following instructions
If you need to reference a private assembly, you can upload the assembly file into a bin folder relative to your function and reference it by using the file name (e.g. #r "MyAssembly.dll").
but I when run the function, I am getting this error for every dll. "Metadata file could not be opened -- PE image doesn't contain managed metadata"
Looks like you're adding references to native binaries as well. Your references must be .NET assemblies. If you're deploying native indirect dependencies, you don't need to reference those from your function script.
UPDATE: There as a defect in the last portal deployment causing the content of files uploaded in the portal to be prefixed and suffixed with multipart form data, invalidating files.
The issue has been fixed and is being rolled out, but in the meantime, please upload the files using Kudu to workaround this issue. You can find more information about the problem here (and by following the issue link)
I also faced the same issue while building MAUI app in android platform. A native module was present in the project with .so extension. But a windows native DLL also present in the project for the purpose for running the same project in windows. Excluding the windows native DLL while building running in android fixed the issue. Sometimes I have to close the project and delete bin and obj folder and then rebuild the project to get rid of this issue.

Deploying an external assembly (DevExpress) to an azure app service

We are deploying to azure automatically from github via a kudu script. It was working okay until I tried to add DevExpress XtraReports to a project.
I have some DevExpress references in my csproj file like so:
<Reference Include="DevExpress.XtraReports.v16.2, Version=16.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Resources\DevExpress.XtraReports.v16.2.dll</HintPath>
</Reference>
Everything run great and works fine on my local machine but when it builds on azure I get the following error: "The type or namespace name 'DevExpress' could not be found (are you missing a using directive or an assembly reference?)". The DevExpress dlls are checkin into source control and are set to copy local true.
All the packages that are nuget packages work fine. However DevExpress has to be a binary reference and I am not sure how to copy them to the correct directory to be included when everything builds in azure.
Thoughts? I feel like I am missing something obvious but cannot figure out what it is.
This was egg on my face, ID10T error, whatever you want to call it. It was the typical the files weren't in source control error. While working late at night I saw the *.xml files in source control and assumed it was the dll files. With fresh eyes I caught it. It was driving me crazy.

Need to include a DocumentFormat.OpenXML dll in project

I have a customization project where I'm importing an Excel file content into the Lot/Ser No. Allocation grid. This works fine on my machine, but I had to download the DocumentFormat.OpenXml dll and include a reference in my class library project in order to do this. I've created a customization project, but when someone else tries to use it, that reference and that file are not there. I've tried to include it in the files section of the customization manager, but I have no way of doing that (can't browse to a file) - not that that would make any difference anyway, since that's the bin folder of the website, and not the class library.
Bottom line: Is there a way to include a dll file that's used in the class library project references in a customization package?
Add the dll file in Bin folder of your local website -> the file should appear in the Add Files dialog inside Customization Project Manager
Select the dll file in the Add Files dialog and click Save
After that, DocumentFormat.OpenXml.dll becomes a part of your customization package, which will always deploy it together with your extension library
Ruslan provided a good answer explaining how to include your custom DLL, however you might want to know that there are built in functions to read Excel files which make inclusion of third-party libraries unnecessary. Please refer to the following article: http://asiablog.acumatica.com/2016/03/reading-excel-file-acumatica.html?m=1

Unable to load assembly in appDomain

Until recently I was loading my assembly by calling Assembly.LoadFrom and it was ok. But now I need to load it in a temporary appDomain but I keep having a FileLoadException when trying to load the assembly in the temp domain. I have tried to pass appDomainSetup parameters to the CreateDomain method but without success.
Here is my code.
var tempDomain = AppDomain.CreateDomain("TempDomain");
Assembly sampleAssembly = tempDomain.Load(pathToDll);
My assembly is in a sub directory of my application base directory
AppDomain.Load loads the assembly in the currently executing AppDomain and not in the "TempDomain" one. As remarked in the MSDN doc:
This method should be used only to load an assembly into the current
application domain. This method is provided as a convenience for
interoperability callers who cannot call the static Assembly.Load
method. To load assemblies into other application domains, use a
method such as CreateInstanceAndUnwrap.
Now in your case the call fails because the currently executing AppDomain (most probably your main AppDomain) cannot locate assemblies from the sub directory. When you try to load assemblies in the load context, you should make sure that these assemblies are located in one of the following places:
the base dir of the AppDomain
a sub directory of the base dir that is specified in the AppDomain's private bin paths
the GAC
For more info you can check the following articles:
How the Runtime Locates Assemblies
Best Practices for Assembly Loading
Back to Basics: Using Fusion Log Viewer to Debug Obscure Loader Errors

Could not locate assembly

I have a SharePoint webpart for which I have had to change its public key. However, I don't appear to be able to locate every reference to the old assembly signed with this key.
Now I get a 'Parser Error'...
Parser Error Message: Could not load file or assembly '[Assembly.name], Version=1.0.0.0, Culture=neutral, PublicKeyToken=[Old public key token]' or one of its dependencies. The system cannot find the file specified.
Can anyone advise me how I can trace what is referencing this assembly? I've deleted the instance of the web part on the page that is causing this error - what more can I do?
Thanks in advance,
Flippsie
Each webpart instance references the DLL explicitly. You can verify this by exporting the webpart and then opening up the file in a text editor. You'll see your DLL called out between the <Assembly></Assembly> node.
Try adding the webpart back to the page again. You may have to make a new DWP/.WEBPART file or update it in the Webpart gallery.

Resources