That assembly does not allow partially trusted callers

wrappingduke 21 Reputation points
2022-05-20T18:27:50.62+00:00

We have an ASP.NET Core 3.1 Web API controller that is called from an ASP.NET web app using .NET 3.5 framework. The API controller is called via a HttpWebRequest and results in an error

That assembly does not allow partially trusted callers

Both apps reside on the same shared hosting environment and domain. That is, both app's have the same domain but are in different folders (i.e. applications) in IIS. For instance, mywebsite.com/folder1 and mywebsite.com/folder2.

Here's a sample how asp.net web app calls the .net core web api:

 oRequest = HttpWebRequest.Create("https://www.mywebsite.com/folder2/path/to/api")
With oRequest
.Method = "GET"
.ContentType = "application/x-www-form-urlencoded"
.Accept = "application/json"
.ContentLength = 0    
oResponse = oRequest.GetResponse()
oReader = New StreamReader(oResponse.GetResponseStream)
'store results in string
sResult = oReader.ReadToEnd
End With

We checked the .NET trust level and both app's are set to "Full (Internal)". Also, we tried adding the AllowPartiallyTrustedCallers attribute to the controller but per MS, "Partially trusted code is no longer supported. This attribute has no effect in .NET Core."

Is there another way to call the api?

Help is appreciated.

Internet Information Services
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,140 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,246 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,117 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 55,041 Reputation points
    2022-05-23T16:35:38.95+00:00

    you don't specify which application gets the error.

    your sample code just does a GET, though there is no reason to set the content-type for a GET. what happens if you just type the GET url into the browser?


  2. Bruce (SqlWork.com) 55,041 Reputation points
    2022-05-23T18:03:50.073+00:00

    then the error is unrelated to the code you have shown us. in some other code you are calling an untrusted assembly.

    note: while you may have configured trust in the application, the IIS machine config has to be configured to allow it.


  3. Bruce (SqlWork.com) 55,041 Reputation points
    2022-05-23T22:39:55.11+00:00

    methods can not be marked AllowPartiallyTrustedCallers, only assemblies. you update the assembly.cs file with the attribute and strongly name the assembly.

    typically you would do this to the library causing the trust error or wrap the library with a trusted wrapper.


  4. Sam Wu-MSFT 7,036 Reputation points Microsoft Vendor
    2022-05-25T09:39:15.253+00:00

    @wrappingduke It is difficult to reproduce your problem, I suggest you open a case via: https://support.microsoft.com.

    0 comments No comments