How to Retrieve the Loaderexception Property

How to retrieve the LoaderException property?

try
{
// load the assembly or type
}
catch (Exception ex)
{
if (ex is System.Reflection.ReflectionTypeLoadException)
{
var typeLoadException = ex as ReflectionTypeLoadException;
var loaderExceptions = typeLoadException.LoaderExceptions;
}
}

Error message 'Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.'

I solved this issue by setting the Copy Local attribute of my project's references to true.

MVC Application - Retrieve the LoaderExceptions from Global.asax.cs

replace StsMvcHttpApplication by MvcHttpApplication or make sure you are refering to StsMvcHttpApplication assemblies and all their dependencies

Azure table: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information

Is there a way to look at the LoaderException stacktrace.

You could use StackTrace class to trace exception in your project.

Or you could retrieve ReflectionTypeLoadException.LoaderException property to get more information about LoaderException.

Catch the exception in Code:

try
{
// load the assembly or type
}
catch (Exception ex)
{
if (ex is System.Reflection.ReflectionTypeLoadException)
{
var typeLoadException = ex as ReflectionTypeLoadException;
var loaderExceptions = typeLoadException.LoaderExceptions;
}
}

At the moment, Under Property of the Project, Application -> Target Framework is running in .netStandard 2.0

Just some features in trigger types could use in Azure function v2 preview template:

Sample Image

For example, the BlobTrigger supports fine in v2. You could have a try to operate azure storage.

Create Azure function v2 preview:

Sample Image

Create BlobTrigger:

Sample Image

The Code in BlobTrigger:

public static class Function1
{
[FunctionName("Function1")]
public static void Run([BlobTrigger("helloworld/{name}", Connection = "AzureWebJobsStorage")]Stream myBlob, string name, TraceWriter log)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
"storage account connection string");
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("helloworld");
CloudAppendBlob blob = container.GetAppendBlobReference("log2.txt");
using (var fileStream = System.IO.File.OpenRead(@"D:\log.txt"))
{
blob.UploadFromStreamAsync(fileStream);
}
log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
}

}

The result in BlobTrigger:

Sample Image

So you'd better to choose the compatible platform version. More details please refer this article.

Azure Functions runtime 2.0 is in preview, and currently not all features of Azure Functions are supported.

Cannot compile: Retrieve the LoaderExceptions Property from NULL for more information

This link tells me to turn off Auto-Serialization. That made it work.

Still wondering why it worked on my friends machine and not mine. There should be a way to diagnose this better.



Related Topics



Leave a reply



Submit