Hi,
using .net core 1.1, and package <PackageReference Include="Google.Cloud.Diagnostics.AspNetCore" Version="1.0.0-alpha07" />
Mac:UDL-API$ dotnet --info
.NET Command Line Tools (1.0.1)
Product Information:
`Version:` 1.0.1
Commit SHA-1 hash: 005db40cd1
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.12
OS Platform: Darwin
RID: osx.10.12-x64
Base Path: /usr/local/share/dotnet/sdk/1.0.1
i get the error
' System.InvalidOperationException : Could not create an instance of type 'Google.Cloud.Diagnostics.Common.IManagedTracer'. Model bound complex types must not be abstract or value types and must have a parameterless constructor.'
That may be an issue on my side, but the documentation at http://googlecloudplatform.github.io/google-cloud-dotnet/docs/Google.Cloud.Diagnostics.AspNetCore/ does not really give much more clue on what is going on.
@Jonathan34 Can you give a little more context?
If you can share a pointer to the code that would be great, but I understand that is not always possible. If it's not public can you give me an example of where this is failing? How are you using IManagedTracer?
My guess is you are injecting the IManagedTracer on an MVC action or other similar method that requests the "[FromServices]" attribute.
If any parts of the docs aren't clear, lacking info, ect, please let me know and I will update them.
Hi,
If you are on slack (@jonathan on the .net group) / hangouts, I can eventually show you live, but I cannot share the code.
I have setup the middlewares according documentation (useGoogleTrace & AddGoogleTrace), I am trying to use an instance of IManagedTracer by dependency injection in a asp.net core MVC controller. It builds fine but fails on runtime.
The exception happens when i try to use an integration tests that hits this endpoint.
This is the packages the integration test project has.
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="1.1.1" />
</ItemGroup>
Let me know
Ok you nailed it quite fast. I was missing the [FromServices] attribute in the controller to completely enable the dependency injection! Now works ok.
I realize this is pure asp.net core but you may want to update the doc to mention that [FromServices] attribute is required for a controller, I believe it would help various people (the asp.net documentation also lacks information on how this could be enabled in a controller).
Let me know otherwise i ll close the ticket!
Thanks for the quick help!
@Jonathan34 Awesome glad everything is working. I will be sure to add an example to our docs to make this a little more clear.
I'll use this to track updating the docs and close this once I have a PR in.
Thanks for the feedback!
@Jonathan34 also a note (I will add this in the docs when I update them) the IManagedTracer is a singleton. I would suggest injecting it into the constructor of the controller and using it that way (no need for the [FromServices] attribute).
Most helpful comment
@Jonathan34 also a note (I will add this in the docs when I update them) the IManagedTracer is a singleton. I would suggest injecting it into the constructor of the controller and using it that way (no need for the [FromServices] attribute).