Skip to main content

PowerShell: Get Actual Error

I was having hard time to find the reason why I was not able to find a custom method in a .Net DLL.

Find your Assembly:


PS C:\vstsagent\A1\_work\r1\a\_DevOps_CI\Scripts> [appdomain]::currentdomain.getassemblies() | Where-Object FullName -Match "MyAssembly"



GAC    Version        Location

---    -------        --------

False  v4.0.30319     C:\vstsagent\A1\_work\r1\a\_DevOps_CI\Scripts\Tools\MyAssembly.dll



PS C:\vstsagent\A1\_work\r1\a\_DevOps_CI\Scripts> $a = [appdomain]::currentdomain.getassemblies() | Where-Object FullName -Match "MyAssembly"

PS C:\vstsagent\A1\_work\r1\a\_DevOps_CI\Scripts> $a



GAC    Version        Location

---    -------        --------

False  v4.0.30319     C:\vstsagent\A1\_work\r1\a\_DevOps_CI\Scripts\Tools\MyAssembly.dll


When I was trying to get the Types in the assembly, I was getting the exception:


PS C:\vstsagent\A1\_work\r1\a\_DevOps_CI\Scripts> $a.GetTypes()
Exception calling "GetTypes" with "0" argument(s): "Unable to load one or more of the requested types. Retrieve the
LoaderExceptions property for more information."
At line:1 char:1
+ $a.GetTypes()
+ ~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ReflectionTypeLoadException

I tried to get the actual exception, but I was not able to get it. Then I found following code which displayed the actual exception:


PS C:\vstsagent\A1\_work\r1\a\_DevOps_CI\Scripts> $x = $Error[0]
>> $x.Exception.GetBaseException().LoaderExceptions

Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or
one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or
one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or
one of its dependencies. The system cannot find the file specified.


Comments

Popular posts from this blog

Ensuring High Availability with F5 Failover: A Comprehensive Guide

F5 failover refers to the process of switching from a primary (active) F5 load balancer to a secondary (standby) F5 load balancer in the event of a failure or maintenance requirement. This ensures continuous availability and minimizes downtime for applications and services relying on the load balancer. F5 Networks provides a range of products, including the BIG-IP platform, which supports high availability (HA) configurations to enable failover. Key Concepts High Availability (HA) : F5 BIG-IP devices can be configured in HA pairs to provide redundancy. One device is active (handling traffic), and the other is standby (ready to take over if the active device fails). Failover Mechanisms: Failover can be triggered by various conditions, such as hardware failures, software issues, or manual intervention. The standby device continuously monitors the active device and takes over when it detects a failure. Sync-Failover Device Group: F5 devices in an HA pair are part of a sync-failover device...

Steps to Improve DevOps Culture

Introduction DevOps is fast becoming an essential aspect of many company cultures for numerous reasons. This guide outlines how to properly implement DevOps using the right tools and, crucially, the right mindset. However, implementing DevOps is more than just adopting new tools and practices. It’s about fostering a culture of continuous innovation and incremental improvement. Although challenging, the benefits of a robust DevOps culture are undeniable. DevOps is a critical foundation that empowers organizations to innovate, learn, and improve, driving business success. Step 1: Leverage the Best Metrics When initiating DevOps, start with clear end goals in mind. Metrics are crucial for tracking progress and ensuring a successful journey. The DORA State of DevOps 2019 report highlights key metrics to benchmark your DevOps transformation: Deployment Frequency : How often you deploy code to production or release it to end-users. Lead Time for Changes : The duration from code commit to run...