The type initializer for ‘codeRR.Client.Err’ threw an exception


#1

I’ve had Coderr working for some time, and over the last few weeks, noticed that it wasn’t actually working. Not sure what I’ve changed or done, but for some reason, it’s no longer working at all. Adding an email handler to my try/catch in the application start event, and I get the following:

System.TypeInitializationException: The type initializer for 'codeRR.Client.Err' threw an exception. ---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.Assembly.GetTypes()
at codeRR.Client.ContextProviders.ContextProvidersRegistrar..ctor()
at codeRR.Client.Config.CoderrConfiguration..ctor()
at codeRR.Client.Err..cctor()
--- End of inner exception stack trace ---
at Website.Global_asax.SetupErrorHandler() in C:\BuildAgent\work\172bc81c85a992f8\Website\Global.asax.vb:line 46

I am calling it with:

Private Sub SetupErrorHandler()
    Try
        if not CodeErrActive then 
        If Not Debugger.IsAttached Then
            Dim CodeRRURL As New Uri("https://xxx/")
            Dim Provider As New VirtualPathProviderBasedGenerator("~/Errors/")
            Err.Configuration.Credentials(CodeRRURL, "xxx", "xxx")**
            Dim t As IContextInfoProvider = New CurrentUserContext
            Err.Configuration.ContextProviders.Add(t)
            Err.Configuration.UserInteraction.AskForEmailAddress = False
            Err.Configuration.UserInteraction.AskUserForDetails = True
            Err.Configuration.UserInteraction.AskUserForPermission = False
            Err.Configuration.QueueReports = True
            Err.Configuration.SetErrorPageGenerator(Provider)
            Err.Configuration.CatchAspNetExceptions()
            CodeErrActive = True
        End If
            End If
    Catch ex As Exception
        functions.sendDebugemail("Error in Application Start:<br />" & ex.ToString(), "Error in Application State")
    End Try
End Sub

Line 46 is the Err.Configuration.Credentials


#2

I’ve had a similar problem:

https://discuss.coderr.io/t/coderr-client-nuget-giving-error-on-launch/69

Was caused by not providing the new config file… You could try that :slight_smile:


#3

Thanks for the quick response!

When you say config file, which file do you mean? Web.config? there don’t seem to be any references to Coderr at all in there.


#4

It’s the {assembly}.dll.config or {assembly}.exe.config file that goes along with the assembly after building your project. Make sure you copy it along if you’re deploying to a new directory.


#5

Still no good I’m afraid. I wish I knew what/when it changed, as it WAS working. I’ve tried going to different .NET levels, I’ve removed and re-added the nuget packages, no change, still getting the error.

This is an ASP.NET website, not an application, so there isn’t dll.config files.

Looks like it’s having trouble with context providers.

Interestingly, I had written my own custom context provider, so I tried removing that, and it makes no difference. I can’t really simplify the initialisation code much more, and still getting this error. Can you check the content of those config files you mention, and if they’re not containing anything specific, do you mind sharing the content? Maybe I’ll be able to find a hint in there of something that I can translate to the ASP.NET equivilant.


#6

Can you send me the web.config directly to my email? You can remove the connectionStrings from the config.
I would also like to know the file and product version for each Coderr.Client DLL that you are using.


#7

Absolutely. The DLL’s are:
image
image

The web.config I’ve sanitized, and don’t mind putting up:
https://pastebin.com/z57T120R

Those DLL’s are from the nuget packages:

Coderr.Client, version 1.0.20

and

Coderr.Client.AspNet, version 1.0.1

These are in packages.config as:

<package id="Coderr.Client" version="1.0.20" targetFramework="net46" />
<package id="Coderr.Client.AspNet" version="1.0.1" targetFramework="net46" />

Everything is .NET 4.6 in here, but I’ve tried winding that back to 4.5.2, 4.5.1, 4.5, and even 4.0 for good measure, and am still getting the error.


#8

I can’t find anything wrong. This is typically due to incompatible versions of the nuget packages. It’s like Sam says, there should be <assemblyBindings> in a config somewhere (the class library where you use Coderr). They need to be copied to your web.config.

I’ve also made an update to the ASP.NET package now forcing it to use the latest core package. the namespace have also changed from “codeRR” to “Coderr” which will require some additional work.


#9

Okay, this looks like it’s the issue. I don’t have this text anywhere in my project at all. Is this something you can give me a copy/paste of to add to my web.config? I can’t find it in any file in the entire project, and re-installing the nuget packages doesn’t add it back. Coderr is used in the main “website” class, which is the entire application basically.

I’m pushing the upgrade to 1.1.0 via nuget now to my staging server. The case sensitivity change in the namespace won’t have any issues for me, since I’m using VB.

Another odd thing I’ve just found; it works on localhost! So on my win10 dev machine, it works. But pushing it to my production and stage servers, and it doesn’t work. That’s rather odd.

I did have to remove:
SetErrorPageGenerator(provider)
and
CatchAspNetExceptions()

as they are no longer available options in the Err.Configuration object since the update.
And, well, lots of other errors, lol. Doesn’t seem namespace related, but seems to be having a lot of compile and runtime issues. I’m going to roll back to 1.0.20 for the moment until I’ve got more time to try this out :slight_smile: