Autofac exception - security critical vs level 2 security transparency
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm updating an older project to use .net 471 instead of 462 and the most recent version of all nuget packages.
I've had a lot of versioning issues to plow through, but I finally got a project that builds.
But, when I execute the programming I get this exception:
System.TypeAccessException: 'Attempt by security transparent method
'Autofac.Integration.WebApi.RegistrationExtensions.RegisterApiControllers(Autofac.ContainerBuilder,
System.Reflection.Assembly)' to access security critical type
'Autofac.Builder.IRegistrationBuilder`3'
failed.
Followed by
Assembly 'Autofac.Integration.WebApi, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=17863af14b0044da' is marked with the
AllowPartiallyTrustedCallersAttribute, and uses the level 2 security
transparency model. Level 2 transparency causes all methods in
AllowPartiallyTrustedCallers assemblies to become security transparent
by default, which may be the cause of this exception.'
That happens when calling:
builder.RegisterApiControllers(ThisAssembly);
Where builder is an Autofac ContainerBuilder
.
Question
Like the subject says, it must be some kind of conflict between SecurityCritical
and AllowPartiallyTrustedCallersAttribute
but I don't know how I've introduced it and what the best action is, so
What's going on and how can I fix this?
Update
Going further on JLe's suggestion, I removed the webapi
reference and used webapi2
instead. I got a related error on my logging setup, but since that's not "core functionality" I skipped it for now (I will need to get back to that) to see what I'd get. I get to the browser screen, which gives me this:
Method 'my.namespace.MyController+d__6.MoveNext()' is
security transparent, but is a member of a security critical type.
I tried putting [SecurityCritical]
on the controller class, but apparently you're not allowed to do async calls in a class with that attribute:
Error CS4031 Async methods are not allowed in an Interface, Class, or
Structure which has the 'SecurityCritical' or 'SecuritySafeCritical'
attribute.
But I can't fix that, because I'm doing async calls to the backend (NServicebus ESB).
c# asp.net .net asp.net-web-api2 autofac
|
show 2 more comments
I'm updating an older project to use .net 471 instead of 462 and the most recent version of all nuget packages.
I've had a lot of versioning issues to plow through, but I finally got a project that builds.
But, when I execute the programming I get this exception:
System.TypeAccessException: 'Attempt by security transparent method
'Autofac.Integration.WebApi.RegistrationExtensions.RegisterApiControllers(Autofac.ContainerBuilder,
System.Reflection.Assembly)' to access security critical type
'Autofac.Builder.IRegistrationBuilder`3'
failed.
Followed by
Assembly 'Autofac.Integration.WebApi, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=17863af14b0044da' is marked with the
AllowPartiallyTrustedCallersAttribute, and uses the level 2 security
transparency model. Level 2 transparency causes all methods in
AllowPartiallyTrustedCallers assemblies to become security transparent
by default, which may be the cause of this exception.'
That happens when calling:
builder.RegisterApiControllers(ThisAssembly);
Where builder is an Autofac ContainerBuilder
.
Question
Like the subject says, it must be some kind of conflict between SecurityCritical
and AllowPartiallyTrustedCallersAttribute
but I don't know how I've introduced it and what the best action is, so
What's going on and how can I fix this?
Update
Going further on JLe's suggestion, I removed the webapi
reference and used webapi2
instead. I got a related error on my logging setup, but since that's not "core functionality" I skipped it for now (I will need to get back to that) to see what I'd get. I get to the browser screen, which gives me this:
Method 'my.namespace.MyController+d__6.MoveNext()' is
security transparent, but is a member of a security critical type.
I tried putting [SecurityCritical]
on the controller class, but apparently you're not allowed to do async calls in a class with that attribute:
Error CS4031 Async methods are not allowed in an Interface, Class, or
Structure which has the 'SecurityCritical' or 'SecuritySafeCritical'
attribute.
But I can't fix that, because I'm doing async calls to the backend (NServicebus ESB).
c# asp.net .net asp.net-web-api2 autofac
1
Are you using nuget.org/packages/Autofac.WebApi2 or nuget.org/packages/Autofac.WebApi?
– JLe
Nov 26 '18 at 13:29
1
I'm just guessing, but the Autofac.WebApi2 package is for WebApi2, so I though maybe the old package created some version conflict which lead to your exception. Could you try remove the old one?
– JLe
Nov 26 '18 at 13:34
I just tried, but webapi is needed for thatRegisterApiControllers
andAutofacWebApiDependencyResolver
.
– Spikee
Nov 26 '18 at 13:35
Have you tried cleaning your solution? The WebApi2 package should contain those as well, version 4.2.0. The actual namespace of it is the same, Autofac.Integration.WebApi even though it's version 2.
– JLe
Nov 26 '18 at 13:46
1
@JLe: Your suggestion about cleaning up the packages ultimately fixed it (by making sure I was using webapi2). Could you write an answer so I can accept it?
– Spikee
Nov 28 '18 at 6:38
|
show 2 more comments
I'm updating an older project to use .net 471 instead of 462 and the most recent version of all nuget packages.
I've had a lot of versioning issues to plow through, but I finally got a project that builds.
But, when I execute the programming I get this exception:
System.TypeAccessException: 'Attempt by security transparent method
'Autofac.Integration.WebApi.RegistrationExtensions.RegisterApiControllers(Autofac.ContainerBuilder,
System.Reflection.Assembly)' to access security critical type
'Autofac.Builder.IRegistrationBuilder`3'
failed.
Followed by
Assembly 'Autofac.Integration.WebApi, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=17863af14b0044da' is marked with the
AllowPartiallyTrustedCallersAttribute, and uses the level 2 security
transparency model. Level 2 transparency causes all methods in
AllowPartiallyTrustedCallers assemblies to become security transparent
by default, which may be the cause of this exception.'
That happens when calling:
builder.RegisterApiControllers(ThisAssembly);
Where builder is an Autofac ContainerBuilder
.
Question
Like the subject says, it must be some kind of conflict between SecurityCritical
and AllowPartiallyTrustedCallersAttribute
but I don't know how I've introduced it and what the best action is, so
What's going on and how can I fix this?
Update
Going further on JLe's suggestion, I removed the webapi
reference and used webapi2
instead. I got a related error on my logging setup, but since that's not "core functionality" I skipped it for now (I will need to get back to that) to see what I'd get. I get to the browser screen, which gives me this:
Method 'my.namespace.MyController+d__6.MoveNext()' is
security transparent, but is a member of a security critical type.
I tried putting [SecurityCritical]
on the controller class, but apparently you're not allowed to do async calls in a class with that attribute:
Error CS4031 Async methods are not allowed in an Interface, Class, or
Structure which has the 'SecurityCritical' or 'SecuritySafeCritical'
attribute.
But I can't fix that, because I'm doing async calls to the backend (NServicebus ESB).
c# asp.net .net asp.net-web-api2 autofac
I'm updating an older project to use .net 471 instead of 462 and the most recent version of all nuget packages.
I've had a lot of versioning issues to plow through, but I finally got a project that builds.
But, when I execute the programming I get this exception:
System.TypeAccessException: 'Attempt by security transparent method
'Autofac.Integration.WebApi.RegistrationExtensions.RegisterApiControllers(Autofac.ContainerBuilder,
System.Reflection.Assembly)' to access security critical type
'Autofac.Builder.IRegistrationBuilder`3'
failed.
Followed by
Assembly 'Autofac.Integration.WebApi, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=17863af14b0044da' is marked with the
AllowPartiallyTrustedCallersAttribute, and uses the level 2 security
transparency model. Level 2 transparency causes all methods in
AllowPartiallyTrustedCallers assemblies to become security transparent
by default, which may be the cause of this exception.'
That happens when calling:
builder.RegisterApiControllers(ThisAssembly);
Where builder is an Autofac ContainerBuilder
.
Question
Like the subject says, it must be some kind of conflict between SecurityCritical
and AllowPartiallyTrustedCallersAttribute
but I don't know how I've introduced it and what the best action is, so
What's going on and how can I fix this?
Update
Going further on JLe's suggestion, I removed the webapi
reference and used webapi2
instead. I got a related error on my logging setup, but since that's not "core functionality" I skipped it for now (I will need to get back to that) to see what I'd get. I get to the browser screen, which gives me this:
Method 'my.namespace.MyController+d__6.MoveNext()' is
security transparent, but is a member of a security critical type.
I tried putting [SecurityCritical]
on the controller class, but apparently you're not allowed to do async calls in a class with that attribute:
Error CS4031 Async methods are not allowed in an Interface, Class, or
Structure which has the 'SecurityCritical' or 'SecuritySafeCritical'
attribute.
But I can't fix that, because I'm doing async calls to the backend (NServicebus ESB).
c# asp.net .net asp.net-web-api2 autofac
c# asp.net .net asp.net-web-api2 autofac
edited Nov 26 '18 at 14:45
Spikee
asked Nov 26 '18 at 13:10
SpikeeSpikee
1,35341842
1,35341842
1
Are you using nuget.org/packages/Autofac.WebApi2 or nuget.org/packages/Autofac.WebApi?
– JLe
Nov 26 '18 at 13:29
1
I'm just guessing, but the Autofac.WebApi2 package is for WebApi2, so I though maybe the old package created some version conflict which lead to your exception. Could you try remove the old one?
– JLe
Nov 26 '18 at 13:34
I just tried, but webapi is needed for thatRegisterApiControllers
andAutofacWebApiDependencyResolver
.
– Spikee
Nov 26 '18 at 13:35
Have you tried cleaning your solution? The WebApi2 package should contain those as well, version 4.2.0. The actual namespace of it is the same, Autofac.Integration.WebApi even though it's version 2.
– JLe
Nov 26 '18 at 13:46
1
@JLe: Your suggestion about cleaning up the packages ultimately fixed it (by making sure I was using webapi2). Could you write an answer so I can accept it?
– Spikee
Nov 28 '18 at 6:38
|
show 2 more comments
1
Are you using nuget.org/packages/Autofac.WebApi2 or nuget.org/packages/Autofac.WebApi?
– JLe
Nov 26 '18 at 13:29
1
I'm just guessing, but the Autofac.WebApi2 package is for WebApi2, so I though maybe the old package created some version conflict which lead to your exception. Could you try remove the old one?
– JLe
Nov 26 '18 at 13:34
I just tried, but webapi is needed for thatRegisterApiControllers
andAutofacWebApiDependencyResolver
.
– Spikee
Nov 26 '18 at 13:35
Have you tried cleaning your solution? The WebApi2 package should contain those as well, version 4.2.0. The actual namespace of it is the same, Autofac.Integration.WebApi even though it's version 2.
– JLe
Nov 26 '18 at 13:46
1
@JLe: Your suggestion about cleaning up the packages ultimately fixed it (by making sure I was using webapi2). Could you write an answer so I can accept it?
– Spikee
Nov 28 '18 at 6:38
1
1
Are you using nuget.org/packages/Autofac.WebApi2 or nuget.org/packages/Autofac.WebApi?
– JLe
Nov 26 '18 at 13:29
Are you using nuget.org/packages/Autofac.WebApi2 or nuget.org/packages/Autofac.WebApi?
– JLe
Nov 26 '18 at 13:29
1
1
I'm just guessing, but the Autofac.WebApi2 package is for WebApi2, so I though maybe the old package created some version conflict which lead to your exception. Could you try remove the old one?
– JLe
Nov 26 '18 at 13:34
I'm just guessing, but the Autofac.WebApi2 package is for WebApi2, so I though maybe the old package created some version conflict which lead to your exception. Could you try remove the old one?
– JLe
Nov 26 '18 at 13:34
I just tried, but webapi is needed for that
RegisterApiControllers
and AutofacWebApiDependencyResolver
.– Spikee
Nov 26 '18 at 13:35
I just tried, but webapi is needed for that
RegisterApiControllers
and AutofacWebApiDependencyResolver
.– Spikee
Nov 26 '18 at 13:35
Have you tried cleaning your solution? The WebApi2 package should contain those as well, version 4.2.0. The actual namespace of it is the same, Autofac.Integration.WebApi even though it's version 2.
– JLe
Nov 26 '18 at 13:46
Have you tried cleaning your solution? The WebApi2 package should contain those as well, version 4.2.0. The actual namespace of it is the same, Autofac.Integration.WebApi even though it's version 2.
– JLe
Nov 26 '18 at 13:46
1
1
@JLe: Your suggestion about cleaning up the packages ultimately fixed it (by making sure I was using webapi2). Could you write an answer so I can accept it?
– Spikee
Nov 28 '18 at 6:38
@JLe: Your suggestion about cleaning up the packages ultimately fixed it (by making sure I was using webapi2). Could you write an answer so I can accept it?
– Spikee
Nov 28 '18 at 6:38
|
show 2 more comments
1 Answer
1
active
oldest
votes
Make sure you're using nuget.org/packages/Autofac.WebApi2 as that one if for WebApi2, and not the older one called just Autofac.WebApi (the namespaces are the same though, Autofac.Integration.WebApi
).
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53481867%2fautofac-exception-security-critical-vs-level-2-security-transparency%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Make sure you're using nuget.org/packages/Autofac.WebApi2 as that one if for WebApi2, and not the older one called just Autofac.WebApi (the namespaces are the same though, Autofac.Integration.WebApi
).
add a comment |
Make sure you're using nuget.org/packages/Autofac.WebApi2 as that one if for WebApi2, and not the older one called just Autofac.WebApi (the namespaces are the same though, Autofac.Integration.WebApi
).
add a comment |
Make sure you're using nuget.org/packages/Autofac.WebApi2 as that one if for WebApi2, and not the older one called just Autofac.WebApi (the namespaces are the same though, Autofac.Integration.WebApi
).
Make sure you're using nuget.org/packages/Autofac.WebApi2 as that one if for WebApi2, and not the older one called just Autofac.WebApi (the namespaces are the same though, Autofac.Integration.WebApi
).
answered Nov 28 '18 at 7:38
JLeJLe
2,53431329
2,53431329
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53481867%2fautofac-exception-security-critical-vs-level-2-security-transparency%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Are you using nuget.org/packages/Autofac.WebApi2 or nuget.org/packages/Autofac.WebApi?
– JLe
Nov 26 '18 at 13:29
1
I'm just guessing, but the Autofac.WebApi2 package is for WebApi2, so I though maybe the old package created some version conflict which lead to your exception. Could you try remove the old one?
– JLe
Nov 26 '18 at 13:34
I just tried, but webapi is needed for that
RegisterApiControllers
andAutofacWebApiDependencyResolver
.– Spikee
Nov 26 '18 at 13:35
Have you tried cleaning your solution? The WebApi2 package should contain those as well, version 4.2.0. The actual namespace of it is the same, Autofac.Integration.WebApi even though it's version 2.
– JLe
Nov 26 '18 at 13:46
1
@JLe: Your suggestion about cleaning up the packages ultimately fixed it (by making sure I was using webapi2). Could you write an answer so I can accept it?
– Spikee
Nov 28 '18 at 6:38