Ad Code

Responsive Advertisement

C# Error 03: An exception of type 'System.TypeLoadException' occurred in C#

C# Error 03: An exception of type 'System.TypeLoadException' occurred in C# 

The System.TypeLoadException typically occurs when the runtime is unable to find or load a type from an assembly. In your case, the error message indicates that the type Dynomerk.CentralData.Common.DynoTestResult_TVSMServer could not be loaded from the Dynomerk.CentralData.DTO.Common assembly.

Possible Causes & Solutions

1. Check Assembly Version & Reference

  • Ensure that the Dynomerk.CentralData.DTO.Common.dll assembly is referenced correctly in your project.
  • Right-click on References in your project → Click Add Reference → Check if Dynomerk.CentralData.DTO.Common.dll is properly added.

2. Clean & Rebuild Solution

  • Close Visual Studio
  • Navigate to your project folder and delete bin and obj folders
  • Restart Visual Studio and Rebuild the Solution (Ctrl + Shift + B)

3. Verify Type Exists in Assembly

  • Check whether the type Dynomerk.CentralData.Common.DynoTestResult_TVSMServer exists in the assembly.
  • Use ILSpy or dotPeek to inspect the Dynomerk.CentralData.DTO.Common.dll file and confirm if the class is present.

4. Ensure Correct Namespace

If the class was moved to a different namespace, you may need to update your using statements accordingly.

5. Verify Assembly Deployment

If the error occurs after deployment, ensure the correct version of Dynomerk.CentralData.DTO.Common.dll is present in the output directory or server.

6. Check for Strong Naming Conflicts

If the assembly is strongly named (has a PublicKeyToken), ensure that the correct version is referenced.

  • Try removing and re-adding the reference.
  • Check the GAC (Global Assembly Cache) using:
    gacutil -l Dynomerk.CentralData.DTO.Common
    
    If the wrong version is loaded, remove it and add the correct one.

7. Ensure Target Framework Compatibility

  • If your project targets .NET Framework 4.5+ and the DLL is built with .NET Standard, ensure compatibility.
  • Right-click on your project → Properties → Check Target Framework.

8. Try Binding Redirects (If Needed)

If the issue is due to assembly version mismatches, you can add a binding redirect in the app.config or web.config:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Dynomerk.CentralData.DTO.Common" publicKeyToken="0f66186f31bb8fdd" culture="neutral" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

🛠 Next Steps

  1. Verify assembly reference and type existence.
  2. Rebuild solution after clearing bin/obj.
  3. Check for mismatched versions in the GAC.
  4. Use ILSpy or dotPeek to confirm the class exists in the DLL.
  5. Ensure runtime compatibility between the DLL and your application.

If you like comment and share. 🚀

Post a Comment

0 Comments

Ad Code

Responsive Advertisement